fixed some bugs, handle delay loading of ALL_ATTRIBUTE

git-svn-id: https://svn.code.sf.net/p/jode/code/branches/stable@1053 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 20d93c44fe
commit ddad164a2e
  1. 25
      jode/jode/bytecode/ClassInfo.java
  2. 1
      jode/jode/bytecode/FieldInfo.java
  3. 2
      jode/jode/bytecode/MethodInfo.java

@ -231,6 +231,11 @@ public class ClassInfo extends BinaryInfo {
} }
public void read(DataInputStream input, int howMuch) throws IOException { public void read(DataInputStream input, int howMuch) throws IOException {
/* Since we have to read the whole class anyway, we load all
* info, that we may need later and that does not take much memory.
*/
howMuch |= FIELDS | METHODS | HIERARCHY | INNERCLASSES | OUTERCLASSES;
howMuch &= ~status;
/* header */ /* header */
if (input.readInt() != 0xcafebabe) if (input.readInt() != 0xcafebabe)
throw new ClassFormatException("Wrong magic"); throw new ClassFormatException("Wrong magic");
@ -261,11 +266,13 @@ public class ClassInfo extends BinaryInfo {
} }
/* fields */ /* fields */
if ((howMuch & FIELDS) != 0) { if ((howMuch & (FIELDS | ALL_ATTRIBUTES)) != 0) {
int count = input.readUnsignedShort(); int count = input.readUnsignedShort();
fields = new FieldInfo[count]; if ((howMuch & FIELDS) != 0)
fields = new FieldInfo[count];
for (int i=0; i< count; i++) { for (int i=0; i< count; i++) {
fields[i] = new FieldInfo(this); if ((howMuch & FIELDS) != 0)
fields[i] = new FieldInfo(this);
fields[i].read(cpool, input, howMuch); fields[i].read(cpool, input, howMuch);
} }
} else { } else {
@ -278,11 +285,13 @@ public class ClassInfo extends BinaryInfo {
} }
/* methods */ /* methods */
if ((howMuch & METHODS) != 0) { if ((howMuch & (METHODS | ALL_ATTRIBUTES)) != 0) {
int count = input.readUnsignedShort(); int count = input.readUnsignedShort();
methods = new MethodInfo[count]; if ((howMuch & METHODS) != 0)
methods = new MethodInfo[count];
for (int i=0; i< count; i++) { for (int i=0; i< count; i++) {
methods[i] = new MethodInfo(this); if ((howMuch & METHODS) != 0)
methods[i] = new MethodInfo(this);
methods[i].read(cpool, input, howMuch); methods[i].read(cpool, input, howMuch);
} }
} else { } else {
@ -296,6 +305,7 @@ public class ClassInfo extends BinaryInfo {
/* attributes */ /* attributes */
readAttributes(cpool, input, howMuch); readAttributes(cpool, input, howMuch);
status |= howMuch;
} }
public void reserveSmallConstants(GrowableConstantPool gcp) { public void reserveSmallConstants(GrowableConstantPool gcp) {
@ -546,7 +556,6 @@ public class ClassInfo extends BinaryInfo {
new DataInputStream(classpath.getFile(name.replace('.', '/') new DataInputStream(classpath.getFile(name.replace('.', '/')
+ ".class")); + ".class"));
read(input, howMuch); read(input, howMuch);
status |= howMuch;
} catch (IOException ex) { } catch (IOException ex) {
String message = ex.getMessage(); String message = ex.getMessage();
@ -645,7 +654,7 @@ public class ClassInfo extends BinaryInfo {
public FieldInfo findField(String name, String typeSig) { public FieldInfo findField(String name, String typeSig) {
if ((status & FIELDS) == 0) if ((status & FIELDS) == 0)
loadInfo(FIELDS); loadInfo(FIELDS);
for (int i=0; i< methods.length; i++) for (int i=0; i< fields.length; i++)
if (fields[i].getName().equals(name) if (fields[i].getName().equals(name)
&& fields[i].getType().equals(typeSig)) && fields[i].getType().equals(typeSig))
return fields[i]; return fields[i];

@ -159,6 +159,7 @@ public class FieldInfo extends BinaryInfo {
} }
public Object getConstant() { public Object getConstant() {
clazzInfo.loadInfo(ALL_ATTRIBUTES);
return constant; return constant;
} }

@ -211,10 +211,12 @@ public class MethodInfo extends BinaryInfo {
} }
public void setBytecode(BytecodeInfo newBytecode) { public void setBytecode(BytecodeInfo newBytecode) {
clazzInfo.loadInfo(ALL_ATTRIBUTES);
bytecode = newBytecode; bytecode = newBytecode;
} }
public void setExceptions(String[] newExceptions) { public void setExceptions(String[] newExceptions) {
clazzInfo.loadInfo(ALL_ATTRIBUTES);
exceptions = newExceptions; exceptions = newExceptions;
} }

Loading…
Cancel
Save