Remove java.lang.reflect code

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@130 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 87f79ddf49
commit 1172c72832
  1. 20
      jode/jode/bytecode/SearchPath.java
  2. 38
      jode/jode/decompiler/ClassAnalyzer.java
  3. 42
      jode/jode/decompiler/CodeAnalyzer.java
  4. 2
      jode/jode/decompiler/FieldAnalyzer.java
  5. 69
      jode/jode/decompiler/ImportHandler.java
  6. 6
      jode/jode/decompiler/MethodAnalyzer.java
  7. 2
      jode/jode/expr/GetFieldOperator.java
  8. 26
      jode/jode/expr/InvokeOperator.java
  9. 2
      jode/jode/expr/PutFieldOperator.java
  10. 141
      jode/jode/type/ClassInterfacesType.java
  11. 9
      jode/jode/type/MethodType.java
  12. 25
      jode/jode/type/Type.java

@ -59,6 +59,26 @@ public class SearchPath {
} }
} }
public boolean exists(String filename) {
for (int i=0; i<dirs.length; i++) {
if (dirs[i] == null)
continue;
if (zips[i] != null) {
ZipEntry ze = zips[i].getEntry(filename);
if (ze != null)
return true;
} else {
if (java.io.File.separatorChar != '/')
filename = filename
.replace('/', java.io.File.separatorChar);
File f = new File(dirs[i], filename);
if (f.exists())
return true;
}
}
return false;
}
/** /**
* Searches for a file in the search path. * Searches for a file in the search path.
* @param filename the filename. The path components should be separated * @param filename the filename. The path components should be separated

@ -19,14 +19,12 @@
package jode; package jode;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import gnu.bytecode.ConstantPool; import gnu.bytecode.ConstantPool;
import gnu.bytecode.CpoolEntry; import gnu.bytecode.CpoolEntry;
import gnu.bytecode.CpoolValue1; import gnu.bytecode.CpoolValue1;
import gnu.bytecode.CpoolValue2; import gnu.bytecode.CpoolValue2;
import gnu.bytecode.CpoolString; import gnu.bytecode.CpoolString;
import jode.bytecode.ClassHierarchy;
import jode.flow.TransformConstructors; import jode.flow.TransformConstructors;
public class ClassAnalyzer implements Analyzer { public class ClassAnalyzer implements Analyzer {
@ -35,22 +33,17 @@ public class ClassAnalyzer implements Analyzer {
MethodAnalyzer staticConstructor; MethodAnalyzer staticConstructor;
MethodAnalyzer[] constructors; MethodAnalyzer[] constructors;
Class clazz; ClassHierarchy clazz;
gnu.bytecode.ClassType classType; gnu.bytecode.ClassType classType;
ClassAnalyzer parent; ClassAnalyzer parent;
public ClassAnalyzer(ClassAnalyzer parent, Class clazz, public ClassAnalyzer(ClassAnalyzer parent, ClassHierarchy clazz,
JodeEnvironment env) JodeEnvironment env)
{ {
this.parent = parent; this.parent = parent;
this.clazz = clazz; this.clazz = clazz;
this.env = env; this.env = env;
try { this.classType = env.getClassType(clazz.getName());
this.classType = gnu.bytecode.ClassFileInput.
readClassType(env.getClassStream(clazz));
} catch (java.io.IOException ex) {
ex.printStackTrace();
}
} }
public boolean setFieldInitializer(String fieldName, Expression expr) { public boolean setFieldInitializer(String fieldName, Expression expr) {
@ -64,7 +57,7 @@ public class ClassAnalyzer implements Analyzer {
return false; return false;
} }
public Class getClazz() { public ClassHierarchy getClazz() {
return clazz; return clazz;
} }
@ -104,12 +97,12 @@ public class ClassAnalyzer implements Analyzer {
TransformConstructors.transform(this, true, new MethodAnalyzer[] TransformConstructors.transform(this, true, new MethodAnalyzer[]
{ staticConstructor }); { staticConstructor });
env.useClass(clazz); env.useClass(clazz.getName());
if (clazz.getSuperclass() != null) if (clazz.getSuperclass() != null)
env.useClass(clazz.getSuperclass()); env.useClass(clazz.getSuperclass().getName());
Class[] interfaces = clazz.getInterfaces(); ClassHierarchy[] interfaces = clazz.getInterfaces();
for (int j=0; j< interfaces.length; j++) for (int j=0; j< interfaces.length; j++)
env.useClass(interfaces[j]); env.useClass(interfaces[j].getName());
} }
public void dumpSource(TabbedPrintWriter writer) throws java.io.IOException public void dumpSource(TabbedPrintWriter writer) throws java.io.IOException
@ -124,19 +117,20 @@ public class ClassAnalyzer implements Analyzer {
writer.print(clazz.isInterface() writer.print(clazz.isInterface()
? ""/*interface is in modif*/ ? ""/*interface is in modif*/
: "class "); : "class ");
writer.println(env.classString(clazz)); writer.println(env.classString(clazz.getName()));
writer.tab(); writer.tab();
Class superClazz = clazz.getSuperclass(); ClassHierarchy superClazz = clazz.getSuperclass();
if (superClazz != null && superClazz != Object.class) { if (superClazz != null &&
writer.println("extends "+env.classString(superClazz)); superClazz != ClassHierarchy.javaLangObject) {
writer.println("extends "+env.classString(superClazz.getName()));
} }
Class[] interfaces = clazz.getInterfaces(); ClassHierarchy[] interfaces = clazz.getInterfaces();
if (interfaces.length > 0) { if (interfaces.length > 0) {
writer.print(clazz.isInterface() ? "extends " : "implements "); writer.print(clazz.isInterface() ? "extends " : "implements ");
for (int i=0; i < interfaces.length; i++) { for (int i=0; i < interfaces.length; i++) {
if (i > 0) if (i > 0)
writer.print(", "); writer.print(", ");
writer.print(env.classString(interfaces[i])); writer.print(env.classString(interfaces[i].getName()));
} }
writer.println(""); writer.println("");
} }

@ -18,6 +18,7 @@
*/ */
package jode; package jode;
import jode.bytecode.ClassHierarchy;
import jode.flow.FlowBlock; import jode.flow.FlowBlock;
import jode.flow.TransformExceptionHandlers; import jode.flow.TransformExceptionHandlers;
@ -182,43 +183,6 @@ public class CodeAnalyzer implements Analyzer {
methodHeader.analyze(); methodHeader.analyze();
} }
// void readCode(byte[] code, short[] handlers)
// throws ClassFormatError
// {
// FlowBlock[] instr = new FlowBlock[code.length];
// int returnCount;
// try {
// DataInputStream stream =
// new DataInputStream(new ByteArrayInputStream(code));
// for (int addr = 0; addr < code.length; ) {
// instr[addr] = Opcodes.readOpcode(addr, stream, this);
// addr = instr[addr].getNextAddr();
// }
// } catch (IOException ex) {
// throw new ClassFormatError(ex.toString());
// }
// for (int addr=0; addr<instr.length; ) {
// instr[addr].resolveJumps(instr);
// addr = instr[addr].getNextAddr();
// }
// handler = new TransformExceptionHandlers(instr);
// for (int i=0; i<handlers.length; i += 4) {
// Type type = null;
// if (handlers[i + 3 ] != 0) {
// CpoolClass cpcls = (CpoolClass)
// method.classAnalyzer.getConstant(handlers[i + 3]);
// type = Type.tClass(cpcls.getName().getString());
// }
// handler.addHandler(handlers[i + 0], handlers[i + 1],
// handlers[i + 2], type);
// }
// methodHeader = instr[0];
// }
public void analyze() public void analyze()
{ {
byte[] codeArray = code.getCode(); byte[] codeArray = code.getCode();
@ -265,7 +229,7 @@ public class CodeAnalyzer implements Analyzer {
return param[slot]; return param[slot];
} }
public void useClass(Class clazz) public void useClass(String clazz)
{ {
env.useClass(clazz); env.useClass(clazz);
} }
@ -274,7 +238,7 @@ public class CodeAnalyzer implements Analyzer {
return method.classAnalyzer.getTypeString(type); return method.classAnalyzer.getTypeString(type);
} }
public Class getClazz() { public ClassHierarchy getClazz() {
return method.classAnalyzer.clazz; return method.classAnalyzer.clazz;
} }
} }

@ -18,7 +18,7 @@
*/ */
package jode; package jode;
import java.lang.reflect.*; import java.lang.reflect.Modifier;
import gnu.bytecode.Attribute; import gnu.bytecode.Attribute;
import gnu.bytecode.MiscAttr; import gnu.bytecode.MiscAttr;
import gnu.bytecode.Spy; import gnu.bytecode.Spy;

@ -19,6 +19,8 @@
package jode; package jode;
import java.util.*; import java.util.*;
import jode.bytecode.ClassHierarchy;
import gnu.bytecode.ClassType;
public class JodeEnvironment { public class JodeEnvironment {
Hashtable imports; Hashtable imports;
@ -31,16 +33,23 @@ public class JodeEnvironment {
SearchPath classPath; SearchPath classPath;
JodeEnvironment(String path) { JodeEnvironment(String path) {
Type.setEnvironment(this);
classPath = new SearchPath(path); classPath = new SearchPath(path);
ClassHierarchy.setClassPath(classPath);
Type.setEnvironment(this);
imports = new Hashtable(); imports = new Hashtable();
/* java.lang is always imported */ /* java.lang is always imported */
imports.put("java.lang.*", new Integer(Integer.MAX_VALUE)); imports.put("java.lang.*", new Integer(Integer.MAX_VALUE));
} }
public java.io.InputStream getClassStream(Class clazz) public gnu.bytecode.ClassType getClassType(String clazzName) {
throws java.io.IOException { try {
return classPath.getFile(clazz.getName().replace('.', '/') + ".class"); return gnu.bytecode.ClassFileInput.readClassType
(classPath.getFile(clazzName.replace('.', '/')
+".class"));
} catch (java.io.IOException ex) {
ex.printStackTrace();
throw new RuntimeException("Class not found.");
}
} }
/** /**
@ -68,22 +77,9 @@ public class JodeEnvironment {
name = name.substring(pkgdelim); name = name.substring(pkgdelim);
if (pkg.length() != 0) { if (pkg.length() != 0) {
try { if (classPath.exists((pkg+name).replace('.', '/')
Class.forName(pkg + name); + ".class"))
/* UGLY: If class doesn't conflict, above
* Instruction throws an exception and we
* doesn't reach here.
* XXX - Is there a better way to do it ???
*/
// System.err.println(""+pkgName+name
// + " conflicts with "
// + pkg+name);
return true; return true;
} catch (ClassNotFoundException ex) {
/* BTW: Exception generation is slow. I'm
* really sad that this is the default.
*/
}
} }
Enumeration enum = imports.keys(); Enumeration enum = imports.keys();
@ -94,22 +90,9 @@ public class JodeEnvironment {
importName = importName.substring importName = importName.substring
(0, importName.length()-2); (0, importName.length()-2);
if (!importName.equals(pkgName)) { if (!importName.equals(pkgName)) {
try { if (classPath.exists(importName.replace('.', '/')
Class.forName(importName + name); + ".class"))
/* UGLY: If class doesn't conflict, above
* Instruction throws an exception and we
* doesn't reach here.
* XXX - Is there a better way to do it ???
*/
// System.err.println(""+pkgName+name
// + " conflicts with "
// + importName+name);
return true; return true;
} catch (ClassNotFoundException ex) {
/* BTW: Exception generation is slow. I'm
* really sad that this is the default.
*/
}
} }
} }
} }
@ -189,12 +172,9 @@ public class JodeEnvironment {
public void doClass(String className) public void doClass(String className)
{ {
Class clazz; ClassHierarchy clazz;
try { try {
clazz = Class.forName(className); clazz = ClassHierarchy.forName(className);
} catch (ClassNotFoundException ex) {
System.err.println("Class `"+className+"' not found");
return;
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
System.err.println("`"+className+"' is not a class name"); System.err.println("`"+className+"' is not a class name");
return; return;
@ -254,13 +234,6 @@ public class JodeEnvironment {
} }
} }
/* Marks the clazz as used, so that it will be imported if used often
* enough.
*/
public void useClass(Class clazz) {
useClass(clazz.getName());
}
/** /**
* Check if clazz is imported and maybe remove package delimiter from * Check if clazz is imported and maybe remove package delimiter from
* full qualified class name. * full qualified class name.
@ -303,10 +276,6 @@ public class JodeEnvironment {
return name; return name;
} }
public String classString(Class clazz) {
return classString(clazz.getName());
}
protected int loadFileFlags() protected int loadFileFlags()
{ {
return 1; return 1;

@ -105,7 +105,8 @@ public class MethodAnalyzer implements Analyzer {
int offset = 0; int offset = 0;
if (!isStatic()) { if (!isStatic()) {
LocalInfo clazz = code.getParamInfo(0); LocalInfo clazz = code.getParamInfo(0);
clazz.setType(Type.tType(this.classAnalyzer.clazz)); clazz.setType
(Type.tClass(this.classAnalyzer.getClazz().getName()));
clazz.setName("this"); clazz.setName("this");
offset++; offset++;
} }
@ -157,7 +158,8 @@ public class MethodAnalyzer implements Analyzer {
writer.print(""); /* static block */ writer.print(""); /* static block */
else { else {
if (isConstructor) if (isConstructor)
writer.print(env.classString(classAnalyzer.clazz)); writer.print(env.classString(classAnalyzer.
getClazz().getName()));
else else
writer.print(getReturnType().toString() writer.print(getReturnType().toString()
+ " " + methodName); + " " + methodName);

@ -58,7 +58,7 @@ public class GetFieldOperator extends Operator {
public String toString(String[] operands) { public String toString(String[] operands) {
return staticFlag return staticFlag
? (classType.equals(Type.tType(codeAnalyzer.getClazz())) ? (classType.equals(Type.tClass(codeAnalyzer.getClazz().getName()))
&& codeAnalyzer.findLocal(fieldName) == null && codeAnalyzer.findLocal(fieldName) == null
? fieldName ? fieldName
: classType.toString() + "." + fieldName) : classType.toString() + "." + fieldName)

@ -19,6 +19,7 @@
package jode; package jode;
import gnu.bytecode.CpoolRef; import gnu.bytecode.CpoolRef;
import jode.bytecode.ClassHierarchy;
public final class InvokeOperator extends Operator { public final class InvokeOperator extends Operator {
CodeAnalyzer codeAnalyzer; CodeAnalyzer codeAnalyzer;
@ -89,34 +90,31 @@ public final class InvokeOperator extends Operator {
} }
public boolean isThis() { public boolean isThis() {
Class clazz = codeAnalyzer.method.classAnalyzer.getClazz(); return (classType.equals(Type.tClass(codeAnalyzer.method.
return (classType.equals(Type.tType(clazz))); classAnalyzer.getClazz().
getName())));
} }
public boolean isSuperOrThis() { public boolean isSuperOrThis() {
Class clazz = codeAnalyzer.method.classAnalyzer.getClazz(); return ((ClassInterfacesType)classType).getClazz().superClassOf
while (clazz != null (codeAnalyzer.method.classAnalyzer.getClazz());
&& !classType.equals(Type.tType(clazz))) {
clazz = clazz.getSuperclass();
}
return (clazz != null);
} }
public String toString(String[] operands) { public String toString(String[] operands) {
String object = null; String object = null;
if (specialFlag) { if (specialFlag) {
Class clazz = codeAnalyzer.method.classAnalyzer.clazz; ClassHierarchy clazz = codeAnalyzer.getClazz();
if (operands[0].equals("this")) { if (operands[0].equals("this")) {
object = ""; object = "";
while (clazz != null while (clazz != null
&& !classType.equals(Type.tType(clazz))) { && !classType.equals(Type.tClass(clazz.getName()))) {
object = "super"; object = "super";
clazz = clazz.getSuperclass(); clazz = clazz.getSuperclass();
} }
if (clazz == null) if (clazz == null)
object = "NON VIRTUAL this"; object = "NON VIRTUAL this";
} else if (classType.equals(Type.tType(clazz))) } else if (classType.equals(Type.tClass(clazz.getName())))
object = operands[0]; object = operands[0];
else else
object = "NON VIRTUAL "+operands[0]; object = "NON VIRTUAL "+operands[0];
@ -124,13 +122,11 @@ public final class InvokeOperator extends Operator {
object = (object != null) ? object object = (object != null) ? object
: methodType.isStatic() : methodType.isStatic()
? (classType.equals(Type.tType(codeAnalyzer.getClazz())) ? (classType.equals(Type.tClass(codeAnalyzer.getClazz().getName()))
? "" ? ""
: classType.toString()) : classType.toString())
: (operands[0].equals("this") : (operands[0].equals("this")
? (specialFlag && ? (specialFlag && isSuperOrThis()
classType.equals(Type.tType(codeAnalyzer.getClazz()
.getSuperclass()))
? "super" ? "super"
: "") : "")
: operands[0]); : operands[0]);

@ -68,7 +68,7 @@ public class PutFieldOperator extends StoreInstruction {
public String getLValueString(String[] operands) { public String getLValueString(String[] operands) {
return staticFlag return staticFlag
? (classType.equals(Type.tType(codeAnalyzer.getClazz())) ? (classType.equals(Type.tClass(codeAnalyzer.getClazz().getName()))
&& codeAnalyzer.findLocal(fieldName) == null && codeAnalyzer.findLocal(fieldName) == null
? fieldName ? fieldName
: classType.toString() + "." + fieldName) : classType.toString() + "." + fieldName)

@ -17,6 +17,7 @@
* $Id$ * $Id$
*/ */
package jode; package jode;
import jode.bytecode.ClassHierarchy;
import java.util.Vector; import java.util.Vector;
import java.util.Stack; import java.util.Stack;
@ -34,70 +35,51 @@ import java.util.Stack;
* @author Jochen Hoenicke */ * @author Jochen Hoenicke */
public class ClassInterfacesType extends Type { public class ClassInterfacesType extends Type {
Class clazz; ClassHierarchy clazz;
Class ifaces[]; ClassHierarchy ifaces[];
public ClassHierarchy getClazz() {
return clazz;
}
public final static Class cObject = new Object().getClass();
public ClassInterfacesType(String clazzName) { public ClassInterfacesType(String clazzName) {
super(TC_CLASS); super(TC_CLASS);
try { ClassHierarchy clazz = ClassHierarchy.forName(clazzName);
Class clazz = Class.forName(clazzName); if (clazz.isInterface()) {
if (clazz.isInterface()) { this.clazz = null;
this.clazz = null; ifaces = new ClassHierarchy[] {clazz};
ifaces = new Class[] {clazz}; } else {
} else { this.clazz =
this.clazz = (clazz == cObject) ? null : clazz; (clazz == ClassHierarchy.javaLangObject) ? null : clazz;
ifaces = new Class[0]; ifaces = new ClassHierarchy[0];
}
} catch (ClassNotFoundException ex) {
throw new AssertError(ex.toString());
} }
} }
public ClassInterfacesType(Class clazz) { public ClassInterfacesType(ClassHierarchy clazz) {
super(TC_CLASS); super(TC_CLASS);
if (clazz.isInterface()) { if (clazz.isInterface()) {
this.clazz = null; this.clazz = null;
ifaces = new Class[] { clazz }; ifaces = new ClassHierarchy[] { clazz };
} else { } else {
this.clazz = (clazz == cObject) ? null : clazz; this.clazz =
ifaces = new Class[0]; (clazz == ClassHierarchy.javaLangObject) ? null : clazz;
ifaces = new ClassHierarchy[0];
} }
} }
public ClassInterfacesType(Class clazz, Class[] ifaces) { public ClassInterfacesType(ClassHierarchy clazz, ClassHierarchy[] ifaces) {
super(TC_CLASS); super(TC_CLASS);
this.clazz = clazz; this.clazz = clazz;
this.ifaces = ifaces; this.ifaces = ifaces;
} }
private static Type create(Class clazz, Class[] ifaces) { private static Type create(ClassHierarchy clazz, ClassHierarchy[] ifaces) {
/* Make sure that every {java.lang.Object} equals tObject */ /* Make sure that every {java.lang.Object} equals tObject */
if (ifaces.length == 0 && clazz == null) if (ifaces.length == 0 && clazz == null)
return tObject; return tObject;
return new ClassInterfacesType(clazz, ifaces); return new ClassInterfacesType(clazz, ifaces);
} }
public final static boolean superClassOf(Class parent, Class clazz) {
while (clazz != parent && clazz != null) {
clazz = clazz.getSuperclass();
}
return clazz == parent;
}
public final static boolean implementedBy(Class iface, Class clazz) {
while (clazz != iface && clazz != null) {
Class[] ifaces = clazz.getInterfaces();
for (int i=0; i< ifaces.length; i++) {
if (implementedBy(iface, ifaces[i]))
return true;
}
clazz = clazz.getSuperclass();
}
return clazz != null;
}
/** /**
* Create the type corresponding to the range from bottomType to * Create the type corresponding to the range from bottomType to
* this. Checks if the given type range may be not empty. This * this. Checks if the given type range may be not empty. This
@ -121,13 +103,13 @@ public class ClassInterfacesType extends Type {
/* The searched type must be a class type. /* The searched type must be a class type.
*/ */
if (this.ifaces.length != 0 if (this.ifaces.length != 0
|| !superClassOf(bottom.clazz,this.clazz)) || !bottom.clazz.superClassOf(this.clazz))
return tError; return tError;
/* All interfaces must be implemented by this.clazz /* All interfaces must be implemented by this.clazz
*/ */
for (int i=0; i < bottom.ifaces.length; i++) { for (int i=0; i < bottom.ifaces.length; i++) {
if (!implementedBy(bottom.ifaces[i], this.clazz)) if (!bottom.ifaces[i].implementedBy(this.clazz))
return tError; return tError;
} }
@ -143,10 +125,10 @@ public class ClassInterfacesType extends Type {
* classes/interfaces that implement all bottom.ifaces. * classes/interfaces that implement all bottom.ifaces.
*/ */
Class clazz = this.clazz; ClassHierarchy clazz = this.clazz;
if (clazz != null) { if (clazz != null) {
for (int i=0; i < bottom.ifaces.length; i++) { for (int i=0; i < bottom.ifaces.length; i++) {
if (!implementedBy(bottom.ifaces[i], clazz)) { if (!bottom.ifaces[i].implementedBy(clazz)) {
clazz = null; clazz = null;
break; break;
} }
@ -163,19 +145,19 @@ public class ClassInterfacesType extends Type {
} }
} }
Class[] ifaces = new Class[this.ifaces.length]; ClassHierarchy[] ifaces = new ClassHierarchy[this.ifaces.length];
int count = 0; int count = 0;
big_loop: big_loop:
for (int j=0; j < this.ifaces.length; j++) { for (int j=0; j < this.ifaces.length; j++) {
for (int i=0; i < bottom.ifaces.length; i++) { for (int i=0; i < bottom.ifaces.length; i++) {
if (!implementedBy(bottom.ifaces[i], this.ifaces[j])) if (!bottom.ifaces[i].implementedBy(this.ifaces[j]))
continue big_loop; continue big_loop;
} }
ifaces[count++] = (this.ifaces[j]); ifaces[count++] = (this.ifaces[j]);
} }
if (count < ifaces.length) { if (count < ifaces.length) {
Class[] shortIfaces = new Class[count]; ClassHierarchy[] shortIfaces = new ClassHierarchy[count];
System.arraycopy(ifaces, 0, shortIfaces, 0, count); System.arraycopy(ifaces, 0, shortIfaces, 0, count);
ifaces = shortIfaces; ifaces = shortIfaces;
} else if (clazz == this.clazz) } else if (clazz == this.clazz)
@ -184,14 +166,14 @@ public class ClassInterfacesType extends Type {
} }
} }
private boolean implementsAllIfaces(Class[] otherIfaces) { private boolean implementsAllIfaces(ClassHierarchy[] otherIfaces) {
big: big:
for (int i=0; i < otherIfaces.length; i++) { for (int i=0; i < otherIfaces.length; i++) {
Class iface = otherIfaces[i]; ClassHierarchy iface = otherIfaces[i];
if (clazz != null && implementedBy(iface, clazz)) if (clazz != null && iface.implementedBy(clazz))
continue big; continue big;
for (int j=0; j < this.ifaces.length; j++) { for (int j=0; j < this.ifaces.length; j++) {
if (implementedBy(iface, ifaces[j])) if (iface.implementedBy(ifaces[j]))
continue big; continue big;
} }
return false; return false;
@ -215,7 +197,7 @@ public class ClassInterfacesType extends Type {
return tError; return tError;
ClassInterfacesType other = (ClassInterfacesType) type; ClassInterfacesType other = (ClassInterfacesType) type;
Class clazz; ClassHierarchy clazz;
/* First determine the clazz, one of the two classes must be a sub /* First determine the clazz, one of the two classes must be a sub
* class of the other or null. * class of the other or null.
@ -225,9 +207,9 @@ public class ClassInterfacesType extends Type {
clazz = other.clazz; clazz = other.clazz;
else if (other.clazz == null) else if (other.clazz == null)
clazz = this.clazz; clazz = this.clazz;
else if (superClassOf(this.clazz, other.clazz)) else if (this.clazz.superClassOf(other.clazz))
clazz = other.clazz; clazz = other.clazz;
else if (superClassOf(other.clazz, this.clazz)) else if (other.clazz.superClassOf(this.clazz))
clazz = this.clazz; clazz = this.clazz;
else else
return tError; return tError;
@ -249,12 +231,12 @@ public class ClassInterfacesType extends Type {
Vector ifaces = new Vector(); Vector ifaces = new Vector();
big_loop_this: big_loop_this:
for (int i=0; i< this.ifaces.length; i++) { for (int i=0; i< this.ifaces.length; i++) {
Class iface = this.ifaces[i]; ClassHierarchy iface = this.ifaces[i];
if (clazz != null && implementedBy(iface, clazz)) { if (clazz != null && iface.implementedBy(clazz)) {
continue big_loop_this; continue big_loop_this;
} }
for (int j=0; j<other.ifaces.length; j++) { for (int j=0; j<other.ifaces.length; j++) {
if (implementedBy(iface, other.ifaces[j])) { if (iface.implementedBy(other.ifaces[j])) {
continue big_loop_this; continue big_loop_this;
} }
} }
@ -266,12 +248,13 @@ public class ClassInterfacesType extends Type {
} }
big_loop_other: big_loop_other:
for (int i=0; i< other.ifaces.length; i++) { for (int i=0; i< other.ifaces.length; i++) {
Class iface = other.ifaces[i]; ClassHierarchy iface = other.ifaces[i];
if (clazz != null && implementedBy(iface, clazz)) { if (clazz != null && iface.implementedBy(clazz)) {
continue big_loop_other; continue big_loop_other;
} }
for (int j=0; j<ifaces.size(); j++) { for (int j=0; j<ifaces.size(); j++) {
if (implementedBy(iface, (Class) ifaces.elementAt(j))) { if (iface.implementedBy((ClassHierarchy)
ifaces.elementAt(j))) {
continue big_loop_other; continue big_loop_other;
} }
} }
@ -282,7 +265,7 @@ public class ClassInterfacesType extends Type {
ifaces.addElement(iface); ifaces.addElement(iface);
} }
Class[] ifaceArray = new Class[ifaces.size()]; ClassHierarchy[] ifaceArray = new ClassHierarchy[ifaces.size()];
ifaces.copyInto(ifaceArray); ifaces.copyInto(ifaceArray);
return create(clazz, ifaceArray); return create(clazz, ifaceArray);
} }
@ -302,7 +285,7 @@ public class ClassInterfacesType extends Type {
if (code != TC_CLASS) if (code != TC_CLASS)
return tError; return tError;
ClassInterfacesType other = (ClassInterfacesType) type; ClassInterfacesType other = (ClassInterfacesType) type;
Class clazz; ClassHierarchy clazz;
/* First the easy part, determine the clazz */ /* First the easy part, determine the clazz */
if (this.clazz == null || other.clazz == null) if (this.clazz == null || other.clazz == null)
@ -311,11 +294,11 @@ public class ClassInterfacesType extends Type {
clazz = this.clazz; clazz = this.clazz;
while(clazz != null) { while(clazz != null) {
if (superClassOf(clazz, other.clazz)) if (clazz.superClassOf(other.clazz))
break; break;
clazz = clazz.getSuperclass(); clazz = clazz.getSuperclass();
} }
if (clazz == cObject) if (clazz == ClassHierarchy.javaLangObject)
clazz = null; clazz = null;
} }
@ -334,9 +317,9 @@ public class ClassInterfacesType extends Type {
Stack allIfaces = new Stack(); Stack allIfaces = new Stack();
if (this.clazz != null) { if (this.clazz != null) {
Class c = this.clazz; ClassHierarchy c = this.clazz;
while (clazz != c) { while (clazz != c) {
Class clazzIfaces[] = c.getInterfaces(); ClassHierarchy clazzIfaces[] = c.getInterfaces();
for (int i=0; i<clazzIfaces.length; i++) for (int i=0; i<clazzIfaces.length; i++)
allIfaces.push(clazzIfaces[i]); allIfaces.push(clazzIfaces[i]);
c = c.getSuperclass(); c = c.getSuperclass();
@ -354,19 +337,19 @@ public class ClassInterfacesType extends Type {
*/ */
iface_loop: iface_loop:
while (!allIfaces.isEmpty()) { while (!allIfaces.isEmpty()) {
Class iface = (Class) allIfaces.pop(); ClassHierarchy iface = (ClassHierarchy) allIfaces.pop();
if ((clazz != null && implementedBy(iface, clazz)) if ((clazz != null && iface.implementedBy(clazz))
|| ifaces.contains(iface)) || ifaces.contains(iface))
/* We can skip this, as clazz or ifaces already imply it. /* We can skip this, as clazz or ifaces already imply it.
*/ */
continue iface_loop; continue iface_loop;
if (other.clazz != null && implementedBy(iface, other.clazz)) { if (other.clazz != null && iface.implementedBy(other.clazz)) {
ifaces.addElement(iface); ifaces.addElement(iface);
continue iface_loop; continue iface_loop;
} }
for (int i=0; i<other.ifaces.length; i++) { for (int i=0; i<other.ifaces.length; i++) {
if (implementedBy(iface, other.ifaces[i])) { if (iface.implementedBy(other.ifaces[i])) {
ifaces.addElement(iface); ifaces.addElement(iface);
continue iface_loop; continue iface_loop;
} }
@ -375,12 +358,12 @@ public class ClassInterfacesType extends Type {
/* This interface is not implemented by any of the other /* This interface is not implemented by any of the other
* ifaces. Try its parent interfaces now. * ifaces. Try its parent interfaces now.
*/ */
Class clazzIfaces[] = iface.getInterfaces(); ClassHierarchy clazzIfaces[] = iface.getInterfaces();
for (int i=0; i<clazzIfaces.length; i++) for (int i=0; i<clazzIfaces.length; i++)
allIfaces.push(clazzIfaces[i]); allIfaces.push(clazzIfaces[i]);
} }
Class[] ifaceArray = new Class[ifaces.size()]; ClassHierarchy[] ifaceArray = new ClassHierarchy[ifaces.size()];
ifaces.copyInto(ifaceArray); ifaces.copyInto(ifaceArray);
return create(clazz, ifaceArray); return create(clazz, ifaceArray);
} }
@ -391,9 +374,9 @@ public class ClassInterfacesType extends Type {
public void useType() { public void useType() {
if (!jode.Decompiler.isTypeDebugging) { if (!jode.Decompiler.isTypeDebugging) {
if (clazz != null) if (clazz != null)
env.useClass(clazz); env.useClass(clazz.getName());
else if (ifaces.length > 0) else if (ifaces.length > 0)
env.useClass(ifaces[0]); env.useClass(ifaces[0].getName());
} }
} }
@ -415,11 +398,11 @@ public class ClassInterfacesType extends Type {
return sb.append("}").toString(); return sb.append("}").toString();
} else { } else {
if (clazz != null) if (clazz != null)
return env.classString(clazz); return env.classString(clazz.getName());
else if (ifaces.length > 0) else if (ifaces.length > 0)
return env.classString(ifaces[0]); return env.classString(ifaces[0].getName());
else else
return env.classString(cObject); return env.classString("java.lang.Object");
} }
} }
@ -428,13 +411,13 @@ public class ClassInterfacesType extends Type {
} }
public String getDefaultName() { public String getDefaultName() {
Class type; ClassHierarchy type;
if (clazz != null) if (clazz != null)
type = clazz; type = clazz;
else if (ifaces.length > 0) else if (ifaces.length > 0)
type = ifaces[0]; type = ifaces[0];
else else
type = cObject; type = ClassHierarchy.javaLangObject;
String name = type.getName(); String name = type.getName();
int dot = name.lastIndexOf('.'); int dot = name.lastIndexOf('.');
if (dot >= 0) if (dot >= 0)

@ -28,15 +28,6 @@ public class MethodType {
final Type returnType; final Type returnType;
final boolean staticFlag; final boolean staticFlag;
public MethodType(boolean isStatic, Class[] argTypes, Class retType) {
this.staticFlag = isStatic;
parameterTypes = new Type[argTypes.length];
for (int i=0; i < argTypes.length; i++)
parameterTypes[i] = Type.tType(argTypes[i]);
returnType = Type.tType(retType);
}
public MethodType(boolean isStatic, String signature) { public MethodType(boolean isStatic, String signature) {
this.staticFlag = isStatic; this.staticFlag = isStatic;
int index = 1, types = 0; int index = 1, types = 0;

@ -144,34 +144,11 @@ public class Type {
throw new AssertError("Unknown type signature: "+type); throw new AssertError("Unknown type signature: "+type);
} }
public static final Type tType(Class clazz) {
if (clazz.isArray())
return tArray(tType(clazz.getComponentType()));
if (clazz.isPrimitive()) {
return clazz == Boolean.TYPE ? tBoolean
: clazz == Byte.TYPE ? tByte
: clazz == Character.TYPE ? tChar
: clazz == Short.TYPE ? tShort
: clazz == Integer.TYPE ? tInt
: clazz == Float.TYPE ? tFloat
: clazz == Long.TYPE ? tLong
: clazz == Double.TYPE ? tDouble
: clazz == Void.TYPE ? tVoid
: tError;
}
return new ClassInterfacesType(clazz);
}
public static final Type tClass(String clazzname) { public static final Type tClass(String clazzname) {
clazzname = clazzname.replace('/', '.'); clazzname = clazzname.replace('/', '.');
Object result = classHash.get(clazzname); Object result = classHash.get(clazzname);
if (result == null) { if (result == null) {
try { result = new ClassInterfacesType(clazzname);
Class clazz = Class.forName(clazzname);
result = new ClassInterfacesType(clazzname);
} catch (ClassNotFoundException ex) {
result = new UnfoundClassType(clazzname);
}
classHash.put(clazzname, result); classHash.put(clazzname, result);
} }
return (Type) result; return (Type) result;

Loading…
Cancel
Save