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 {
}
public ArgType getType() {
return field.getType();
return ArgType.tryToResolveClassAlias(field.dex(), field.getType());
}
public int getDecompiledLine() {
......
package jadx.api;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.nodes.MethodNode;
public final class JavaMethod implements JavaNode {
......@@ -40,11 +44,27 @@ public final class JavaMethod implements JavaNode {
}
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() {
return mth.getReturnType();
ArgType retType = mth.getReturnType();
if (retType == null) {
retType = mth.getMethodInfo().getReturnType();
}
return ArgType.tryToResolveClassAlias(mth.dex(), retType);
}
public boolean isConstructor() {
......
......@@ -5,6 +5,8 @@ import java.util.Collections;
import java.util.List;
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.RootNode;
import jadx.core.dex.nodes.parser.SignatureParser;
......@@ -620,6 +622,31 @@ public abstract class ArgType {
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
public String toString() {
return "ARG_TYPE";
......
......@@ -91,9 +91,8 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode {
if (noCode) {
return;
}
retType = null;
// don't unload retType and argsList, will be used in jadx-gui after class unload
thisArg = null;
argsList = Collections.emptyList();
sVars = Collections.emptyList();
genericMap = null;
instructions = null;
......
......@@ -65,17 +65,21 @@ public class Utils {
}
public static String typeFormat(String name, ArgType type) {
return "<html><body><nobr>" + name
+ "<span style='color:#888888;'> : " + typeStr(type) + "</span>"
return "<html><body><nobr>" + escapeHtml(name)
+ "<span style='color:#888888;'> " + escapeHtml(typeStr(type)) + "</span>"
+ "</nobr></body></html>";
}
public static String escapeHtml(String str) {
return str.replace("<", "&lt;");
}
public static String typeStr(ArgType type) {
if (type == null) {
return "null";
}
if (type.isObject()) {
String cls = type.getObject();
String cls = type.toString();
int dot = cls.lastIndexOf('.');
if (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