fix(gui): fix caret positions of search/usage/goto decl, add search to popup menu (#1093) (PR #1094)

* fix caret positions of search/usage/goto decl to matched place & add menu items for search

* Remove static field for main window

Co-authored-by: tobias <tobias.hotmail.com>
This commit is contained in:
LBJ-the-GOAT
2021-01-25 19:49:21 +08:00
committed by GitHub
parent 9744547fab
commit ffb2956d90
23 changed files with 228 additions and 46 deletions
@@ -5,6 +5,7 @@ public final class CodePosition {
private final JavaNode node;
private final int line;
private final int offset;
private int usagePosition = -1;
public CodePosition(JavaNode node, int line, int offset) {
this.node = node;
@@ -18,6 +19,15 @@ public final class CodePosition {
this.offset = offset;
}
public int getUsagePosition() {
return usagePosition;
}
public CodePosition setUsagePosition(int usagePosition) {
this.usagePosition = usagePosition;
return this;
}
public JavaNode getNode() {
return node;
}
@@ -120,8 +120,16 @@ public class CodeWriter {
CodeWriter add(CodeWriter code) {
line--;
for (Map.Entry<CodePosition, Object> entry : code.annotations.entrySet()) {
Object val = entry.getValue();
if (val instanceof DefinitionWrapper) {
LineAttrNode node = ((DefinitionWrapper) val).getNode();
node.setDefPosition(node.getDefPosition() + this.buf.length());
}
CodePosition pos = entry.getKey();
attachAnnotation(entry.getValue(), new CodePosition(line + pos.getLine(), pos.getOffset()));
int usagePos = pos.getUsagePosition() + bufLength();
attachAnnotation(val,
new CodePosition(line + pos.getLine(), pos.getOffset())
.setUsagePosition(usagePos));
}
for (Map.Entry<Integer, Integer> entry : code.lineMap.entrySet()) {
attachSourceLine(line + entry.getKey(), entry.getValue());
@@ -211,12 +219,14 @@ public class CodeWriter {
}
public void attachDefinition(LineAttrNode obj) {
obj.setDefPosition(buf.length());
attachAnnotation(obj);
attachAnnotation(new DefinitionWrapper(obj), new CodePosition(line, offset));
}
public void attachAnnotation(Object obj) {
attachAnnotation(obj, new CodePosition(line, offset + 1));
attachAnnotation(obj,
new CodePosition(line, offset + 1).setUsagePosition(bufLength()));
}
public void attachLineAnnotation(Object obj) {
@@ -8,6 +8,17 @@ public abstract class LineAttrNode extends AttrNode {
private int decompiledLine;
// the position exactly where a node declared at in decompiled java code.
private int defPosition;
public int getDefPosition() {
return this.defPosition;
}
public void setDefPosition(int defPosition) {
this.defPosition = defPosition;
}
public int getSourceLine() {
return sourceLine;
}