-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional functions for processing Java annotations #2247
Merged
romainbrenguier
merged 4 commits into
diffblue:develop
from
antlechner:antonia/annotation-conversion
May 31, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4b7a195
Improve naming of annotation variables
antlechner 1db0af4
Define inverse function of convert_annotations
antlechner 1fa0b97
Generalize and rename does_annotation_exist
antlechner 3a7135a
Add module_dependencies.txt in test folder
antlechner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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(); | ||
} |
76 changes: 76 additions & 0 deletions
76
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,76 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Unit tests for converting annotations | ||
|
||
Author: Diffblue Ltd. | ||
|
||
\*******************************************************************/ | ||
|
||
#include <java-testing-utils/load_java_class.h> | ||
#include <java_bytecode/java_bytecode_convert_class.h> | ||
#include <java_bytecode/java_bytecode_parse_tree.h> | ||
#include <java_bytecode/java_types.h> | ||
#include <testing-utils/catch.hpp> | ||
|
||
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 class-level annotation MyClassAnnotation(6)") | ||
{ | ||
const symbol_tablet &new_symbol_table = load_java_class( | ||
"ClassWithClassAnnotation", | ||
"./java_bytecode/java_bytecode_convert_class"); | ||
|
||
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 method-level annotation MyMethodAnnotation(11)") | ||
{ | ||
const symbol_tablet &new_symbol_table = load_java_class( | ||
"ClassWithMethodAnnotation", | ||
"./java_bytecode/java_bytecode_convert_class"); | ||
|
||
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); | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
jbmc/unit/java_bytecode/java_bytecode_convert_class/module_dependencies.txt
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 @@ | ||
java-testing-utils | ||
testing-utils | ||
java_bytecode |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to follow on @mgudemann comment you could comment on this in the WHEN section, for instance:
WHEN("Parsing a class with a class-level annotation MyClassAnnotation(6)")
it would make it clear where this 6 comes from.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, I added that for both the class and method annotation.