Skip to content

Commit a18b32d

Browse files
author
Matthias Güdemann
authored
Merge pull request diffblue#2571 from jeannielynnmoulton/jeannie/InnerClassAccessibility
[TG-4099] Parse and capture outer class information for an inner class
2 parents 87c2a68 + c959c3f commit a18b32d

26 files changed

+317
-14
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ void java_bytecode_convert_classt::convert(
279279
class_type.set_is_inner_class(c.is_inner_class);
280280
class_type.set_is_static_class(c.is_static_class);
281281
class_type.set_is_anonymous_class(c.is_anonymous_class);
282+
class_type.set_outer_class(c.outer_class);
282283
if(c.is_enum)
283284
{
284285
if(max_array_length != 0 && c.enum_elements > max_array_length)

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ struct java_bytecode_parse_treet
208208
bool is_static_class = false;
209209
bool is_anonymous_class = false;
210210
bool attribute_bootstrapmethods_read = false;
211+
irep_idt outer_class; // when no outer class is set, there is no outer class
211212
size_t enum_elements=0;
212213

213214
enum class method_handle_typet

jbmc/src/java_bytecode/java_bytecode_parser.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,11 @@ void java_bytecode_parsert::rinner_classes_attribute(
16431643
}
16441644
else
16451645
{
1646+
std::string outer_class_info_name =
1647+
class_infot(pool_entry(outer_class_info_index))
1648+
.get_name(pool_entry_lambda);
1649+
parsed_class.outer_class =
1650+
constant(outer_class_info_index).type().get(ID_C_base_name);
16461651
parsed_class.is_private = is_private;
16471652
parsed_class.is_protected = is_protected;
16481653
parsed_class.is_public = is_public;

jbmc/src/java_bytecode/java_types.h

+10
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ class java_class_typet:public class_typet
121121
return set(ID_is_inner_class, is_inner_class);
122122
}
123123

124+
const irep_idt get_outer_class() const
125+
{
126+
return get(ID_outer_class);
127+
}
128+
129+
void set_outer_class(irep_idt outer_class)
130+
{
131+
return set(ID_outer_class, outer_class);
132+
}
133+
124134
const bool get_is_static_class() const
125135
{
126136
return get_bool(ID_is_static);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

jbmc/unit/java_bytecode/java_bytecode_parser/InnerClasses.java

+66
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,72 @@ private PrivateDoublyNestedInnerClass(int i) {
8585
}
8686
}
8787

88+
class InnerPrivateClassesDeeplyNested {
89+
private class SinglyNestedPrivateClass {
90+
int i;
91+
SinglyNestedPrivateClass(int i) {
92+
this.i = i;
93+
}
94+
public class PublicDoublyNestedInnerClass {
95+
public int i;
96+
public PublicDoublyNestedInnerClass(int i) {
97+
this.i = i;
98+
}
99+
}
100+
class DefaultDoublyNestedInnerClass {
101+
int i;
102+
DefaultDoublyNestedInnerClass(int i) {
103+
this.i = i;
104+
}
105+
}
106+
protected class ProtectedDoublyNestedInnerClass {
107+
protected int i;
108+
protected ProtectedDoublyNestedInnerClass(int i) {
109+
this.i = i;
110+
}
111+
}
112+
private class PrivateDoublyNestedInnerClass {
113+
private int i;
114+
private PrivateDoublyNestedInnerClass(int i) {
115+
this.i = i;
116+
}
117+
}
118+
}
119+
}
120+
121+
class OuterClassMostRestrictiveDeeplyNested {
122+
public class SinglyNestedPublicClass {
123+
int i;
124+
SinglyNestedPublicClass(int i) {
125+
this.i = i;
126+
}
127+
public class PublicDoublyNestedInnerClass {
128+
public int i;
129+
public PublicDoublyNestedInnerClass(int i) {
130+
this.i = i;
131+
}
132+
}
133+
class DefaultDoublyNestedInnerClass {
134+
int i;
135+
DefaultDoublyNestedInnerClass(int i) {
136+
this.i = i;
137+
}
138+
}
139+
protected class ProtectedDoublyNestedInnerClass {
140+
protected int i;
141+
protected ProtectedDoublyNestedInnerClass(int i) {
142+
this.i = i;
143+
}
144+
}
145+
private class PrivateDoublyNestedInnerClass {
146+
private int i;
147+
private PrivateDoublyNestedInnerClass(int i) {
148+
this.i = i;
149+
}
150+
}
151+
}
152+
}
153+
88154
class ContainsAnonymousClass {
89155
interface InnerInterface {
90156
int i = 0;
Binary file not shown.

0 commit comments

Comments
 (0)