File tree Expand file tree Collapse file tree 5 files changed +53
-0
lines changed
unit/java_bytecode/java_bytecode_convert_method Expand file tree Collapse file tree 5 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -447,6 +447,7 @@ void java_bytecode_convert_methodt::convert(
447
447
// (function) type of the symbol
448
448
java_method_typet method_type = to_java_method_type (method_symbol.type );
449
449
method_type.set (ID_C_class, class_symbol.name );
450
+ method_type.set_is_final (m.is_final );
450
451
method_return_type = method_type.return_type ();
451
452
java_method_typet::parameterst ¶meters = method_type.parameters ();
452
453
Original file line number Diff line number Diff line change @@ -278,6 +278,16 @@ class java_method_typet : public code_typet
278
278
{
279
279
add (ID_exceptions_thrown_list).get_sub ().push_back (irept (exception ));
280
280
}
281
+
282
+ bool get_is_final () const
283
+ {
284
+ return get_bool (ID_final);
285
+ }
286
+
287
+ void set_is_final (bool is_final)
288
+ {
289
+ set (ID_final, is_final);
290
+ }
281
291
};
282
292
283
293
template <>
Original file line number Diff line number Diff line change
1
+ public class ClassWithFinalMethod {
2
+ public final int finalFunc () {
3
+ return 0 ;
4
+ }
5
+ public int nonFinalFunc () {
6
+ return 0 ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change @@ -57,3 +57,37 @@ SCENARIO(
57
57
}
58
58
}
59
59
}
60
+
61
+ SCENARIO (
62
+ " java_bytecode_convert_final_method" ,
63
+ " [core][java_bytecode][java_bytecode_convert_method]" )
64
+ {
65
+ GIVEN (" A class with final and non-final methods" )
66
+ {
67
+ const symbol_tablet symbol_table = load_java_class (
68
+ " ClassWithFinalMethod" , " ./java_bytecode/java_bytecode_convert_method" );
69
+
70
+ WHEN (" When parsing a final method" )
71
+ {
72
+ const symbolt function_symbol =
73
+ symbol_table.lookup_ref (" java::ClassWithFinalMethod.finalFunc:()I" );
74
+ const java_method_typet &function_type =
75
+ require_type::require_java_method (function_symbol.type );
76
+ THEN (" The method should be marked as final" )
77
+ {
78
+ REQUIRE (function_type.get_is_final ());
79
+ }
80
+ }
81
+ WHEN (" When parsing a non-final method" )
82
+ {
83
+ const symbolt function_symbol =
84
+ symbol_table.lookup_ref (" java::ClassWithFinalMethod.nonFinalFunc:()I" );
85
+ const java_method_typet &function_type =
86
+ require_type::require_java_method (function_symbol.type );
87
+ THEN (" The method should not be marked as final" )
88
+ {
89
+ REQUIRE (!function_type.get_is_final ());
90
+ }
91
+ }
92
+ }
93
+ }
You can’t perform that action at this time.
0 commit comments