Skip to content

Commit

Permalink
fix(gui): use alias for types in tooltips (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed May 20, 2022
1 parent 7b1c7b9 commit 21e94d8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -874,28 +874,37 @@ public <R> R visitTypes(Function<ArgType, R> 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<ArgType> genericTypes = type.getGenericTypes();
if (genericTypes != null) {
return new GenericObject(baseType.getObject(), tryToResolveClassAlias(root, genericTypes));
}
}
return ArgType.object(aliasFullName);
return type;
}

public static List<ArgType> tryToResolveClassAlias(RootNode root, List<ArgType> types) {
return ListUtils.map(types, t -> tryToResolveClassAlias(root, t));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public int getPos() {
}

public String getTooltip() {
return null;
return makeLongStringHtml();
}

private static final Comparator<JNode> COMPARATOR = Comparator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 21e94d8

Please sign in to comment.