fall back onto reflection classes

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@168 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 75b3868f88
commit 4984990fbe
  1. 71
      jode/jode/bytecode/ClassInfo.java
  2. 18
      jode/jode/bytecode/MethodInfo.java

@ -188,6 +188,54 @@ public class ClassInfo extends BinaryInfo {
}
}
public void loadInfoReflection(int howMuch) {
try {
Class clazz = Class.forName(name);
modifiers = clazz.getModifiers();
if ((howMuch & HIERARCHY) != 0) {
if (clazz.getSuperclass() == null)
superclass = null;
else
superclass = ClassInfo.forName
(clazz.getSuperclass().getName());
Class[] ifaces = clazz.getInterfaces();
interfaces = new ClassInfo[ifaces.length];
for (int i=0; i<ifaces.length; i++)
interfaces[i] = ClassInfo.forName(ifaces[i].getName());
status |= HIERARCHY;
}
if ((howMuch & ~HIERARCHY) != 0) {
jode.Decompiler.err.println
("Can't find class " + name
+ " in classpath. Bad things may or may not happen.");
status |= howMuch;
}
} catch (ClassNotFoundException ex) {
// Nothing helped, ``guess'' the hierarchie
String message = ex.getMessage();
if ((howMuch & ~(METHODS|HIERARCHY)) == 0) {
jode.Decompiler.err.println
("Can't read class " + name + ", types may be incorrect. ("
+ ex.getClass().getName()
+ (message != null ? ": " + message : "") + ")");
} else
jode.Decompiler.err.println
("Can't read class " + name
+ "(" + ex.getClass().getName()
+ (message != null ? ": " + message : "") + ")");
if (name.equals("java.lang.Object"))
superclass = null;
else
superclass = ClassInfo.forName("java.lang.Object");
interfaces = new ClassInfo[0];
modifiers = Modifier.PUBLIC;
status = FULLINFO;
}
}
public void loadInfo(int howMuch) {
try {
DataInputStream input =
@ -209,25 +257,10 @@ public class ClassInfo extends BinaryInfo {
status |= howMuch;
} catch (IOException ex) {
String message = ex.getLocalizedMessage();
if ((howMuch & ~(METHODS|HIERARCHY)) == 0)
jode.Decompiler.err.println
("Can't read class " + name + ", types may be incorrect. ("
+ ex.getClass().getName()
+ (message != null ? ": " + message : "") + ")");
else
jode.Decompiler.err.println
("Can't read class " + name
+ "(" + ex.getClass().getName()
+ (message != null ? ": " + message : "") + ")");
if (name.equals("java.lang.Object"))
superclass = null;
else
superclass = ClassInfo.forName("java.lang.Object");
interfaces = new ClassInfo[0];
modifiers = Modifier.PUBLIC;
status = FULLINFO;
// Try getting the info through the reflection interface
// instead.
loadInfoReflection(howMuch);
}
}

@ -27,6 +27,15 @@ public class MethodInfo extends BinaryInfo {
String name;
MethodType type;
public void read(ConstantPool constantPool,
DataInputStream input, int howMuch) throws IOException {
modifier = input.readUnsignedShort();
name = constantPool.getUTF8(input.readUnsignedShort());
type = new MethodType(Modifier.isStatic(modifier),
constantPool.getUTF8(input.readUnsignedShort()));
readAttributes(constantPool, input, howMuch);
}
public String getName() {
return name;
}
@ -39,15 +48,6 @@ public class MethodInfo extends BinaryInfo {
return modifier;
}
public void read(ConstantPool constantPool,
DataInputStream input, int howMuch) throws IOException {
modifier = input.readUnsignedShort();
name = constantPool.getUTF8(input.readUnsignedShort());
type = new MethodType(Modifier.isStatic(modifier),
constantPool.getUTF8(input.readUnsignedShort()));
readAttributes(constantPool, input, howMuch);
}
public String toString() {
return "Method "+Modifier.toString(modifier)+" "+
type.toString()+" "+name;

Loading…
Cancel
Save