|
| 1 | +package jadx.gui.ui.action; |
| 2 | + |
| 3 | +import org.slf4j.Logger; |
| 4 | +import org.slf4j.LoggerFactory; |
| 5 | + |
| 6 | +import jadx.api.JavaClass; |
| 7 | +import jadx.api.JavaField; |
| 8 | +import jadx.api.JavaMethod; |
| 9 | +import jadx.api.JavaNode; |
| 10 | +import jadx.gui.treemodel.JClass; |
| 11 | +import jadx.gui.treemodel.JField; |
| 12 | +import jadx.gui.treemodel.JMethod; |
| 13 | +import jadx.gui.treemodel.JNode; |
| 14 | +import jadx.gui.ui.codearea.CodeArea; |
| 15 | +import jadx.gui.utils.UiUtils; |
| 16 | + |
| 17 | +public final class CopyReferenceAction extends JNodeAction { |
| 18 | + private static final Logger LOG = LoggerFactory.getLogger(CopyReferenceAction.class); |
| 19 | + private static final long serialVersionUID = -8816072267744391424L; |
| 20 | + |
| 21 | + public CopyReferenceAction(CodeArea codeArea) { |
| 22 | + super(ActionModel.COPY_REFERENCE, codeArea); |
| 23 | + } |
| 24 | + |
| 25 | + @Override |
| 26 | + public void runAction(JNode node) { |
| 27 | + JavaNode javaNode = node.getJavaNode(); |
| 28 | + String ref; |
| 29 | + if (javaNode instanceof JavaClass) { |
| 30 | + ref = javaNode.getFullName(); |
| 31 | + } else if (javaNode instanceof JavaMethod) { |
| 32 | + ref = ((JavaMethod) javaNode).getDeclaringClass().getFullName() + '.' + javaNode.getName(); |
| 33 | + } else if (javaNode instanceof JavaField) { |
| 34 | + ref = ((JavaField) javaNode).getDeclaringClass().getFullName() + '.' + javaNode.getName(); |
| 35 | + } else { |
| 36 | + LOG.warn("Copy reference not supported for node type: {}", node.getClass()); |
| 37 | + return; |
| 38 | + } |
| 39 | + UiUtils.copyToClipboard(ref); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public boolean isActionEnabled(JNode node) { |
| 44 | + return node instanceof JMethod || node instanceof JClass || node instanceof JField; |
| 45 | + } |
| 46 | +} |
0 commit comments