Skip to content

Commit

Permalink
fix(gui): save variable name to show in tooltip (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed May 22, 2022
1 parent 6448f0e commit 4cd4746
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions jadx-core/src/main/java/jadx/api/JavaVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jetbrains.annotations.ApiStatus;

import jadx.api.metadata.annotations.VarNode;
import jadx.core.dex.instructions.args.ArgType;

public class JavaVariable implements JavaNode {
private final JavaMethod mth;
Expand Down Expand Up @@ -43,6 +44,10 @@ public String getFullName() {
return varNode.getType() + " " + varNode.getName() + " (r" + varNode.getReg() + "v" + varNode.getSsa() + ")";
}

public ArgType getType() {
return ArgType.tryToResolveClassAlias(mth.getMethodNode().root(), varNode.getType());
}

@Override
public JavaClass getDeclaringClass() {
return mth.getDeclaringClass();
Expand Down
3 changes: 2 additions & 1 deletion jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ public void declareVar(ICodeWriter code, CodeVar codeVar) {
* Variable definition without type, only var name
*/
private void defVar(ICodeWriter code, CodeVar codeVar) {
String varName = mgen.getNameGen().assignArg(codeVar);
if (code.isMetadataSupported()) {
code.attachDefinition(VarNode.get(mth, codeVar));
}
code.add(mgen.getNameGen().assignArg(codeVar));
code.add(varName);
}

private String lit(LiteralArg arg) {
Expand Down
6 changes: 6 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/treemodel/JField.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public String makeLongStringHtml() {
return UiUtils.typeFormatHtml(field.getFullName(), field.getType());
}

@Override
public String getTooltip() {
String fullType = UiUtils.escapeHtml(field.getType().toString());
return UiUtils.wrapHtml(fullType + ' ' + UiUtils.escapeHtml(field.getName()));
}

@Override
public String makeDescString() {
return UiUtils.typeStr(field.getType()) + " " + field.getName();
Expand Down
13 changes: 13 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/treemodel/JVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import jadx.api.JavaNode;
import jadx.api.JavaVariable;
import jadx.gui.utils.UiUtils;

public class JVariable extends JNode {
private static final long serialVersionUID = -3002100457834453783L;
Expand Down Expand Up @@ -55,6 +56,18 @@ public String makeLongString() {
return var.getFullName();
}

@Override
public String makeLongStringHtml() {
return UiUtils.typeFormatHtml(var.getName(), var.getType());
}

@Override
public String getTooltip() {
String name = var.getName() + " (r" + var.getReg() + "v" + var.getSsa() + ")";
String fullType = UiUtils.escapeHtml(var.getType().toString());
return UiUtils.wrapHtml(fullType + ' ' + UiUtils.escapeHtml(name));
}

@Override
public boolean canRename() {
return true;
Expand Down
12 changes: 9 additions & 3 deletions jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,15 @@ public static String typeFormat(String name, ArgType type) {
}

public static String typeFormatHtml(String name, ArgType type) {
return "<html><body><nobr>" + escapeHtml(name)
+ "<span style='color:#888888;'> " + escapeHtml(typeStr(type)) + "</span>"
+ "</nobr></body></html>";
return wrapHtml(escapeHtml(name) + ' ' + fadeHtml(escapeHtml(typeStr(type))));
}

public static String fadeHtml(String htmlStr) {
return "<span style='color:#888888;'>" + htmlStr + "</span>"; // TODO: get color from theme
}

public static String wrapHtml(String htmlStr) {
return "<html><body><nobr>" + htmlStr + "</nobr></body></html>";
}

public static String escapeHtml(String str) {
Expand Down

0 comments on commit 4cd4746

Please sign in to comment.