7
7
import java .io .IOException ;
8
8
import java .io .InputStream ;
9
9
import java .util .ArrayList ;
10
+ import java .util .Collections ;
10
11
import java .util .List ;
11
12
import javax .swing .JFileChooser ;
12
13
@@ -26,9 +27,7 @@ public static int getMagic() {
26
27
}
27
28
private int minor_version ;
28
29
private int major_version ;
29
-
30
30
private ConstantPool constant_pool ;
31
-
32
31
private int access_flags ;
33
32
private int this_class ;
34
33
private int super_class ;
@@ -137,7 +136,8 @@ private List<AttributeInfo> loadAttributes(int attributes_count)
137
136
138
137
139
138
for (int j = 0 ; j < number_of_exceptions ; j ++) {
140
- ((Exceptions ) attribute ).addExceptionIndex (j , this .readUnsignedShort ());
139
+ ((Exceptions ) attribute ).addExceptionIndex (j ,
140
+ this .readUnsignedShort ());
141
141
}
142
142
143
143
break ;
@@ -162,7 +162,8 @@ private List<AttributeInfo> loadAttributes(int attributes_count)
162
162
163
163
case SourceFile :
164
164
// System.err.println("SourceFile attribute");
165
- attribute = new SourceFile (attribute_name_index , attribute_length , this .readUnsignedShort ());
165
+ attribute = new SourceFile (attribute_name_index , attribute_length ,
166
+ this .readUnsignedShort ());
166
167
break ;
167
168
168
169
case LineNumberTable :
@@ -181,7 +182,8 @@ private List<AttributeInfo> loadAttributes(int attributes_count)
181
182
// System.err.println("LocalVariableTable attribute");
182
183
int local_variable_table_length = this .readUnsignedShort ();
183
184
attribute = new LocalVariableTable (attribute_name_index ,
184
- attribute_length , local_variable_table_length );
185
+ attribute_length , local_variable_table_length ,
186
+ constant_pool );
185
187
for (int j = 0 ; j < local_variable_table_length ; j ++) {
186
188
((LocalVariableTable ) attribute ).addEntry (
187
189
new LocalVariableTable .Entry (
@@ -191,6 +193,8 @@ private List<AttributeInfo> loadAttributes(int attributes_count)
191
193
this .readUnsignedShort (),
192
194
this .readUnsignedShort ()));
193
195
}
196
+ Collections .sort (((LocalVariableTable ) attribute ).getTable ());
197
+
194
198
break ;
195
199
case Deprecated :
196
200
// System.err.println("Deprecated attribute");
@@ -214,8 +218,8 @@ private List<AttributeInfo> loadAttributes(int attributes_count)
214
218
private void loadMethods (int methods_count ) throws IOException {
215
219
for (int i = 0 ; i < methods_count ; i ++) {
216
220
MethodInfo method = new MethodInfo (this .readUnsignedShort (),
217
- this .readUnsignedShort (), this .readUnsignedShort ());
218
-
221
+ this .readUnsignedShort (), this .readUnsignedShort (), constant_pool );
222
+
219
223
method .setName (constant_pool .getUTF8_Info (method .getName_index ()).getValue ());
220
224
method .setDescriptor (constant_pool .getUTF8_Info (method .getDescriptor_index ()).getValue ());
221
225
int attribute_count = this .readUnsignedShort ();
@@ -227,7 +231,7 @@ private void loadMethods(int methods_count) throws IOException {
227
231
private void loadFields (int fields_count ) throws IOException {
228
232
for (int i = 0 ; i < fields_count ; i ++) {
229
233
FieldInfo field = new FieldInfo (this .readUnsignedShort (),
230
- this .readUnsignedShort (), this .readUnsignedShort ());
234
+ this .readUnsignedShort (), this .readUnsignedShort (), constant_pool );
231
235
232
236
field .setName (constant_pool .getUTF8_Info (field .getName_index ()).getValue ());
233
237
field .setDescriptor (constant_pool .getUTF8_Info (field .getDescriptor_index ()).getValue ());
@@ -237,7 +241,6 @@ private void loadFields(int fields_count) throws IOException {
237
241
}
238
242
}
239
243
240
-
241
244
private void loadInterfaces (int interfaces_count ) throws IOException {
242
245
for (int i = 0 ; i < interfaces_count ; i ++) {
243
246
int index = this .readUnsignedShort ();
@@ -307,29 +310,29 @@ public String getClassName() {
307
310
return getConstant_pool ().getUTF8_Info (utf ).getValue ().replace ("/" , "." );
308
311
}
309
312
310
- public String getSuperClassName (){
313
+ public String getSuperClassName () {
311
314
int utf = getConstant_pool ().getClass_Info (getSuper_class ()).getName_index ();
312
315
return getConstant_pool ().getUTF8_Info (utf ).getValue ().replace ("/" , "." );
313
316
}
314
-
315
- public MethodInfo getMethod (String name ){
316
- for (MethodInfo method : methods ){
317
- if (method .getName ().equals (name )){
317
+
318
+ public MethodInfo getMethod (String name ) {
319
+ for (MethodInfo method : methods ) {
320
+ if (method .getName ().equals (name )) {
318
321
return method ;
319
322
}
320
323
}
321
324
return null ;
322
325
}
323
-
324
- public FieldInfo getField (String name ){
325
- for (FieldInfo field : fields ){
326
- if (field .getName ().equals (name )){
326
+
327
+ public FieldInfo getField (String name ) {
328
+ for (FieldInfo field : fields ) {
329
+ if (field .getName ().equals (name )) {
327
330
return field ;
328
331
}
329
332
}
330
333
return null ;
331
334
}
332
-
335
+
333
336
public static void main (String [] args ) throws Exception {
334
337
JFileChooser browser = new JFileChooser ();
335
338
int result = browser .showOpenDialog (null );
@@ -409,8 +412,8 @@ public List<MethodInfo> getMethods() {
409
412
public List <AttributeInfo > getAttributes () {
410
413
return attributes ;
411
414
}
412
-
413
- public boolean isInterface (){
415
+
416
+ public boolean isInterface () {
414
417
return AccessFlags .isInterface (this .access_flags );
415
418
}
416
419
}
0 commit comments