-
Notifications
You must be signed in to change notification settings - Fork 275
Add support for Java annotations with Class value #2260
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
Merged
romainbrenguier
merged 1 commit into
diffblue:develop
from
antlechner:antonia/annotation-class-value
Jun 1, 2018
Merged
Changes from all commits
Commits
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 hidden or 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
+249 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/AnnotationWithClassType.class
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
jbmc/unit/java_bytecode/java_bytecode_parser/AnnotationWithClassType.java
This file contains hidden or 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 AnnotationWithClassType { | ||
Class<?> value(); | ||
} |
Binary file added
BIN
+334 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/ClassWithClassTypeAnnotation.class
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
jbmc/unit/java_bytecode/java_bytecode_parser/ClassWithClassTypeAnnotation.java
This file contains hidden or 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 @@ | ||
@AnnotationWithClassType(java.lang.String.class) | ||
public class ClassWithClassTypeAnnotation { | ||
} |
Binary file added
BIN
+325 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/ClassWithPrimitiveTypeAnnotation.class
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
jbmc/unit/java_bytecode/java_bytecode_parser/ClassWithPrimitiveTypeAnnotation.java
This file contains hidden or 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 @@ | ||
@AnnotationWithClassType(byte.class) | ||
public class ClassWithPrimitiveTypeAnnotation { | ||
} |
Binary file added
BIN
+315 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/ClassWithVoidTypeAnnotation.class
Binary file not shown.
3 changes: 3 additions & 0 deletions
3
jbmc/unit/java_bytecode/java_bytecode_parser/ClassWithVoidTypeAnnotation.java
This file contains hidden or 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 @@ | ||
@AnnotationWithClassType(void.class) | ||
public class ClassWithVoidTypeAnnotation { | ||
} |
3 changes: 3 additions & 0 deletions
3
jbmc/unit/java_bytecode/java_bytecode_parser/module_dependencies.txt
This file contains hidden or 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 |
95 changes: 95 additions & 0 deletions
95
jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_annotations.cpp
This file contains hidden or 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,95 @@ | ||
/*******************************************************************\ | ||
|
||
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> | ||
|
||
// See | ||
// https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.16.1 | ||
SCENARIO( | ||
"java_bytecode_parse_annotations", | ||
"[core][java_bytecode][java_bytecode_parser]") | ||
{ | ||
GIVEN("Some class files in the class path") | ||
{ | ||
WHEN( | ||
"Parsing an annotation with Class value specified to non-primitive " | ||
"(java.lang.String)") | ||
{ | ||
const symbol_tablet &new_symbol_table = load_java_class( | ||
"ClassWithClassTypeAnnotation", "./java_bytecode/java_bytecode_parser"); | ||
|
||
THEN("The annotation should store the correct type (String)") | ||
{ | ||
const symbolt &class_symbol = | ||
*new_symbol_table.lookup("java::ClassWithClassTypeAnnotation"); | ||
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 &element_value_pair = annotation.element_value_pairs.front(); | ||
const auto &id = | ||
to_symbol_expr(element_value_pair.value).get_identifier(); | ||
const auto &java_type = java_type_from_string(id2string(id)); | ||
const std::string &class_name = | ||
id2string(to_symbol_type(java_type.subtype()).get_identifier()); | ||
REQUIRE(id2string(class_name) == "java::java.lang.String"); | ||
} | ||
} | ||
WHEN("Parsing an annotation with Class value specified to primitive (byte)") | ||
{ | ||
const symbol_tablet &new_symbol_table = load_java_class( | ||
"ClassWithPrimitiveTypeAnnotation", | ||
"./java_bytecode/java_bytecode_parser"); | ||
|
||
THEN("The annotation should store the correct type (byte)") | ||
{ | ||
const symbolt &class_symbol = | ||
*new_symbol_table.lookup("java::ClassWithPrimitiveTypeAnnotation"); | ||
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 &element_value_pair = annotation.element_value_pairs.front(); | ||
const auto &id = | ||
to_symbol_expr(element_value_pair.value).get_identifier(); | ||
const auto &java_type = java_type_from_string(id2string(id)); | ||
REQUIRE(java_type == java_byte_type()); | ||
} | ||
} | ||
WHEN("Parsing an annotation with Class value specified to void") | ||
{ | ||
const symbol_tablet &new_symbol_table = load_java_class( | ||
"ClassWithVoidTypeAnnotation", "./java_bytecode/java_bytecode_parser"); | ||
|
||
THEN("The annotation should store the correct type (void)") | ||
{ | ||
const symbolt &class_symbol = | ||
*new_symbol_table.lookup("java::ClassWithVoidTypeAnnotation"); | ||
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 &element_value_pair = annotation.element_value_pairs.front(); | ||
const auto &id = | ||
to_symbol_expr(element_value_pair.value).get_identifier(); | ||
const auto &java_type = java_type_from_string(id2string(id)); | ||
REQUIRE(java_type == void_type()); | ||
} | ||
} | ||
} | ||
} |
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.
please add link to section
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.
Done