-
Notifications
You must be signed in to change notification settings - Fork 274
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
Changes from 2 commits
7e28299
2dcbb00
61e4d58
28fbcce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Outer$RedHerring { | ||
} |
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
|
||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/*******************************************************************\ | ||
|
||
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> | ||
|
||
SCENARIO( | ||
"Parsing inner java classes", | ||
"[core][java_bytecode][java_bytecode_parser]") | ||
{ | ||
GIVEN("A class file of an inner class.") | ||
{ | ||
WHEN("Parsing an inner class called \"Inner\".") | ||
{ | ||
const symbol_tablet &symbol_table = load_java_class( | ||
"Outer$Inner", "./java_bytecode/java_bytecode_parser"); | ||
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. ❓ What happens if you load from |
||
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 inner name \"Inner\".") | ||
{ | ||
REQUIRE(id2string(class_type->get_inner_name()) == "Inner"); | ||
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. ⛏️ Add a check on |
||
} | ||
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.") | ||
{ | ||
WHEN("Parsing an outer class.") | ||
{ | ||
const symbol_tablet &symbol_table = | ||
load_java_class("Outer", "./java_bytecode/java_bytecode_parser"); | ||
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 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.") | ||
{ | ||
WHEN("Parsing an anonymous class.") | ||
{ | ||
const symbol_tablet &symbol_table = load_java_class( | ||
"Outer$1", "./java_bytecode/java_bytecode_parser"); | ||
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 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 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()); | ||
} | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.