-
Notifications
You must be signed in to change notification settings - Fork 275
Add parsing of the names of inner java classes. #3599
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
thomasspriggs
merged 4 commits into
diffblue:develop
from
thomasspriggs:tas/inner_class_names
Dec 20, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7e28299
Add parsing of the names of inner java classes
thomasspriggs 2dcbb00
Add unit test for inner class names
thomasspriggs 61e4d58
Add checks of `get_name()` to inner class unit test
thomasspriggs 28fbcce
Rerun inner class unit test with outer and inner loaded first
thomasspriggs 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
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 not shown.
Binary file not shown.
Binary file added
BIN
+273 Bytes
jbmc/unit/java_bytecode/java_bytecode_parser/Outer$RedHerring.class
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
jbmc/unit/java_bytecode/java_bytecode_parser/Outer$RedHerring.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,2 @@ | ||
class Outer$RedHerring { | ||
} |
Binary file not shown.
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,7 @@ | ||
class Outer { | ||
class Inner { | ||
} | ||
|
||
Outer anonymous = new Outer() { | ||
thk123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} |
143 changes: 143 additions & 0 deletions
143
jbmc/unit/java_bytecode/java_bytecode_parser/parse_inner_class.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,143 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Unit tests for converting inner classes | ||
|
||
Author: Diffblue Ltd. | ||
|
||
\*******************************************************************/ | ||
|
||
#include <java-testing-utils/load_java_class.h> | ||
#include <java_bytecode/java_types.h> | ||
#include <testing-utils/catch.hpp> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
SCENARIO( | ||
"Parsing inner java classes", | ||
"[core][java_bytecode][java_bytecode_parser]") | ||
{ | ||
for(const auto &load_first : std::vector<std::string>{"Outer$Inner", "Outer"}) | ||
{ | ||
const symbol_tablet &symbol_table = | ||
load_java_class(load_first, "./java_bytecode/java_bytecode_parser"); | ||
|
||
GIVEN("A class file of an inner class and " + load_first + " loaded first.") | ||
{ | ||
WHEN("Parsing an inner class called \"Inner\".") | ||
{ | ||
const symbolt *class_symbol = symbol_table.lookup("java::Outer$Inner"); | ||
REQUIRE(class_symbol); | ||
const java_class_typet *class_type = | ||
type_try_dynamic_cast<java_class_typet>(class_symbol->type); | ||
REQUIRE(class_type); | ||
|
||
THEN("The inner class should have the name \"java::Outer$Inner\".") | ||
{ | ||
REQUIRE(id2string(class_type->get_name()) == "java::Outer$Inner"); | ||
} | ||
THEN("The inner class should have the inner name \"Inner\".") | ||
{ | ||
REQUIRE(id2string(class_type->get_inner_name()) == "Inner"); | ||
} | ||
THEN("The inner class is not considered to be an anonymous class.") | ||
{ | ||
REQUIRE_FALSE(class_type->get_is_anonymous_class()); | ||
} | ||
THEN("The inner class has the outer class \"Outer\".") | ||
{ | ||
REQUIRE(id2string(class_type->get_outer_class()) == "Outer"); | ||
} | ||
} | ||
} | ||
GIVEN( | ||
"A class file of a class which is not an inner class and " + load_first + | ||
" loaded first.") | ||
{ | ||
WHEN("Parsing an outer class.") | ||
{ | ||
const symbolt *class_symbol = symbol_table.lookup("java::Outer"); | ||
REQUIRE(class_symbol); | ||
const java_class_typet *class_type = | ||
type_try_dynamic_cast<java_class_typet>(class_symbol->type); | ||
REQUIRE(class_type); | ||
|
||
THEN("The outer class should have the name \"java::Outer\".") | ||
{ | ||
REQUIRE(id2string(class_type->get_name()) == "java::Outer"); | ||
} | ||
THEN("The outer class should not have an inner name.") | ||
{ | ||
REQUIRE(id2string(class_type->get_inner_name()).empty()); | ||
} | ||
THEN("The outer class is not considered to be an anonymous class.") | ||
{ | ||
REQUIRE_FALSE(class_type->get_is_anonymous_class()); | ||
} | ||
THEN("The outer class does not have an outer class.") | ||
{ | ||
REQUIRE(id2string(class_type->get_outer_class()).empty()); | ||
} | ||
} | ||
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. Please add tests for the inner class is loaded correctly when starting at the outer class. |
||
} | ||
GIVEN( | ||
"A class file of an anonymous class and " + load_first + " loaded first.") | ||
{ | ||
WHEN("Parsing an anonymous class.") | ||
{ | ||
const symbolt *class_symbol = symbol_table.lookup("java::Outer$1"); | ||
REQUIRE(class_symbol); | ||
const java_class_typet *class_type = | ||
type_try_dynamic_cast<java_class_typet>(class_symbol->type); | ||
REQUIRE(class_type); | ||
|
||
THEN("The anonymous class should have the name \"java::Outer$1\".") | ||
{ | ||
REQUIRE(id2string(class_type->get_name()) == "java::Outer$1"); | ||
} | ||
THEN("The anonymous class should not have an inner name.") | ||
{ | ||
REQUIRE(id2string(class_type->get_inner_name()).empty()); | ||
} | ||
THEN("The anonymous class is considered to be an anonymous class.") | ||
{ | ||
REQUIRE(class_type->get_is_anonymous_class()); | ||
} | ||
THEN("The anonymous class does not have an outer class.") | ||
{ | ||
REQUIRE(id2string(class_type->get_outer_class()).empty()); | ||
} | ||
} | ||
} | ||
} | ||
GIVEN("A class file of an outer class which is named with a '$'.") | ||
{ | ||
WHEN("Parsing an outer class named with a '$'.") | ||
{ | ||
const symbol_tablet &symbol_table = load_java_class( | ||
"Outer$RedHerring", "./java_bytecode/java_bytecode_parser"); | ||
const auto *class_symbol = symbol_table.lookup("java::Outer$RedHerring"); | ||
REQUIRE(class_symbol); | ||
const java_class_typet *class_type = | ||
type_try_dynamic_cast<java_class_typet>(class_symbol->type); | ||
REQUIRE(class_type); | ||
|
||
THEN("The outer class should have the name \"java::Outer$RedHerring\".") | ||
{ | ||
REQUIRE(id2string(class_type->get_name()) == "java::Outer$RedHerring"); | ||
} | ||
THEN("The outer class should not have an inner name.") | ||
{ | ||
REQUIRE(id2string(class_type->get_inner_name()).empty()); | ||
} | ||
THEN("The inner class is not considered to be an anonymous class.") | ||
{ | ||
REQUIRE_FALSE(class_type->get_is_anonymous_class()); | ||
} | ||
THEN("The outer class does not have an outer class.") | ||
{ | ||
REQUIRE(id2string(class_type->get_outer_class()).empty()); | ||
} | ||
} | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.