Commit 62826334 authored by Skylot's avatar Skylot

fix(gui): use alias for field and method types in tree view

parent 19cf7c9f
...@@ -39,7 +39,7 @@ public final class JavaField implements JavaNode { ...@@ -39,7 +39,7 @@ public final class JavaField implements JavaNode {
} }
public ArgType getType() { public ArgType getType() {
return field.getType(); return ArgType.tryToResolveClassAlias(field.dex(), field.getType());
} }
public int getDecompiledLine() { public int getDecompiledLine() {
......
package jadx.api; package jadx.api;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jadx.core.dex.info.AccessInfo; import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
public final class JavaMethod implements JavaNode { public final class JavaMethod implements JavaNode {
...@@ -40,11 +44,27 @@ public final class JavaMethod implements JavaNode { ...@@ -40,11 +44,27 @@ public final class JavaMethod implements JavaNode {
} }
public List<ArgType> getArguments() { public List<ArgType> getArguments() {
return mth.getMethodInfo().getArgumentsTypes(); if (mth.getMethodInfo().getArgumentsTypes().isEmpty()) {
return Collections.emptyList();
}
List<RegisterArg> arguments = mth.getArguments(false);
Stream<ArgType> argTypeStream;
if (arguments == null || arguments.isEmpty() || mth.isNoCode()) {
argTypeStream = mth.getMethodInfo().getArgumentsTypes().stream();
} else {
argTypeStream = arguments.stream().map(RegisterArg::getType);
}
return argTypeStream
.map(type -> ArgType.tryToResolveClassAlias(mth.dex(), type))
.collect(Collectors.toList());
} }
public ArgType getReturnType() { public ArgType getReturnType() {
return mth.getReturnType(); ArgType retType = mth.getReturnType();
if (retType == null) {
retType = mth.getMethodInfo().getReturnType();
}
return ArgType.tryToResolveClassAlias(mth.dex(), retType);
} }
public boolean isConstructor() { public boolean isConstructor() {
......
...@@ -5,6 +5,8 @@ import java.util.Collections; ...@@ -5,6 +5,8 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import jadx.core.Consts; import jadx.core.Consts;
import jadx.core.dex.info.ClassInfo;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.DexNode; import jadx.core.dex.nodes.DexNode;
import jadx.core.dex.nodes.RootNode; import jadx.core.dex.nodes.RootNode;
import jadx.core.dex.nodes.parser.SignatureParser; import jadx.core.dex.nodes.parser.SignatureParser;
...@@ -620,6 +622,31 @@ public abstract class ArgType { ...@@ -620,6 +622,31 @@ public abstract class ArgType {
return 1; return 1;
} }
public static ArgType tryToResolveClassAlias(DexNode dex, ArgType type) {
if (!type.isObject() || type.isGenericType()) {
return type;
}
ClassNode cls = dex.resolveClass(type);
if (cls == null) {
return type;
}
ClassInfo clsInfo = cls.getClassInfo();
if (!clsInfo.hasAlias()) {
return type;
}
String aliasFullName = clsInfo.getAliasFullName();
if (type.isGeneric()) {
if (type instanceof GenericObject) {
return new GenericObject(aliasFullName, type.getGenericTypes());
}
if (type instanceof WildcardType) {
return new WildcardType(ArgType.object(aliasFullName), type.getWildcardBounds());
}
}
return ArgType.object(aliasFullName);
}
@Override @Override
public String toString() { public String toString() {
return "ARG_TYPE"; return "ARG_TYPE";
......
...@@ -91,9 +91,8 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode { ...@@ -91,9 +91,8 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode {
if (noCode) { if (noCode) {
return; return;
} }
retType = null; // don't unload retType and argsList, will be used in jadx-gui after class unload
thisArg = null; thisArg = null;
argsList = Collections.emptyList();
sVars = Collections.emptyList(); sVars = Collections.emptyList();
genericMap = null; genericMap = null;
instructions = null; instructions = null;
......
...@@ -65,17 +65,21 @@ public class Utils { ...@@ -65,17 +65,21 @@ public class Utils {
} }
public static String typeFormat(String name, ArgType type) { public static String typeFormat(String name, ArgType type) {
return "<html><body><nobr>" + name return "<html><body><nobr>" + escapeHtml(name)
+ "<span style='color:#888888;'> : " + typeStr(type) + "</span>" + "<span style='color:#888888;'> " + escapeHtml(typeStr(type)) + "</span>"
+ "</nobr></body></html>"; + "</nobr></body></html>";
} }
public static String escapeHtml(String str) {
return str.replace("<", "&lt;");
}
public static String typeStr(ArgType type) { public static String typeStr(ArgType type) {
if (type == null) { if (type == null) {
return "null"; return "null";
} }
if (type.isObject()) { if (type.isObject()) {
String cls = type.getObject(); String cls = type.toString();
int dot = cls.lastIndexOf('.'); int dot = cls.lastIndexOf('.');
if (dot != -1) { if (dot != -1) {
return cls.substring(dot + 1); return cls.substring(dot + 1);
......
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