gui: add type and access info to classes tree
This commit is contained in:
@@ -33,6 +33,7 @@ public class JClass extends DefaultMutableTreeNode implements JNode {
|
||||
|
||||
@Override
|
||||
public void updateChilds() {
|
||||
removeAllChildren();
|
||||
JClass currentParent = jParrent == null ? this : jParrent;
|
||||
for (JavaClass javaClass : cls.getInnerClasses()) {
|
||||
JClass child = new JClass(javaClass);
|
||||
|
||||
@@ -2,18 +2,22 @@ package jadx.gui.treemodel;
|
||||
|
||||
import jadx.api.JavaField;
|
||||
import jadx.core.dex.info.AccessInfo;
|
||||
import jadx.gui.utils.OverlayIcon;
|
||||
import jadx.gui.utils.Utils;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
public class JField extends DefaultMutableTreeNode implements JNode {
|
||||
public class JField extends DefaultMutableTreeNode implements JNode {
|
||||
private static final ImageIcon ICON_FLD_DEF = Utils.openIcon("field_default_obj");
|
||||
private static final ImageIcon ICON_FLD_PRI = Utils.openIcon("field_private_obj");
|
||||
private static final ImageIcon ICON_FLD_PRO = Utils.openIcon("field_protected_obj");
|
||||
private static final ImageIcon ICON_FLD_PUB = Utils.openIcon("field_public_obj");
|
||||
|
||||
private static final ImageIcon ICON_TRANSIENT = Utils.openIcon("transient_co");
|
||||
private static final ImageIcon ICON_VOLATILE = Utils.openIcon("volatile_co");
|
||||
|
||||
private final JavaField field;
|
||||
private final JClass jParent;
|
||||
|
||||
@@ -39,19 +43,14 @@ public class JField extends DefaultMutableTreeNode implements JNode {
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
AccessInfo af = field.getAccessFlags();
|
||||
if(af.isPublic()){
|
||||
return ICON_FLD_PUB;
|
||||
} else if(af.isPrivate()) {
|
||||
return ICON_FLD_PRI;
|
||||
} else if(af.isProtected()) {
|
||||
return ICON_FLD_PRO;
|
||||
} else {
|
||||
return ICON_FLD_DEF;
|
||||
}
|
||||
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);
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return field.getName();
|
||||
return Utils.typeFormat(field.getName(), field.getType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,14 @@ package jadx.gui.treemodel;
|
||||
|
||||
import jadx.api.JavaMethod;
|
||||
import jadx.core.dex.info.AccessInfo;
|
||||
import jadx.core.dex.instructions.args.ArgType;
|
||||
import jadx.gui.utils.OverlayIcon;
|
||||
import jadx.gui.utils.Utils;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class JMethod extends DefaultMutableTreeNode implements JNode {
|
||||
private static final ImageIcon ICON_MTH_DEF = Utils.openIcon("methdef_obj");
|
||||
@@ -14,6 +17,9 @@ public class JMethod extends DefaultMutableTreeNode implements JNode {
|
||||
private static final ImageIcon ICON_MTH_PRO = Utils.openIcon("methpro_obj");
|
||||
private static final ImageIcon ICON_MTH_PUB = Utils.openIcon("methpub_obj");
|
||||
|
||||
private static final ImageIcon ICON_CONSTRUCTOR = Utils.openIcon("constr_ovr");
|
||||
private static final ImageIcon ICON_SYNC = Utils.openIcon("synch_co");
|
||||
|
||||
private final JavaMethod mth;
|
||||
private final JClass jparent;
|
||||
|
||||
@@ -38,20 +44,28 @@ public class JMethod extends DefaultMutableTreeNode implements JNode {
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
AccessInfo af = mth.getAccessFlags();
|
||||
if (af.isPublic()) {
|
||||
return ICON_MTH_PUB;
|
||||
} else if (af.isPrivate()) {
|
||||
return ICON_MTH_PRI;
|
||||
} else if (af.isProtected()) {
|
||||
return ICON_MTH_PRO;
|
||||
} else {
|
||||
return ICON_MTH_DEF;
|
||||
}
|
||||
AccessInfo accessFlags = mth.getAccessFlags();
|
||||
OverlayIcon icon = Utils.makeIcon(accessFlags, ICON_MTH_PUB, ICON_MTH_PRI, ICON_MTH_PRO, ICON_MTH_DEF);
|
||||
if(accessFlags.isConstructor()) icon.add(ICON_CONSTRUCTOR);
|
||||
if (accessFlags.isSynchronized()) icon.add(ICON_SYNC);
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mth.getName();
|
||||
if (mth.isClassInit()) {
|
||||
return "{...}";
|
||||
}
|
||||
|
||||
StringBuilder base = new StringBuilder();
|
||||
base.append(mth.getName());
|
||||
base.append('(');
|
||||
for (Iterator<ArgType> it = mth.getArguments().iterator(); it.hasNext(); ) {
|
||||
base.append(Utils.typeStr(it.next()));
|
||||
if(it.hasNext())
|
||||
base.append(", ");
|
||||
}
|
||||
base.append(')');
|
||||
return Utils.typeFormat(base.toString(), mth.getReturnType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package jadx.gui.utils;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class OverlayIcon implements Icon {
|
||||
|
||||
private final Icon icon;
|
||||
private final List<Icon> icons = new ArrayList<Icon>(4);
|
||||
|
||||
private static final double A = 0.8;
|
||||
private static final double B = 0.2;
|
||||
private static final double[] pos = new double[]{A, B, B, B, A, A, B, A};
|
||||
|
||||
public OverlayIcon(Icon icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconHeight() {
|
||||
return icon.getIconHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconWidth() {
|
||||
return icon.getIconWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
int w = getIconWidth();
|
||||
int h = getIconHeight();
|
||||
|
||||
icon.paintIcon(c, g, x, y);
|
||||
int k = 0;
|
||||
for (Icon icon : icons) {
|
||||
int dx = (int) (pos[k++] * (w - icon.getIconWidth()));
|
||||
int dy = (int) (pos[k++] * (h - icon.getIconHeight()));
|
||||
icon.paintIcon(c, g, x + dx, y + dy);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Icon icon) {
|
||||
icons.add(icon);
|
||||
}
|
||||
|
||||
public void addAll(Collection<Icon> icons) {
|
||||
icons.addAll(icons);
|
||||
}
|
||||
|
||||
public List<Icon> getIcons() {
|
||||
return icons;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package jadx.gui.utils;
|
||||
|
||||
import jadx.core.dex.info.AccessInfo;
|
||||
import jadx.core.dex.instructions.args.ArgType;
|
||||
import jadx.core.utils.exceptions.JadxRuntimeException;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.KeyStroke;
|
||||
@@ -10,6 +13,11 @@ import java.net.URL;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static final ImageIcon ICON_STATIC = Utils.openIcon("static_co");
|
||||
private static final ImageIcon ICON_FINAL = Utils.openIcon("final_co");
|
||||
private static final ImageIcon ICON_ABSTRACT = Utils.openIcon("abstract_co");
|
||||
private static final ImageIcon ICON_NATIVE = Utils.openIcon("native_co");
|
||||
|
||||
public static ImageIcon openIcon(String name) {
|
||||
String iconPath = "/icons-16/" + name + ".png";
|
||||
URL resource = Utils.class.getResource(iconPath);
|
||||
@@ -23,4 +31,43 @@ public class Utils {
|
||||
comp.getInputMap().put(key, id);
|
||||
comp.getActionMap().put(id, action);
|
||||
}
|
||||
|
||||
public static String typeFormat(String name, ArgType type) {
|
||||
return "<html>" + name + "<span style='color:#888888;'> : " + typeStr(type) + "</span></html>";
|
||||
}
|
||||
|
||||
public static String typeStr(ArgType type) {
|
||||
if (type.isObject()) {
|
||||
String cls = type.getObject();
|
||||
int dot = cls.lastIndexOf('.');
|
||||
if (dot != -1) {
|
||||
return cls.substring(dot + 1);
|
||||
} else {
|
||||
return cls;
|
||||
}
|
||||
}
|
||||
if (type.isArray()) {
|
||||
return typeStr(type.getArrayElement()) + "[]";
|
||||
}
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
public static OverlayIcon makeIcon(AccessInfo af, Icon pub, Icon pri, Icon pro, Icon def) {
|
||||
Icon icon;
|
||||
if (af.isPublic()) {
|
||||
icon = pub;
|
||||
} else if (af.isPrivate()) {
|
||||
icon = pri;
|
||||
} else if (af.isProtected()) {
|
||||
icon = pro;
|
||||
} else {
|
||||
icon = def;
|
||||
}
|
||||
OverlayIcon overIcon = new OverlayIcon(icon);
|
||||
if (af.isFinal()) overIcon.add(ICON_FINAL);
|
||||
if (af.isStatic()) overIcon.add(ICON_STATIC);
|
||||
if (af.isAbstract()) overIcon.add(ICON_ABSTRACT);
|
||||
if (af.isNative()) overIcon.add(ICON_NATIVE);
|
||||
return overIcon;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user