@@ -25,17 +25,15 @@ public static void loadHierachy() {
25
25
while (!toLoad .isEmpty ()) {
26
26
ClassNode poll = toLoad .poll ();
27
27
28
- for (ClassNode toProcess : loadHierachy (poll )) {
29
- if (processed .add (toProcess .name )) {
28
+ for (ClassNode toProcess : loadHierachy (poll ))
29
+ if (processed .add (toProcess .name ))
30
30
toLoad .add (toProcess );
31
- }
32
- }
33
31
}
34
32
}
35
33
36
34
public static List <ClassNode > loadHierachy (ClassNode specificNode ) {
37
35
try {
38
- if (specificNode . name . equals ( "java/lang/Object" )) {
36
+ if ("java/lang/Object" . equals ( specificNode . name )) {
39
37
return Collections .emptyList ();
40
38
}
41
39
if ((specificNode .access & Opcodes .ACC_INTERFACE ) != 0 ) {
@@ -58,8 +56,7 @@ public static List<ClassNode> loadHierachy(ClassNode specificNode) {
58
56
for (String interfaceReference : (List <String >) specificNode .interfaces ) {
59
57
ClassNode interfaceNode = assureLoaded (interfaceReference );
60
58
if (interfaceNode == null ) {
61
- throw new IllegalArgumentException ("Could not load "
62
- + interfaceReference );
59
+ throw new IllegalArgumentException ("Could not load " + interfaceReference );
63
60
}
64
61
ClassTree interfaceTree = getClassTree (interfaceReference );
65
62
interfaceTree .subClasses .add (specificNode .name );
@@ -80,59 +77,19 @@ public CustomClassWriter(int flags) {
80
77
public static ClassNode assureLoaded (String ref ) {
81
78
ClassNode clazz = Main .getInstance ().nameToNode .get (ref );
82
79
if (clazz == null ) {
83
- for (Library lib : Main .getInstance ().loadedAPI )
84
- if (lib .classNames .contains (ref )) {
85
- clazz = loadClass (getClass (lib .file , ref ), lib .isLibrary ? ClassReader .SKIP_CODE | ClassReader .SKIP_DEBUG | ClassReader .SKIP_FRAMES : ClassReader .SKIP_FRAMES );
86
- if (clazz != null ) {
87
- if (!lib .isLibrary )
88
- Main .getInstance ().classes .add (clazz );
89
- return clazz ;
90
- }
80
+ for (Library lib : Main .getInstance ().loadedAPI ) {
81
+ clazz = lib .getClassNode (ref );
82
+ if (clazz != null ) {
83
+ if (!lib .isLibrary ())
84
+ Main .getInstance ().classes .add (clazz );
85
+ return clazz ;
91
86
}
87
+ }
92
88
throw new NoClassInPathException (ref );
93
89
}
94
90
return clazz ;
95
91
}
96
92
97
- public static InputStream getClass (File f , String className ) {
98
- try {
99
- final ZipFile zipIn = new ZipFile (f );
100
- final Enumeration <? extends ZipEntry > e = zipIn .entries ();
101
- ArrayList <String > classList = new ArrayList <>();
102
- while (e .hasMoreElements ()) {
103
- final ZipEntry next = e .nextElement ();
104
- String nextClassName = next .getName ().replaceAll ("(.*)\\ .class" , "$1" );
105
- if (nextClassName .equals (className ))
106
- return zipIn .getInputStream (next );
107
- }
108
- zipIn .close ();
109
- } catch (Throwable t ) { }
110
- return null ;
111
- }
112
-
113
- public static ClassNode loadClass (InputStream is , int mode ) {
114
- try {
115
- final ClassReader reader = new ClassReader (is );
116
- final ClassNode node = new ClassNode ();
117
-
118
- reader .accept (node , mode );
119
- for (int i = 0 ; i < node .methods .size (); ++i ) {
120
- final MethodNode methodNode2 = (MethodNode ) node .methods .get (i );
121
- final JSRInlinerAdapter adapter = new JSRInlinerAdapter (methodNode2 , methodNode2 .access , methodNode2 .name , methodNode2 .desc , methodNode2 .signature , (String []) methodNode2 .exceptions .toArray (new String [0 ]));
122
- methodNode2 .accept (adapter );
123
- node .methods .set (i , adapter );
124
- }
125
-
126
- Main .getInstance ().nameToNode .put (node .name , node );
127
- Main .getInstance ().nodeToName .put (node , node .name );
128
-
129
- return node ;
130
- } catch (Throwable t ) {
131
- t .printStackTrace ();
132
- return null ;
133
- }
134
- }
135
-
136
93
@ Override
137
94
protected String getCommonSuperClass (String type1 , String type2 ) {
138
95
String a = getCommonSuperClass1 (type1 , type2 );
@@ -161,21 +118,21 @@ private String getCommonSuperClass0(String type1, String type2) {
161
118
}
162
119
163
120
private String getCommonSuperClass1 (String type1 , String type2 ) {
164
- if (type1 . equals ( "java/lang/Object" ) || type2 . equals ( "java/lang/Object" ))
121
+ if ("java/lang/Object" . equals ( type1 ) || "java/lang/Object" . equals ( type2 ))
165
122
return "java/lang/Object" ;
166
123
String a = getCommonSuperClass0 (type1 , type2 );
167
124
String b = getCommonSuperClass0 (type2 , type1 );
168
- if (!a . equals ( "java/lang/Object" ))
125
+ if (!"java/lang/Object" . equals ( a ))
169
126
return a ;
170
- if (!b . equals ( "java/lang/Object" ))
127
+ if (!"java/lang/Object" . equals ( b ))
171
128
return b ;
172
129
ClassNode first = assureLoaded (type1 );
173
130
ClassNode second = assureLoaded (type2 );
174
131
return getCommonSuperClass (first .superName , second .superName );
175
132
}
176
133
177
134
private boolean isAssignableFrom (String type1 , String type2 ) {
178
- if (type1 . equals ( "java/lang/Object" ))
135
+ if ("java/lang/Object" . equals ( type1 ))
179
136
return true ;
180
137
if (type1 .equals (type2 ))
181
138
return true ;
@@ -207,4 +164,42 @@ public static ClassTree getClassTree(String classNode) {
207
164
}
208
165
return tree ;
209
166
}
167
+
168
+ public static ClassNode loadClass (InputStream is , int mode ) {
169
+ try {
170
+ final ClassReader reader = new ClassReader (is );
171
+ final ClassNode node = new ClassNode ();
172
+
173
+ reader .accept (node , mode );
174
+ for (int i = 0 ; i < node .methods .size (); ++i ) {
175
+ final MethodNode methodNode2 = (MethodNode ) node .methods .get (i );
176
+ final JSRInlinerAdapter adapter = new JSRInlinerAdapter (methodNode2 , methodNode2 .access , methodNode2 .name , methodNode2 .desc , methodNode2 .signature , (String []) methodNode2 .exceptions .toArray (new String [0 ]));
177
+ methodNode2 .accept (adapter );
178
+ node .methods .set (i , adapter );
179
+ }
180
+
181
+ Main .getInstance ().nameToNode .put (node .name , node );
182
+ Main .getInstance ().nodeToName .put (node , node .name );
183
+
184
+ return node ;
185
+ } catch (Throwable t ) {
186
+ t .printStackTrace ();
187
+ return null ;
188
+ }
189
+ }
190
+
191
+ public static InputStream getClass (File f , String className ) {
192
+ try {
193
+ final ZipFile zipIn = new ZipFile (f );
194
+ final Enumeration <? extends ZipEntry > e = zipIn .entries ();
195
+ className += ".class" ;
196
+ while (e .hasMoreElements ()) {
197
+ final ZipEntry next = e .nextElement ();
198
+ if (next .getName ().equals (className ))
199
+ return zipIn .getInputStream (next );
200
+ }
201
+ zipIn .close ();
202
+ } catch (Throwable t ) { }
203
+ return null ;
204
+ }
210
205
}
0 commit comments