inner/anonymous classes handling in constructors

new option syntax


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@736 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent c4a1eb3917
commit 95916f7a1b
  1. 86
      jode/jode/decompiler/MethodAnalyzer.java

@ -19,6 +19,7 @@
package jode.decompiler; package jode.decompiler;
import jode.bytecode.MethodInfo; import jode.bytecode.MethodInfo;
import jode.jvm.SyntheticAnalyzer;
import jode.type.*; import jode.type.*;
import jode.AssertError; import jode.AssertError;
import jode.Decompiler; import jode.Decompiler;
@ -29,32 +30,27 @@ import java.io.*;
public class MethodAnalyzer implements Analyzer { public class MethodAnalyzer implements Analyzer {
ImportHandler imports; ImportHandler imports;
CodeAnalyzer code = null;
ClassAnalyzer classAnalyzer; ClassAnalyzer classAnalyzer;
boolean isConstructor; MethodInfo minfo;
boolean isStatic;
boolean isSynthetic;
boolean isDeprecated;
int modifiers;
String methodName; String methodName;
MethodType methodType; MethodType methodType;
boolean isConstructor;
CodeAnalyzer code = null;
Type[] exceptions; Type[] exceptions;
boolean analyzed = false;
SyntheticAnalyzer synth; SyntheticAnalyzer synth;
public MethodAnalyzer(ClassAnalyzer cla, MethodInfo minfo, public MethodAnalyzer(ClassAnalyzer cla, MethodInfo minfo,
ImportHandler imports) { ImportHandler imports) {
this.classAnalyzer = cla; this.classAnalyzer = cla;
this.imports = imports; this.imports = imports;
this.modifiers = minfo.getModifiers(); this.minfo = minfo;
this.methodType = Type.tMethod(minfo.getType());
this.methodName = minfo.getName(); this.methodName = minfo.getName();
this.isStatic = minfo.isStatic(); this.methodType = Type.tMethod(minfo.getType());
this.isConstructor = this.isConstructor =
methodName.equals("<init>") || methodName.equals("<clinit>"); methodName.equals("<init>") || methodName.equals("<clinit>");
this.isSynthetic = minfo.isSynthetic();
this.isDeprecated = minfo.isDeprecated();
if (minfo.getBytecode() != null) if (minfo.getBytecode() != null)
code = new CodeAnalyzer(this, minfo, imports); code = new CodeAnalyzer(this, minfo, imports);
@ -67,6 +63,8 @@ public class MethodAnalyzer implements Analyzer {
for (int i=0; i< excCount; i++) for (int i=0; i< excCount; i++)
exceptions[i] = Type.tClass(excattr[i]); exceptions[i] = Type.tClass(excattr[i]);
} }
if (minfo.isSynthetic() || methodName.indexOf('$') != -1)
synth = new SyntheticAnalyzer(minfo, true);
} }
public String getName() { public String getName() {
@ -90,17 +88,15 @@ public class MethodAnalyzer implements Analyzer {
} }
public final boolean isStatic() { public final boolean isStatic() {
return isStatic; return minfo.isStatic();
} }
public final boolean isSynthetic() { public final boolean isSynthetic() {
return isSynthetic; return minfo.isSynthetic();
} }
public final boolean isGetClass() { public final SyntheticAnalyzer getSynthetic() {
if (synth == null) return synth;
analyzeSynthetic();
return synth.type == SyntheticAnalyzer.GETCLASS;
} }
public Type getReturnType() { public Type getReturnType() {
@ -113,15 +109,21 @@ public class MethodAnalyzer implements Analyzer {
if (code == null) if (code == null)
return; return;
analyzed = true;
int offset = 0; int offset = 0;
if (!isStatic()) { if (!isStatic()) {
LocalInfo clazz = code.getParamInfo(0); LocalInfo clazz = code.getParamInfo(0);
clazz.setType clazz.setType(Type.tClass(classAnalyzer.getClazz()));
(Type.tClass(this.classAnalyzer.getClazz().getName()));
clazz.setName("this"); clazz.setName("this");
offset++; offset++;
} }
if (isConstructor()
&& classAnalyzer.getParent() instanceof ClassAnalyzer) {
ClassAnalyzer parent = (ClassAnalyzer) classAnalyzer.getParent();
LocalInfo clazz = code.getParamInfo(1);
clazz.setType(Type.tClass(parent.getClazz()));
clazz.setName("this$-1");
}
Type[] paramTypes = methodType.getParameterTypes(); Type[] paramTypes = methodType.getParameterTypes();
for (int i=0; i< paramTypes.length; i++) { for (int i=0; i< paramTypes.length; i++) {
@ -135,7 +137,7 @@ public class MethodAnalyzer implements Analyzer {
if (!isConstructor) if (!isConstructor)
imports.useType(methodType.getReturnType()); imports.useType(methodType.getReturnType());
if (!Decompiler.immediateOutput) { if ((Decompiler.options & Decompiler.OPTION_IMMEDIATE) == 0) {
if (GlobalOptions.verboseLevel > 0) if (GlobalOptions.verboseLevel > 0)
GlobalOptions.err.print(methodName+": "); GlobalOptions.err.print(methodName+": ");
code.analyze(); code.analyze();
@ -144,21 +146,17 @@ public class MethodAnalyzer implements Analyzer {
} }
} }
public void analyzeSynthetic() {
if (!analyzed)
analyze();
synth = new SyntheticAnalyzer(this);
}
public void dumpSource(TabbedPrintWriter writer) public void dumpSource(TabbedPrintWriter writer)
throws IOException throws IOException
{ {
if (synth != null && synth.type == synth.GETCLASS) if (synth != null && synth.getKind() != synth.UNKNOWN)
// We don't need this class anymore (hopefully?) // We don't need this class anymore (hopefully?)
return; return;
if (isConstructor && classAnalyzer.constructors.length == 1 if (isConstructor && classAnalyzer.constructors.length == 1
&& methodType.getParameterTypes().length == 0 && (methodType.getParameterTypes().length == 0
|| (methodType.getParameterTypes().length == 1
&& classAnalyzer.parent instanceof ClassAnalyzer))
&& getMethodHeader() != null && getMethodHeader() != null
&& getMethodHeader().getBlock() instanceof jode.flow.EmptyBlock && getMethodHeader().getBlock() instanceof jode.flow.EmptyBlock
&& getMethodHeader().hasNoJumps()) && getMethodHeader().hasNoJumps())
@ -166,7 +164,8 @@ public class MethodAnalyzer implements Analyzer {
// takes no parameters, this is the default constructor. // takes no parameters, this is the default constructor.
return; return;
if (Decompiler.immediateOutput && code != null) { if ((Decompiler.options & Decompiler.OPTION_IMMEDIATE) != 0
&& code != null) {
// We do the code.analyze() here, to get // We do the code.analyze() here, to get
// immediate output. // immediate output.
@ -183,19 +182,21 @@ public class MethodAnalyzer implements Analyzer {
writer.println(); writer.println();
if (isDeprecated) { if (minfo.isDeprecated()) {
writer.println("/**"); writer.println("/**");
writer.println(" * @deprecated"); writer.println(" * @deprecated");
writer.println(" */"); writer.println(" */");
} }
String modif = Modifier.toString(modifiers); if (minfo.isSynthetic())
writer.print("/*synthetic*/ ");
String modif = Modifier.toString(minfo.getModifiers());
if (modif.length() > 0) if (modif.length() > 0)
writer.print(modif+" "); writer.print(modif+" ");
if (isConstructor && isStatic()) if (isConstructor && isStatic())
writer.print(""); /* static block */ writer.print(""); /* static block */
else { else {
if (isConstructor) if (isConstructor)
writer.print(imports.getClassString(classAnalyzer.getClazz())); writer.print(classAnalyzer.getName());
else { else {
writer.printType(getReturnType()); writer.printType(getReturnType());
writer.print(" " + methodName); writer.print(" " + methodName);
@ -204,8 +205,15 @@ public class MethodAnalyzer implements Analyzer {
Type[] paramTypes = methodType.getParameterTypes(); Type[] paramTypes = methodType.getParameterTypes();
int offset = isStatic()?0:1; int offset = isStatic()?0:1;
int start = 0;
if (isConstructor()
&& classAnalyzer.getParent() instanceof ClassAnalyzer) {
start++;
offset++;
}
LocalInfo[] param = new LocalInfo[paramTypes.length]; LocalInfo[] param = new LocalInfo[paramTypes.length];
for (int i=0; i<paramTypes.length; i++) { for (int i=start; i<paramTypes.length; i++) {
if (code == null) { if (code == null) {
param[i] = new LocalInfo(offset); param[i] = new LocalInfo(offset);
param[i].setType(paramTypes[i]); param[i].setType(paramTypes[i]);
@ -223,8 +231,8 @@ public class MethodAnalyzer implements Analyzer {
} }
} }
for (int i=0; i<paramTypes.length; i++) { for (int i=start; i<paramTypes.length; i++) {
if (i>0) if (i>start)
writer.print(", "); writer.print(", ");
writer.printType(param[i].getType()); writer.printType(param[i].getType());
writer.print(" "+param[i].getName()); writer.print(" "+param[i].getName());
@ -249,4 +257,8 @@ public class MethodAnalyzer implements Analyzer {
} else } else
writer.println(";"); writer.println(";");
} }
public ClassAnalyzer getClassAnalyzer() {
return classAnalyzer;
}
} }

Loading…
Cancel
Save