Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to search for full method/field signature #880

Merged
merged 3 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/treemodel/JField.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jadx.gui.treemodel;

import javax.swing.*;
import javax.swing.Icon;
import javax.swing.ImageIcon;

import jadx.api.JavaField;
import jadx.api.JavaNode;
Expand Down Expand Up @@ -65,11 +66,21 @@ public String makeString() {
return UiUtils.typeFormat(field.getName(), field.getType());
}

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

@Override
public String makeLongString() {
return UiUtils.typeFormat(field.getFullName(), field.getType());
}

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

@Override
public int hashCode() {
return field.hashCode();
Expand Down
14 changes: 13 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/treemodel/JMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import java.util.Iterator;

import javax.swing.*;
import javax.swing.Icon;
import javax.swing.ImageIcon;

import jadx.api.JavaMethod;
import jadx.api.JavaNode;
Expand Down Expand Up @@ -93,12 +94,23 @@ public String makeString() {
return UiUtils.typeFormat(makeBaseString(), getReturnType());
}

@Override
public String makeStringHtml() {
return UiUtils.typeFormatHtml(makeBaseString(), getReturnType());
}

@Override
public String makeLongString() {
String name = mth.getDeclaringClass().getFullName() + '.' + makeBaseString();
return UiUtils.typeFormat(name, getReturnType());
}

@Override
public String makeLongStringHtml() {
String name = mth.getDeclaringClass().getFullName() + '.' + makeBaseString();
return UiUtils.typeFormatHtml(name, getReturnType());
}

@Override
public int hashCode() {
return mth.hashCode();
Expand Down
10 changes: 9 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/treemodel/JNode.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jadx.gui.treemodel;

import javax.swing.*;
import javax.swing.Icon;
import javax.swing.tree.DefaultMutableTreeNode;

import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
Expand Down Expand Up @@ -77,6 +77,10 @@ public String getName() {

public abstract String makeString();

public String makeStringHtml() {
return makeString();
}

public String makeDescString() {
return null;
}
Expand All @@ -89,6 +93,10 @@ public String makeLongString() {
return makeString();
}

public String makeLongStringHtml() {
return makeString();
}

@Override
public String toString() {
return makeString();
Expand Down
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/CommonSearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ private void updateSelection(JTable table, Component comp, boolean isSelected) {

private Component makeCell(JNode node, int column) {
if (column == 0) {
JLabel label = new JLabel(node.makeLongString() + " ", node.getIcon(), SwingConstants.LEFT);
JLabel label = new JLabel(node.makeLongStringHtml() + " ", node.getIcon(), SwingConstants.LEFT);
label.setFont(font);
label.setOpaque(true);
label.setToolTipText(label.getText());
Expand Down
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/RenameDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private JPanel initButtonsPanel() {

private void initUI() {
JLabel lbl = new JLabel(NLS.str("popup.rename"));
JLabel nodeLabel = new JLabel(this.node.makeLongString(), this.node.getIcon(), SwingConstants.LEFT);
JLabel nodeLabel = new JLabel(this.node.makeLongStringHtml(), this.node.getIcon(), SwingConstants.LEFT);
lbl.setLabelFor(nodeLabel);

renameField = new JTextField(40);
Expand Down
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/TabComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void init() {
panel.setOpaque(false);

JNode node = contentPanel.getNode();
label = new JLabel(node.makeLongString());
label = new JLabel(node.makeLongStringHtml());
label.setFont(getLabelFont());
String toolTip = contentPanel.getTabTooltip();
if (toolTip != null) {
Expand Down
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/UsageDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected synchronized void performSearch() {

private void initUI() {
JLabel lbl = new JLabel(NLS.str("usage_dialog.label"));
JLabel nodeLabel = new JLabel(this.node.makeLongString(), this.node.getIcon(), SwingConstants.LEFT);
JLabel nodeLabel = new JLabel(this.node.makeLongStringHtml(), this.node.getIcon(), SwingConstants.LEFT);
lbl.setLabelFor(nodeLabel);

JPanel searchPane = new JPanel();
Expand Down
4 changes: 4 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/utils/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public static void addKeyBinding(JComponent comp, KeyStroke key, String id, Acti
}

public static String typeFormat(String name, ArgType type) {
return name + typeStr(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>";
Expand Down
18 changes: 10 additions & 8 deletions jadx-gui/src/main/java/jadx/gui/utils/search/TextSearchIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,29 @@ public class TextSearchIndex {
private final JNodeCache nodeCache;

private SearchIndex<JNode> clsNamesIndex;
private SearchIndex<JNode> mthNamesIndex;
private SearchIndex<JNode> fldNamesIndex;
private SearchIndex<JNode> mthSignaturesIndex;
private SearchIndex<JNode> fldSignaturesIndex;
private SearchIndex<CodeNode> codeIndex;

private List<JavaClass> skippedClasses = new ArrayList<>();

public TextSearchIndex(JNodeCache nodeCache) {
this.nodeCache = nodeCache;
this.clsNamesIndex = new SimpleIndex<>();
this.mthNamesIndex = new SimpleIndex<>();
this.fldNamesIndex = new SimpleIndex<>();
this.mthSignaturesIndex = new SimpleIndex<>();
this.fldSignaturesIndex = new SimpleIndex<>();
this.codeIndex = new CodeIndex<>();
}

public void indexNames(JavaClass cls) {
clsNamesIndex.put(cls.getFullName(), nodeCache.makeFrom(cls));
for (JavaMethod mth : cls.getMethods()) {
mthNamesIndex.put(mth.getName(), nodeCache.makeFrom(mth));
JNode mthNode = nodeCache.makeFrom(mth);
mthSignaturesIndex.put(mthNode.makeLongString(), mthNode);
}
for (JavaField fld : cls.getFields()) {
fldNamesIndex.put(fld.getName(), nodeCache.makeFrom(fld));
JNode fldNode = nodeCache.makeFrom(fld);
fldSignaturesIndex.put(fldNode.makeLongString(), fldNode);
}
for (JavaClass innerCls : cls.getInnerClasses()) {
indexNames(innerCls);
Expand Down Expand Up @@ -97,10 +99,10 @@ public Flowable<JNode> buildSearch(String text, Set<SearchDialog.SearchOptions>
result = Flowable.concat(result, clsNamesIndex.search(text, ignoreCase));
}
if (options.contains(METHOD)) {
result = Flowable.concat(result, mthNamesIndex.search(text, ignoreCase));
result = Flowable.concat(result, mthSignaturesIndex.search(text, ignoreCase));
}
if (options.contains(FIELD)) {
result = Flowable.concat(result, fldNamesIndex.search(text, ignoreCase));
result = Flowable.concat(result, fldSignaturesIndex.search(text, ignoreCase));
}
if (options.contains(CODE)) {
if (codeIndex.size() > 0) {
Expand Down