Commit 4a0aacf1 authored by Skylot's avatar Skylot

gui: fix inner classes opening

parent 917cf20d
......@@ -6,6 +6,7 @@ import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.FieldNode;
import jadx.core.dex.nodes.MethodNode;
import jadx.core.utils.exceptions.JadxRuntimeException;
import java.util.ArrayList;
import java.util.Collections;
......@@ -27,14 +28,22 @@ public final class JavaClass {
}
public void decompile() {
if (decompiler == null) {
throw new JadxRuntimeException("Can't decompile inner class");
}
decompiler.processClass(cls);
load();
}
private void load() {
int inClsCount = cls.getInnerClasses().size();
if (inClsCount != 0) {
List<JavaClass> list = new ArrayList<JavaClass>(inClsCount);
for (ClassNode inner : cls.getInnerClasses()) {
if (!inner.getAttributes().contains(AttributeFlag.DONT_GENERATE)) {
list.add(new JavaClass(decompiler, inner));
JavaClass javaClass = new JavaClass(null, inner);
javaClass.load();
list.add(javaClass);
}
}
this.innerClasses = Collections.unmodifiableList(list);
......
......@@ -149,10 +149,9 @@ public class MainWindow extends JFrame {
Object obj = tree.getLastSelectedPathComponent();
if (obj instanceof JNode) {
JNode node = (JNode) obj;
if (node.getJParent() != null) {
showCode(node.getJParent(), node.getLine());
} else if (node.getClass() == JClass.class) {
showCode((JClass) node, node.getLine());
JClass cls = node.getRootClass();
if (cls != null) {
showCode(cls, node.getLine());
}
}
}
......@@ -392,7 +391,7 @@ public class MainWindow extends JFrame {
Object node = path.getLastPathComponent();
if (node instanceof JClass) {
JClass cls = (JClass) node;
cls.load();
cls.getRootClass().load();
}
}
......
......@@ -22,11 +22,19 @@ public class JClass extends JNode {
private static final ImageIcon ICON_ANNOTATION = Utils.openIcon("annotation_obj");
private final JavaClass cls;
private JClass jParrent;
private final JClass jParent;
private boolean loaded;
public JClass(JavaClass cls) {
this.cls = cls;
this.jParent = null;
this.loaded = false;
}
public JClass(JavaClass cls, JClass parent) {
this.cls = cls;
this.jParent = parent;
this.loaded = true;
}
public JavaClass getCls() {
......@@ -47,18 +55,16 @@ public class JClass extends JNode {
if (!loaded) {
add(new TextNode(NLS.str("tree.loading")));
} else {
JClass currentParent = jParrent == null ? this : jParrent;
for (JavaClass javaClass : cls.getInnerClasses()) {
JClass child = new JClass(javaClass);
child.setJParent(currentParent);
child.updateChilds();
JClass child = new JClass(javaClass, this);
add(child);
child.updateChilds();
}
for (JavaField f : cls.getFields()) {
add(new JField(f, currentParent));
add(new JField(f, this));
}
for (JavaMethod m : cls.getMethods()) {
add(new JMethod(m, currentParent));
add(new JMethod(m, this));
}
}
}
......@@ -88,13 +94,17 @@ public class JClass extends JNode {
}
}
public void setJParent(JClass parent) {
this.jParrent = parent;
@Override
public JClass getJParent() {
return jParent;
}
@Override
public JClass getJParent() {
return jParrent;
public JClass getRootClass() {
if (jParent == null) {
return this;
}
return jParent.getRootClass();
}
@Override
......
......@@ -37,6 +37,11 @@ public class JField extends JNode {
}
@Override
public JClass getRootClass() {
return jParent.getRootClass();
}
@Override
public int getLine() {
return field.getDecompiledLine();
}
......@@ -45,8 +50,12 @@ public class JField extends JNode {
public Icon getIcon() {
AccessInfo af = field.getAccessFlags();
OverlayIcon icon = Utils.makeIcon(af, ICON_FLD_PUB, ICON_FLD_PRI, ICON_FLD_PRO, ICON_FLD_DEF);
if (af.isTransient()) icon.add(ICON_TRANSIENT);
if (af.isVolatile()) icon.add(ICON_VOLATILE);
if (af.isTransient()) {
icon.add(ICON_TRANSIENT);
}
if (af.isVolatile()) {
icon.add(ICON_VOLATILE);
}
return icon;
}
......
......@@ -22,11 +22,11 @@ public class JMethod extends JNode {
private static final ImageIcon ICON_SYNC = Utils.openIcon("synch_co");
private final JavaMethod mth;
private final JClass jparent;
private final JClass jParent;
public JMethod(JavaMethod javaMethod, JClass jClass) {
this.mth = javaMethod;
this.jparent = jClass;
this.jParent = jClass;
}
@Override
......@@ -35,7 +35,12 @@ public class JMethod extends JNode {
@Override
public JClass getJParent() {
return jparent;
return jParent;
}
@Override
public JClass getRootClass() {
return jParent.getRootClass();
}
@Override
......
......@@ -7,6 +7,13 @@ public abstract class JNode extends DefaultMutableTreeNode {
public abstract JClass getJParent();
/**
* Return top level JClass or self if already at top.
*/
public JClass getRootClass() {
return null;
}
public abstract int getLine();
public abstract void updateChilds();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment