-
Notifications
You must be signed in to change notification settings - Fork 273
Captures static inner class information #2517
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
mgudemann
merged 1 commit into
diffblue:develop
from
jeannielynnmoulton:jeannie/InnerStaticClasses
Jul 6, 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
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
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
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
+387 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/StaticInnerClass$1.class
Binary file not shown.
Binary file added
BIN
+467 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/StaticInnerClass$1LocalClassInNonStatic.class
Binary file not shown.
Binary file added
BIN
+381 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/StaticInnerClass$1LocalClassInStatic.class
Binary file not shown.
Binary file added
BIN
+464 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/StaticInnerClass$2.class
Binary file not shown.
Binary file added
BIN
+430 Bytes
.../unit/java_bytecode/java_bytecode_parser/StaticInnerClass$PublicNonStaticInnerClass.class
Binary file not shown.
Binary file added
BIN
+353 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/StaticInnerClass$PublicStaticInnerClass.class
Binary file not shown.
Binary file added
BIN
+241 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/StaticInnerClass$SomeInterface.class
Binary file not shown.
Binary file added
BIN
+996 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/StaticInnerClass.class
Binary file not shown.
33 changes: 33 additions & 0 deletions
33
jbmc/unit/java_bytecode/java_bytecode_parser/StaticInnerClass.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,33 @@ | ||
public class StaticInnerClass { | ||
public static interface SomeInterface { | ||
public int i = 0; | ||
} | ||
public static class PublicStaticInnerClass { | ||
public int i; | ||
public PublicStaticInnerClass(int i) { | ||
this.i = i; | ||
} | ||
} | ||
public class PublicNonStaticInnerClass { | ||
public int i; | ||
public PublicNonStaticInnerClass(int i) { | ||
this.i = i; | ||
} | ||
} | ||
public static SomeInterface staticAnonymousClass = new SomeInterface() { | ||
public int i = 50; | ||
}; | ||
public SomeInterface anonymousClass = new SomeInterface() { | ||
public int i = 25; | ||
}; | ||
public void testNonStatic() { | ||
class LocalClassInNonStatic { | ||
public int i = 1; | ||
} | ||
} | ||
public static void testStatic() { | ||
class LocalClassInStatic { | ||
public int i = 2; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -266,4 +266,92 @@ SCENARIO( | |
} | ||
} | ||
} | ||
|
||
const symbol_tablet &new_symbol_table = | ||
load_java_class("StaticInnerClass", "./java_bytecode/java_bytecode_parser"); | ||
GIVEN("Some class with a static inner class") | ||
{ | ||
WHEN("Parsing the InnerClasses attribute for a static inner class ") | ||
{ | ||
THEN("The class should be marked as static") | ||
{ | ||
const symbolt &class_symbol = new_symbol_table.lookup_ref( | ||
"java::StaticInnerClass$PublicStaticInnerClass"); | ||
const java_class_typet java_class = | ||
to_java_class_type(class_symbol.type); | ||
REQUIRE(java_class.get_is_inner_class()); | ||
REQUIRE(java_class.get_is_static_class()); | ||
} | ||
} | ||
WHEN("Parsing the InnerClasses attribute for a non-static inner class ") | ||
{ | ||
THEN("The class should not be marked as static") | ||
{ | ||
const symbolt &class_symbol = new_symbol_table.lookup_ref( | ||
"java::StaticInnerClass$PublicNonStaticInnerClass"); | ||
const java_class_typet java_class = | ||
to_java_class_type(class_symbol.type); | ||
REQUIRE(java_class.get_is_inner_class()); | ||
REQUIRE_FALSE(java_class.get_is_static_class()); | ||
} | ||
} | ||
} | ||
GIVEN("Some class with a static anonymous class") | ||
{ | ||
WHEN("Parsing the InnerClasses attribute for a static anonymous class ") | ||
{ | ||
THEN("The class should be marked as static") | ||
{ | ||
const symbolt &class_symbol = | ||
new_symbol_table.lookup_ref("java::StaticInnerClass$1"); | ||
const java_class_typet java_class = | ||
to_java_class_type(class_symbol.type); | ||
REQUIRE(java_class.get_is_inner_class()); | ||
REQUIRE(java_class.get_is_static_class()); | ||
} | ||
} | ||
WHEN("Parsing the InnerClasses attribute for a non-static anonymous class ") | ||
{ | ||
THEN("The class should not be marked as static") | ||
{ | ||
const symbolt &class_symbol = | ||
new_symbol_table.lookup_ref("java::StaticInnerClass$2"); | ||
const java_class_typet java_class = | ||
to_java_class_type(class_symbol.type); | ||
REQUIRE(java_class.get_is_inner_class()); | ||
REQUIRE_FALSE(java_class.get_is_static_class()); | ||
} | ||
} | ||
} | ||
GIVEN("Some method containing a local class") | ||
{ | ||
WHEN( | ||
"Parsing the InnerClasses attribute for a local class in a static " | ||
"method ") | ||
{ | ||
THEN("The local class should be marked as static") | ||
{ | ||
const symbolt &class_symbol = new_symbol_table.lookup_ref( | ||
"java::StaticInnerClass$1LocalClassInStatic"); | ||
const java_class_typet java_class = | ||
to_java_class_type(class_symbol.type); | ||
REQUIRE(java_class.get_is_inner_class()); | ||
REQUIRE_FALSE(java_class.get_is_static_class()); | ||
} | ||
} | ||
WHEN( | ||
"Parsing the InnerClasses attribute for a local class in a non-static " | ||
"method ") | ||
{ | ||
THEN("The local class should not be marked as static") | ||
{ | ||
const symbolt &class_symbol = new_symbol_table.lookup_ref( | ||
"java::StaticInnerClass$1LocalClassInNonStatic"); | ||
const java_class_typet java_class = | ||
to_java_class_type(class_symbol.type); | ||
REQUIRE(java_class.get_is_inner_class()); | ||
REQUIRE_FALSE(java_class.get_is_static_class()); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't check the static interface, not sure if you think it is worth it? |
||
} | ||
} |
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.
Minor concern that the order of compiling the classes is the only thing to differentiate them, but not critical since we check in the compiled files anway
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.
You could perhaps modify one class to have a different field to check you've got the right one.