From 21e94d8d5c75b232a95baf5bbfe11a257edca47b Mon Sep 17 00:00:00 2001 From: Skylot Date: Fri, 20 May 2022 21:37:37 +0100 Subject: [PATCH] fix(gui): use alias for types in tooltips (#1487) --- .../core/dex/instructions/args/ArgType.java | 43 +++++++++++-------- .../main/java/jadx/gui/treemodel/JNode.java | 2 +- .../ui/codearea/MouseHoverHighlighter.java | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java b/jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java index 061aa95d6e7..9d7025c092e 100644 --- a/jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java +++ b/jadx-core/src/main/java/jadx/core/dex/instructions/args/ArgType.java @@ -12,9 +12,9 @@ import jadx.core.Consts; import jadx.core.dex.info.ClassInfo; -import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.RootNode; import jadx.core.dex.visitors.typeinference.TypeCompareEnum; +import jadx.core.utils.ListUtils; import jadx.core.utils.Utils; import jadx.core.utils.exceptions.JadxRuntimeException; @@ -874,28 +874,37 @@ public R visitTypes(Function visitor) { } public static ArgType tryToResolveClassAlias(RootNode root, ArgType type) { - if (!type.isObject() || type.isGenericType()) { + if (type.isGenericType()) { return type; } - - ClassNode cls = root.resolveClass(type); - if (cls == null) { - return type; - } - ClassInfo clsInfo = cls.getClassInfo(); - if (!clsInfo.hasAlias()) { - return type; + if (type.isArray()) { + ArgType rootType = type.getArrayRootElement(); + ArgType aliasType = tryToResolveClassAlias(root, rootType); + if (aliasType == rootType) { + return type; + } + return ArgType.array(aliasType, type.getArrayDimension()); } - String aliasFullName = clsInfo.getAliasFullName(); - if (type.isGeneric()) { - if (type instanceof GenericObject) { - return new GenericObject(aliasFullName, type.getGenericTypes()); + if (type.isObject()) { + ArgType wildcardType = type.getWildcardType(); + if (wildcardType != null) { + return new WildcardType(tryToResolveClassAlias(root, wildcardType), type.getWildcardBound()); } - if (type instanceof WildcardType) { - return new WildcardType(ArgType.object(aliasFullName), type.getWildcardBound()); + ClassInfo clsInfo = ClassInfo.fromName(root, type.getObject()); + ArgType baseType = clsInfo.hasAlias() ? ArgType.object(clsInfo.getAliasFullName()) : type; + if (!type.isGeneric()) { + return baseType; + } + List genericTypes = type.getGenericTypes(); + if (genericTypes != null) { + return new GenericObject(baseType.getObject(), tryToResolveClassAlias(root, genericTypes)); } } - return ArgType.object(aliasFullName); + return type; + } + + public static List tryToResolveClassAlias(RootNode root, List types) { + return ListUtils.map(types, t -> tryToResolveClassAlias(root, t)); } @Override diff --git a/jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java b/jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java index f0e646a8331..f974e5e74f9 100644 --- a/jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java +++ b/jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java @@ -90,7 +90,7 @@ public int getPos() { } public String getTooltip() { - return null; + return makeLongStringHtml(); } private static final Comparator COMPARATOR = Comparator diff --git a/jadx-gui/src/main/java/jadx/gui/ui/codearea/MouseHoverHighlighter.java b/jadx-gui/src/main/java/jadx/gui/ui/codearea/MouseHoverHighlighter.java index e3d51282311..a18571bb5f7 100644 --- a/jadx-gui/src/main/java/jadx/gui/ui/codearea/MouseHoverHighlighter.java +++ b/jadx-gui/src/main/java/jadx/gui/ui/codearea/MouseHoverHighlighter.java @@ -83,6 +83,6 @@ private void updateToolTip(JavaNode node) { } JNodeCache nodeCache = codeArea.getMainWindow().getCacheObject().getNodeCache(); JNode jNode = nodeCache.makeFrom(node); - codeArea.setToolTipText(jNode.makeLongString()); + codeArea.setToolTipText(jNode.getTooltip()); } }