From ddad164a2e6be18835208adaa69ce2340e989179 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 8 Jul 1999 13:54:38 +0000 Subject: [PATCH] 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 --- jode/jode/bytecode/ClassInfo.java | 25 +++++++++++++++++-------- jode/jode/bytecode/FieldInfo.java | 1 + jode/jode/bytecode/MethodInfo.java | 2 ++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/jode/jode/bytecode/ClassInfo.java b/jode/jode/bytecode/ClassInfo.java index c8742ed..e0482cb 100644 --- a/jode/jode/bytecode/ClassInfo.java +++ b/jode/jode/bytecode/ClassInfo.java @@ -231,6 +231,11 @@ public class ClassInfo extends BinaryInfo { } 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 */ if (input.readInt() != 0xcafebabe) throw new ClassFormatException("Wrong magic"); @@ -261,11 +266,13 @@ public class ClassInfo extends BinaryInfo { } /* fields */ - if ((howMuch & FIELDS) != 0) { + if ((howMuch & (FIELDS | ALL_ATTRIBUTES)) != 0) { int count = input.readUnsignedShort(); - fields = new FieldInfo[count]; + if ((howMuch & FIELDS) != 0) + fields = new FieldInfo[count]; 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); } } else { @@ -278,11 +285,13 @@ public class ClassInfo extends BinaryInfo { } /* methods */ - if ((howMuch & METHODS) != 0) { + if ((howMuch & (METHODS | ALL_ATTRIBUTES)) != 0) { int count = input.readUnsignedShort(); - methods = new MethodInfo[count]; + if ((howMuch & METHODS) != 0) + methods = new MethodInfo[count]; 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); } } else { @@ -296,6 +305,7 @@ public class ClassInfo extends BinaryInfo { /* attributes */ readAttributes(cpool, input, howMuch); + status |= howMuch; } public void reserveSmallConstants(GrowableConstantPool gcp) { @@ -546,7 +556,6 @@ public class ClassInfo extends BinaryInfo { new DataInputStream(classpath.getFile(name.replace('.', '/') + ".class")); read(input, howMuch); - status |= howMuch; } catch (IOException ex) { String message = ex.getMessage(); @@ -645,7 +654,7 @@ public class ClassInfo extends BinaryInfo { public FieldInfo findField(String name, String typeSig) { if ((status & FIELDS) == 0) loadInfo(FIELDS); - for (int i=0; i< methods.length; i++) + for (int i=0; i< fields.length; i++) if (fields[i].getName().equals(name) && fields[i].getType().equals(typeSig)) return fields[i]; diff --git a/jode/jode/bytecode/FieldInfo.java b/jode/jode/bytecode/FieldInfo.java index 4facd8f..d67f409 100644 --- a/jode/jode/bytecode/FieldInfo.java +++ b/jode/jode/bytecode/FieldInfo.java @@ -159,6 +159,7 @@ public class FieldInfo extends BinaryInfo { } public Object getConstant() { + clazzInfo.loadInfo(ALL_ATTRIBUTES); return constant; } diff --git a/jode/jode/bytecode/MethodInfo.java b/jode/jode/bytecode/MethodInfo.java index 8e41301..37d2dfe 100644 --- a/jode/jode/bytecode/MethodInfo.java +++ b/jode/jode/bytecode/MethodInfo.java @@ -211,10 +211,12 @@ public class MethodInfo extends BinaryInfo { } public void setBytecode(BytecodeInfo newBytecode) { + clazzInfo.loadInfo(ALL_ATTRIBUTES); bytecode = newBytecode; } public void setExceptions(String[] newExceptions) { + clazzInfo.loadInfo(ALL_ATTRIBUTES); exceptions = newExceptions; }