generic class declaration works now, but generics are still not propagated correctly.

git-svn-id: https://svn.code.sf.net/p/jode/code/branches/generics@1401 379699f6-c40d-0410-875b-85095c16579e
generics
hoenicke 18 years ago
parent a9e2d0fdaa
commit b3b29c076a
  1. 16
      jode/.classpath
  2. 17
      jode/.project
  3. 40
      jode/src/net/sf/jode/decompiler/ClassAnalyzer.java
  4. 3
      jode/src/net/sf/jode/decompiler/MethodAnalyzer.java
  5. 40
      jode/src/net/sf/jode/decompiler/TabbedPrintWriter.java
  6. 4
      jode/src/net/sf/jode/expr/ConstantArrayOperator.java
  7. 5
      jode/src/net/sf/jode/type/ClassInfoType.java
  8. 4
      jode/src/net/sf/jode/type/ClassType.java

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="net/sf/jode/obfuscator/modules/LocalOptimizer.java|net/sf/jode/obfuscator/modules/RemovePopAnalyzer.java" kind="src" path="src"/>
<classpathentry excluding="src/|innerclasses/" kind="src" path="test"/>
<classpathentry kind="src" path="test/innerclasses"/>
<classpathentry kind="src" path="test/src"/>
<classpathentry kind="lib" path="lib/ant-junit.jar"/>
<classpathentry kind="lib" path="lib/collections.jar"/>
<classpathentry kind="lib" path="lib/jakarta-ant-1.3-optional.jar"/>
<classpathentry kind="lib" path="lib/java-getopt-1.0.8.jar"/>
<classpathentry kind="lib" path="lib/junit.jar"/>
<classpathentry kind="lib" path="release/jode-1.90-CVS.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="props"/>
<classpathentry kind="output" path="build"/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Jode</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -53,10 +53,11 @@ public class ClassAnalyzer
{ {
ImportHandler imports; ImportHandler imports;
ClassInfo clazz; ClassInfo clazz;
ClassType myType;
ClassDeclarer parent; ClassDeclarer parent;
ProgressListener progressListener; ProgressListener progressListener;
String[] generics; String[] generics;
Type[] genericTypes; GenericParameterType[] genericTypes;
/** /**
* The complexity for initi#alizing a class. * The complexity for initi#alizing a class.
@ -105,7 +106,7 @@ public class ClassAnalyzer
if (signature.charAt(0) == '<') { if (signature.charAt(0) == '<') {
String[] genericSignatures = TypeSignature.getGenericSignatures(signature); String[] genericSignatures = TypeSignature.getGenericSignatures(signature);
generics = new String[genericSignatures.length]; generics = new String[genericSignatures.length];
genericTypes = new Type[genericSignatures.length]; genericTypes = new GenericParameterType[genericSignatures.length];
for (int i = 0; i < generics.length; i++) { for (int i = 0; i < generics.length; i++) {
int colon = genericSignatures[i].indexOf(':'); int colon = genericSignatures[i].indexOf(':');
String genName; String genName;
@ -166,6 +167,7 @@ public class ClassAnalyzer
this.parent = parent; this.parent = parent;
this.clazz = clazz; this.clazz = clazz;
this.myType = Type.tClass(clazz, genericTypes);
this.imports = imports; this.imports = imports;
modifiers = clazz.getModifiers(); modifiers = clazz.getModifiers();
@ -244,6 +246,10 @@ public class ClassAnalyzer
return clazz; return clazz;
} }
public ClassType getType() {
return myType;
}
public String getName() { public String getName() {
return name; return name;
@ -505,6 +511,9 @@ public class ClassAnalyzer
{ {
dumpDeclaration(writer, null, 0.0, 0.0); dumpDeclaration(writer, null, 0.0, 0.0);
} }
public void dumpGenericDeclaration(GenericParameterType gen) {
}
public void dumpDeclaration(TabbedPrintWriter writer, public void dumpDeclaration(TabbedPrintWriter writer,
ProgressListener pl, double done, double scale) ProgressListener pl, double done, double scale)
@ -544,30 +553,23 @@ public class ClassAnalyzer
if (!clazz.isInterface()) if (!clazz.isInterface())
writer.print("class "); writer.print("class ");
writer.print(name); writer.print(name);
String signature = clazz.getSignature(); if (genericTypes != null) {
System.err.println("Class Signature: "+signature+ " (class "+name+")"); writer.print("<");
ClassInfo superClazz = clazz.getSuperclass(); writer.startOp(TabbedPrintWriter.EXPL_PAREN, 0);
if (superClazz != null && for (int i=0; i< genericTypes.length; i++) {
superClazz.getName() != "java.lang.Object") {
writer.breakOp();
writer.print(" extends " + (writer.getClassString
(superClazz, Scope.CLASSNAME)));
}
ClassInfo[] interfaces = clazz.getInterfaces();
if (interfaces.length > 0) {
writer.breakOp();
writer.print(clazz.isInterface() ? " extends " : " implements ");
writer.startOp(writer.EXPL_PAREN, 1);
for (int i=0; i < interfaces.length; i++) {
if (i > 0) { if (i > 0) {
writer.print(", "); writer.print(", ");
writer.breakOp(); writer.breakOp();
} }
writer.print(writer.getClassString writer.print(genericTypes[i].getClassName());
(interfaces[i], Scope.CLASSNAME)); writer.printExtendsImplements(genericTypes[i]);
} }
writer.endOp(); writer.endOp();
writer.print(">");
} }
String signature = clazz.getSignature();
System.err.println("Class Signature: "+signature+ " (class "+name+")");
writer.printExtendsImplements(Type.tClass(clazz));
writer.println(); writer.println();
writer.openBraceClass(); writer.openBraceClass();

@ -461,8 +461,7 @@ public class MethodAnalyzer implements Scope, ClassDeclarer {
Block[] blocks = bb.getBlocks(); Block[] blocks = bb.getBlocks();
FlowBlock[] flows = new FlowBlock[blocks.length]; FlowBlock[] flows = new FlowBlock[blocks.length];
int returnCount; TransformExceptionHandlers excHandlers;
TransformExceptionHandlers excHandlers;
{ {
for (int i=0; i < blocks.length; i++) for (int i=0; i < blocks.length; i++)
flows[i] = new FlowBlock(this, i, i > 0 ? flows[i-1]: null); flows[i] = new FlowBlock(this, i, i > 0 ? flows[i-1]: null);

@ -619,6 +619,29 @@ public class TabbedPrintWriter {
print(getTypeString(type)); print(getTypeString(type));
} }
public void printExtendsImplements(ClassType clazz) {
ClassType superClazz = clazz.getSuperClass();
if (superClazz != null &&
superClazz.getClassName() != "java.lang.Object") {
breakOp();
print(" extends " + getTypeString(superClazz));
}
ClassType[] interfaces = clazz.getInterfaces();
if (interfaces.length > 0) {
breakOp();
print(clazz.isInterface() ? " extends " : " implements ");
startOp(EXPL_PAREN, 1);
for (int i=0; i < interfaces.length; i++) {
if (i > 0) {
print(", ");
breakOp();
}
print(getTypeString(interfaces[i]));
}
endOp();
}
}
public void pushScope(Scope scope) { public void pushScope(Scope scope) {
scopes.push(scope); scopes.push(scope);
} }
@ -708,8 +731,21 @@ public class TabbedPrintWriter {
if (type instanceof ArrayType) if (type instanceof ArrayType)
return getTypeString(((ArrayType) type).getElementType()) + "[]"; return getTypeString(((ArrayType) type).getElementType()) + "[]";
else if (type instanceof ClassInfoType) { else if (type instanceof ClassInfoType) {
ClassInfo clazz = ((ClassInfoType) type).getClassInfo(); ClassInfoType classInfoType = (ClassInfoType) type;
return getClassString(clazz, Scope.CLASSNAME); ClassInfo clazz = classInfoType.getClassInfo();
String clazzName = getClassString(clazz, Scope.CLASSNAME);
Type[] genInstances = classInfoType.getGenericInstances();
if (genInstances == null)
return clazzName;
StringBuffer sb = new StringBuffer(clazzName);
sb.append("<");
for (int i = 0; i < genInstances.length; i++) {
if (i > 0)
sb.append(",");
sb.append(getTypeString(genInstances[i]));
}
sb.append(">");
return sb.toString();
} else if (type instanceof ClassType) { } else if (type instanceof ClassType) {
String name = ((ClassType) type).getClassName(); String name = ((ClassType) type).getClassName();
if (imports != null) { if (imports != null) {

@ -33,7 +33,7 @@ public class ConstantArrayOperator extends Operator {
? Type.tSubType(((ArrayType)type).getElementType()) : Type.tError; ? Type.tSubType(((ArrayType)type).getElementType()) : Type.tError;
Object emptyVal; Object emptyVal;
if (argType == type.tError || argType.isOfType(Type.tUObject)) if (argType == Type.tError || argType.isOfType(Type.tUObject))
emptyVal = null; emptyVal = null;
else if (argType.isOfType(Type.tBoolUInt)) else if (argType.isOfType(Type.tBoolUInt))
emptyVal = new Integer(0); emptyVal = new Integer(0);
@ -104,7 +104,7 @@ public class ConstantArrayOperator extends Operator {
writer.print(" "); writer.print(" ");
} }
writer.print("{ "); writer.print("{ ");
writer.startOp(writer.EXPL_PAREN, 0); writer.startOp(TabbedPrintWriter.EXPL_PAREN, 0);
for (int i=0; i< subExpressions.length; i++) { for (int i=0; i< subExpressions.length; i++) {
if (i>0) { if (i>0) {
writer.print(", "); writer.print(", ");

@ -21,18 +21,13 @@ package net.sf.jode.type;
import net.sf.jode.bytecode.ClassInfo; import net.sf.jode.bytecode.ClassInfo;
import net.sf.jode.bytecode.TypeSignature; import net.sf.jode.bytecode.TypeSignature;
import net.sf.jode.util.SimpleMap; import net.sf.jode.util.SimpleMap;
import net.sf.jode.util.SimpleSet;
import net.sf.jode.GlobalOptions; import net.sf.jode.GlobalOptions;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.io.IOException; import java.io.IOException;
import java.util.Vector;
import java.util.Stack;
import java.util.Hashtable;
///#def COLLECTIONS java.util ///#def COLLECTIONS java.util
import java.util.Map; import java.util.Map;
import java.util.Set;
///#enddef ///#enddef
/** /**

@ -100,6 +100,10 @@ public abstract class ClassType extends ReferenceType {
* @return the interfaces' types. * @return the interfaces' types.
*/ */
public abstract ClassType[] getInterfaces(); public abstract ClassType[] getInterfaces();
public Type[] getGenericInstances() {
return genericInstances;
}
/** /**
* Returns true, if all types in this type set are a super type of * Returns true, if all types in this type set are a super type of

Loading…
Cancel
Save