gui: remove not generated elements from class node tree

This commit is contained in:
Skylot
2013-12-27 23:17:27 +04:00
parent 438b3b50d9
commit ebf06fde65
10 changed files with 132 additions and 53 deletions
+21 -17
View File
@@ -1,6 +1,7 @@
package jadx.api;
import jadx.core.codegen.CodeWriter;
import jadx.core.dex.attributes.AttributeFlag;
import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.FieldNode;
@@ -15,44 +16,47 @@ public final class JavaClass {
private final Decompiler decompiler;
private final ClassNode cls;
private final List<JavaClass> innerClasses;
private final List<JavaField> fields;
private final List<JavaMethod> methods;
private List<JavaClass> innerClasses = Collections.emptyList();
private List<JavaField> fields = Collections.emptyList();
private List<JavaMethod> methods = Collections.emptyList();
JavaClass(Decompiler decompiler, ClassNode classNode) {
this.decompiler = decompiler;
this.cls = classNode;
}
public void decompile() {
decompiler.processClass(cls);
int inClsCount = cls.getInnerClasses().size();
if (inClsCount == 0) {
this.innerClasses = Collections.emptyList();
} else {
if (inClsCount != 0) {
List<JavaClass> list = new ArrayList<JavaClass>(inClsCount);
for (ClassNode inner : cls.getInnerClasses()) {
list.add(new JavaClass(decompiler, inner));
if (!inner.getAttributes().contains(AttributeFlag.DONT_GENERATE)) {
list.add(new JavaClass(decompiler, inner));
}
}
this.innerClasses = Collections.unmodifiableList(list);
}
int fieldsCount = cls.getFields().size();
if (fieldsCount == 0) {
this.fields = Collections.emptyList();
} else {
if (fieldsCount != 0) {
List<JavaField> flds = new ArrayList<JavaField>(fieldsCount);
for (FieldNode f : cls.getFields()) {
flds.add(new JavaField(f));
if (!f.getAttributes().contains(AttributeFlag.DONT_GENERATE)) {
flds.add(new JavaField(f));
}
}
this.fields = Collections.unmodifiableList(flds);
}
int methodsCount = cls.getMethods().size();
if (methodsCount == 0) {
this.methods = Collections.emptyList();
} else {
if (methodsCount != 0) {
List<JavaMethod> mths = new ArrayList<JavaMethod>(methodsCount);
for (MethodNode m : cls.getMethods()) {
if (!m.getAccessFlags().isSynthetic()) {
mths.add(new JavaMethod(m));
if (!m.getAttributes().contains(AttributeFlag.DONT_GENERATE)) {
mths.add(new JavaMethod(this, m));
}
}
Collections.sort(mths, new Comparator<JavaMethod>() {
@@ -68,7 +72,7 @@ public final class JavaClass {
public String getCode() {
CodeWriter code = cls.getCode();
if (code == null) {
decompiler.processClass(cls);
decompile();
code = cls.getCode();
}
return code != null ? code.toString() : "error processing class";
@@ -1,7 +1,6 @@
package jadx.api;
import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.info.MethodInfo;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.nodes.MethodNode;
@@ -9,19 +8,19 @@ import java.util.List;
public final class JavaMethod {
private final MethodNode mth;
private final JavaClass parent;
public JavaMethod(MethodNode m) {
public JavaMethod(JavaClass cls, MethodNode m) {
this.parent = cls;
this.mth = m;
}
public String getName() {
MethodInfo mi = mth.getMethodInfo();
if (mi.isConstructor()) {
return mth.getParentClass().getShortName();
} else if (mi.isClassInit()) {
return "static";
}
return mi.getName();
return mth.getMethodInfo().getName();
}
public JavaClass getDeclaringClass() {
return parent;
}
public AccessInfo getAccessFlags() {
@@ -216,9 +216,9 @@ public class ClassGen {
CodeWriter code = new CodeWriter(clsCode.getIndent() + 1);
for (Iterator<MethodNode> it = mthList.iterator(); it.hasNext(); ) {
MethodNode mth = it.next();
if (mth.getAttributes().contains(AttributeFlag.DONT_GENERATE))
if (mth.getAttributes().contains(AttributeFlag.DONT_GENERATE)) {
continue;
}
try {
if (mth.getAccessFlags().isAbstract() || mth.getAccessFlags().isNative()) {
MethodGen mthGen = new MethodGen(this, mth);
@@ -232,9 +232,6 @@ public class ClassGen {
}
code.add(';');
} else {
if (mth.isNoCode())
continue;
MethodGen mthGen = new MethodGen(this, mth);
if (mth.getAttributes().contains(AttributeFlag.INCONSISTENT_CODE)) {
code.startLine("/* JADX WARNING: inconsistent code */");
@@ -253,9 +250,9 @@ public class ClassGen {
String msg = ErrorsCounter.methodError(mth, "Method generation error", e);
code.startLine("/* " + msg + CodeWriter.NL + Utils.getStackTrace(e) + " */");
}
if (it.hasNext())
if (it.hasNext()) {
code.newLine();
}
}
return code;
}
@@ -533,6 +533,7 @@ public class InsnGen {
} else {
parent = cls.getSuperClass();
}
cls.getAttributes().add(AttributeFlag.DONT_GENERATE);
MethodNode defCtr = cls.getDefaultConstructor();
if (RegionUtils.notEmpty(defCtr.getRegion())) {
defCtr.getAttributes().add(AttributeFlag.ANONYMOUS_CONSTRUCTOR);
@@ -124,14 +124,13 @@ public class MethodNode extends LineAttrNode implements ILoadable {
@Override
public void unload() {
if (noCode)
if (noCode) {
return;
}
if (instructions != null) instructions.clear();
blocks = null;
exitBlocks = null;
if (exceptionHandlers != null) exceptionHandlers.clear();
getAttributes().clear();
noCode = true;
}