Skip to content

Commit 69989bb

Browse files
committed
Define inverse function of convert_annotations
This function can be used to retrieve annotations from a symbol table. A unit test is added for this functionality.
1 parent b68c36c commit 69989bb

12 files changed

+121
-0
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,31 @@ void convert_annotations(
10321032
}
10331033
}
10341034

1035+
/// Convert java annotations, e.g. as retrieved from the symbol table, back
1036+
/// to type annotationt (inverse of convert_annotations())
1037+
/// \param java_annotations: The java_annotationt collection to convert
1038+
/// \param annotations: The annotationt collection to populate
1039+
void convert_java_annotations(
1040+
const std::vector<java_annotationt> &java_annotations,
1041+
java_bytecode_parse_treet::annotationst &annotations)
1042+
{
1043+
for(const auto &java_annotation : java_annotations)
1044+
{
1045+
annotations.emplace_back(java_bytecode_parse_treet::annotationt());
1046+
auto &annotation = annotations.back();
1047+
annotation.type = java_annotation.get_type();
1048+
1049+
std::transform(
1050+
java_annotation.get_values().begin(),
1051+
java_annotation.get_values().end(),
1052+
std::back_inserter(annotation.element_value_pairs),
1053+
[](const java_annotationt::valuet &value)
1054+
-> java_bytecode_parse_treet::annotationt::element_value_pairt {
1055+
return {value.get_name(), value.get_value()};
1056+
});
1057+
}
1058+
}
1059+
10351060
/// Checks if the class is implicitly generic, i.e., it is an inner class of
10361061
/// any generic class. All uses of the implicit generic type parameters within
10371062
/// the inner class are updated to point to the type parameters of the

jbmc/src/java_bytecode/java_bytecode_convert_class.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ void convert_annotations(
3333
const java_bytecode_parse_treet::annotationst &parsed_annotations,
3434
std::vector<java_annotationt> &annotations);
3535

36+
void convert_java_annotations(
37+
const std::vector<java_annotationt> &java_annotations,
38+
java_bytecode_parse_treet::annotationst &annotations);
39+
3640
void mark_java_implicitly_generic_class_type(
3741
const irep_idt &class_name,
3842
symbol_tablet &symbol_table);

jbmc/unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SRC += java_bytecode/goto-programs/class_hierarchy_output.cpp \
99
java_bytecode/goto-programs/class_hierarchy_graph.cpp \
1010
java_bytecode/goto-programs/remove_virtual_functions_without_fallback.cpp \
1111
java_bytecode/java_bytecode_convert_class/convert_abstract_class.cpp \
12+
java_bytecode/java_bytecode_convert_class/convert_java_annotations.cpp \
1213
java_bytecode/java_bytecode_convert_method/convert_invoke_dynamic.cpp \
1314
java_bytecode/java_bytecode_parse_generics/parse_generic_class.cpp \
1415
java_bytecode/java_object_factory/gen_nondet_string_init.cpp \
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@MyClassAnnotation(6)
2+
public class ClassWithClassAnnotation {
3+
}
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class ClassWithMethodAnnotation {
2+
3+
@MyMethodAnnotation(methodValue = 11)
4+
public void myMethod() {
5+
}
6+
7+
}
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public @interface MyClassAnnotation {
2+
int value();
3+
}
Binary file not shown.

0 commit comments

Comments
 (0)