fix(gui): yet another fix for broken find usage action
This commit is contained in:
@@ -15,6 +15,8 @@ import jadx.api.JavaNode;
|
||||
import jadx.gui.treemodel.JClass;
|
||||
import jadx.gui.treemodel.JNode;
|
||||
import jadx.gui.ui.ContentPanel;
|
||||
import jadx.gui.ui.MainWindow;
|
||||
import jadx.gui.utils.JNodeCache;
|
||||
import jadx.gui.utils.JumpPosition;
|
||||
|
||||
/**
|
||||
@@ -109,14 +111,31 @@ public final class CodeArea extends AbstractCodeArea {
|
||||
if (pos == null) {
|
||||
return null;
|
||||
}
|
||||
JNode jNode = contentPanel.getTabbedPane().getMainWindow().getCacheObject().getNodeCache().makeFrom(foundNode);
|
||||
JNode jNode = convertJavaNode(foundNode);
|
||||
return new JumpPosition(jNode.getRootClass(), pos.getLine());
|
||||
}
|
||||
|
||||
private JNode convertJavaNode(JavaNode javaNode) {
|
||||
JNodeCache nodeCache = getMainWindow().getCacheObject().getNodeCache();
|
||||
return nodeCache.makeFrom(javaNode);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JNode getJNodeAtOffset(int offset) {
|
||||
JavaNode javaNode = getJavaNodeAtOffset(offset);
|
||||
if (javaNode != null) {
|
||||
return convertJavaNode(javaNode);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search referenced java node by offset in {@code jCls} code
|
||||
*/
|
||||
public JavaNode getJavaNodeAtOffset(int offset) {
|
||||
if (offset == -1) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// TODO: add direct mapping for code offset to CodeWriter (instead of line and line offset pair)
|
||||
int line = this.getLineOfOffset(offset);
|
||||
@@ -128,7 +147,11 @@ public final class CodeArea extends AbstractCodeArea {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MainWindow getMainWindow() {
|
||||
return contentPanel.getTabbedPane().getMainWindow();
|
||||
}
|
||||
|
||||
private JadxDecompiler getDecompiler() {
|
||||
return contentPanel.getTabbedPane().getMainWindow().getWrapper().getDecompiler();
|
||||
return getMainWindow().getWrapper().getDecompiler();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ package jadx.gui.ui.codearea;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import jadx.gui.ui.MainWindow;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import jadx.gui.treemodel.JNode;
|
||||
import jadx.gui.ui.UsageDialog;
|
||||
import jadx.gui.utils.NLS;
|
||||
|
||||
public final class FindUsageAction extends JNodeMenuAction {
|
||||
public final class FindUsageAction extends JNodeMenuAction<JNode> {
|
||||
private static final long serialVersionUID = 4692546569977976384L;
|
||||
|
||||
public FindUsageAction(CodeArea codeArea) {
|
||||
@@ -15,11 +17,16 @@ public final class FindUsageAction extends JNodeMenuAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (jumpPos == null) {
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
MainWindow mainWindow = codeArea.getContentPanel().getTabbedPane().getMainWindow();
|
||||
UsageDialog usageDialog = new UsageDialog(mainWindow, jumpPos.getNode());
|
||||
UsageDialog usageDialog = new UsageDialog(codeArea.getMainWindow(), node);
|
||||
usageDialog.setVisible(true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JNode getNodeByOffset(int offset) {
|
||||
return codeArea.getJNodeAtOffset(offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package jadx.gui.ui.codearea;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import jadx.gui.utils.JumpPosition;
|
||||
import jadx.gui.utils.NLS;
|
||||
|
||||
public final class GoToDeclarationAction extends JNodeMenuAction {
|
||||
public final class GoToDeclarationAction extends JNodeMenuAction<JumpPosition> {
|
||||
private static final long serialVersionUID = -1186470538894941301L;
|
||||
|
||||
public GoToDeclarationAction(CodeArea codeArea) {
|
||||
@@ -16,15 +16,14 @@ public final class GoToDeclarationAction extends JNodeMenuAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (jumpPos != null) {
|
||||
codeArea.getContentPanel().getTabbedPane().codeJump(jumpPos);
|
||||
if (node != null) {
|
||||
codeArea.getContentPanel().getTabbedPane().codeJump(node);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||
super.popupMenuWillBecomeVisible(e);
|
||||
|
||||
putValue(Action.SMALL_ICON, jumpPos == null ? null : jumpPos.getNode().getIcon());
|
||||
public JumpPosition getNodeByOffset(int offset) {
|
||||
return codeArea.getDefPosForNodeAtOffset(offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,11 @@ import javax.swing.event.PopupMenuListener;
|
||||
import org.fife.ui.rsyntaxtextarea.Token;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import jadx.gui.utils.JumpPosition;
|
||||
|
||||
public abstract class JNodeMenuAction extends AbstractAction implements PopupMenuListener {
|
||||
public abstract class JNodeMenuAction<T> extends AbstractAction implements PopupMenuListener {
|
||||
|
||||
protected final transient CodeArea codeArea;
|
||||
@Nullable
|
||||
protected transient JumpPosition jumpPos;
|
||||
protected transient T node;
|
||||
|
||||
public JNodeMenuAction(String name, CodeArea codeArea) {
|
||||
super(name);
|
||||
@@ -26,19 +24,22 @@ public abstract class JNodeMenuAction extends AbstractAction implements PopupMen
|
||||
@Override
|
||||
public abstract void actionPerformed(ActionEvent e);
|
||||
|
||||
@Nullable
|
||||
public abstract T getNodeByOffset(int offset);
|
||||
|
||||
@Override
|
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||
jumpPos = getJumpPos();
|
||||
setEnabled(jumpPos != null);
|
||||
node = getNode();
|
||||
setEnabled(node != null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JumpPosition getJumpPos() {
|
||||
private T getNode() {
|
||||
Point pos = codeArea.getMousePosition();
|
||||
if (pos != null) {
|
||||
Token token = codeArea.viewToToken(pos);
|
||||
int offset = codeArea.adjustOffsetForToken(token);
|
||||
return codeArea.getDefPosForNodeAtOffset(offset);
|
||||
return getNodeByOffset(offset);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user