Skip to content

Commit daeb616

Browse files
author
Daniel Kroening
authored
Merge pull request #2831 from allredj/for-final-mocking
Retrieve final qualifier from bytecode methods [TG-2893]
2 parents b01d603 + 088d101 commit daeb616

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ void java_bytecode_convert_methodt::convert(
447447
// (function) type of the symbol
448448
java_method_typet method_type = to_java_method_type(method_symbol.type);
449449
method_type.set(ID_C_class, class_symbol.name);
450+
method_type.set_is_final(m.is_final);
450451
method_return_type = method_type.return_type();
451452
java_method_typet::parameterst &parameters = method_type.parameters();
452453

jbmc/src/java_bytecode/java_types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@ class java_method_typet : public code_typet
278278
{
279279
add(ID_exceptions_thrown_list).get_sub().push_back(irept(exception));
280280
}
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+
}
281291
};
282292

283293
template <>
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class ClassWithFinalMethod {
2+
public final int finalFunc() {
3+
return 0;
4+
}
5+
public int nonFinalFunc() {
6+
return 0;
7+
}
8+
}

jbmc/unit/java_bytecode/java_bytecode_convert_method/convert_method.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,37 @@ SCENARIO(
5757
}
5858
}
5959
}
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+
}

0 commit comments

Comments
 (0)