-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
1385950
commit 6fea32a
Showing
11 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+304 Bytes
jbmc/unit/java_bytecode/java_bytecode_convert_class/ClassWithClassAnnotation.class
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
jbmc/unit/java_bytecode/java_bytecode_convert_class/ClassWithClassAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@MyClassAnnotation(6) | ||
public class ClassWithClassAnnotation { | ||
} |
Binary file added
BIN
+363 Bytes
jbmc/unit/java_bytecode/java_bytecode_convert_class/ClassWithMethodAnnotation.class
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
jbmc/unit/java_bytecode/java_bytecode_convert_class/ClassWithMethodAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class ClassWithMethodAnnotation { | ||
|
||
@MyMethodAnnotation(methodValue = 11) | ||
public void myMethod() { | ||
} | ||
|
||
} |
Binary file added
BIN
+176 Bytes
jbmc/unit/java_bytecode/java_bytecode_convert_class/MyClassAnnotation.class
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
jbmc/unit/java_bytecode/java_bytecode_convert_class/MyClassAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public @interface MyClassAnnotation { | ||
int value(); | ||
} |
Binary file added
BIN
+184 Bytes
jbmc/unit/java_bytecode/java_bytecode_convert_class/MyMethodAnnotation.class
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
jbmc/unit/java_bytecode/java_bytecode_convert_class/MyMethodAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public @interface MyMethodAnnotation { | ||
int methodValue(); | ||
} |
75 changes: 75 additions & 0 deletions
75
jbmc/unit/java_bytecode/java_bytecode_convert_class/convert_java_annotations.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*******************************************************************\ | ||
Module: Unit tests for converting annotations | ||
Author: Diffblue Ltd. | ||
\*******************************************************************/ | ||
|
||
#include <testing-utils/catch.hpp> | ||
#include <java-testing-utils/load_java_class.h> | ||
#include <java_bytecode/java_types.h> | ||
#include <java_bytecode/java_bytecode_parse_tree.h> | ||
#include <java_bytecode/java_bytecode_convert_class.h> | ||
|
||
SCENARIO( | ||
"java_bytecode_convert_annotations", | ||
"[core][java_bytecode][java_bytecode_convert_class]") | ||
{ | ||
GIVEN("Some class files in the class path") | ||
{ | ||
WHEN("Parsing a class with a class-level annotation") | ||
{ | ||
const symbol_tablet &new_symbol_table = load_java_class( | ||
"ClassWithClassAnnotation", "./java_bytecode/convert_java_annotations"); | ||
|
||
THEN("The annotation should have the correct structure") | ||
{ | ||
const symbolt &class_symbol = | ||
*new_symbol_table.lookup("java::ClassWithClassAnnotation"); | ||
const std::vector<java_annotationt> &java_annotations = | ||
to_annotated_type(class_symbol.type).get_annotations(); | ||
java_bytecode_parse_treet::annotationst annotations; | ||
convert_java_annotations(java_annotations, annotations); | ||
REQUIRE(annotations.size() == 1); | ||
const auto &annotation = annotations.front(); | ||
const auto &identifier = | ||
to_symbol_type(annotation.type.subtype()).get_identifier(); | ||
REQUIRE(id2string(identifier) == "java::MyClassAnnotation"); | ||
const auto &element_value_pair = annotation.element_value_pairs.front(); | ||
const auto &element_name = element_value_pair.element_name; | ||
REQUIRE(id2string(element_name) == "value"); | ||
const auto &expr = element_value_pair.value; | ||
const auto comp_expr = from_integer(6, java_int_type()); | ||
REQUIRE(expr == comp_expr); | ||
} | ||
} | ||
WHEN("Parsing a class with a method-level annotation") | ||
{ | ||
const symbol_tablet &new_symbol_table = load_java_class( | ||
"ClassWithMethodAnnotation", | ||
"./java_bytecode/convert_java_annotations"); | ||
|
||
THEN("The annotation should have the correct structure") | ||
{ | ||
const symbolt &method_symbol = *new_symbol_table.lookup( | ||
"java::ClassWithMethodAnnotation.myMethod:()V"); | ||
const std::vector<java_annotationt> &java_annotations = | ||
to_annotated_type(method_symbol.type).get_annotations(); | ||
java_bytecode_parse_treet::annotationst annotations; | ||
convert_java_annotations(java_annotations, annotations); | ||
REQUIRE(annotations.size() == 1); | ||
const auto &annotation = annotations.front(); | ||
const auto &identifier = | ||
to_symbol_type(annotation.type.subtype()).get_identifier(); | ||
REQUIRE(id2string(identifier) == "java::MyMethodAnnotation"); | ||
const auto &element_value_pair = annotation.element_value_pairs.front(); | ||
const auto &element_name = element_value_pair.element_name; | ||
REQUIRE(id2string(element_name) == "methodValue"); | ||
const auto &expr = element_value_pair.value; | ||
const auto &comp_expr = from_integer(11, java_int_type()); | ||
REQUIRE(expr == comp_expr); | ||
} | ||
} | ||
} | ||
} |