AS1/2: Ctrl+click to declaration of variables, registers. Hilighting methods and classes

AS1/2: Debugger - Show registers
Fixed ctrl+click underline position
This commit is contained in:
Jindra Petřík
2015-12-05 10:53:43 +01:00
parent 8b7e754247
commit ec666b60e4
20 changed files with 321 additions and 64 deletions
@@ -358,12 +358,12 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<ABC
@Override
public boolean isLink(Token token) {
return hasDeclaration(token.length == 1 ? token.start : token.start + 1);
return hasDeclaration(token.start);
}
@Override
public void handleLink(Token token) {
gotoDeclaration(token.length == 1 ? token.start : token.start + 1);
gotoDeclaration(token.start);
}
@Override
@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.gui.action;
import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ClassPath;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.Reference;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionGraph;
import com.jpexs.decompiler.flash.action.ActionList;
@@ -49,9 +50,11 @@ import com.jpexs.decompiler.flash.gui.controls.JPersistentSplitPane;
import com.jpexs.decompiler.flash.gui.controls.NoneSelectedButtonGroup;
import com.jpexs.decompiler.flash.gui.editor.DebuggableEditorPane;
import com.jpexs.decompiler.flash.gui.editor.LineMarkedEditorPane;
import com.jpexs.decompiler.flash.gui.editor.LinkHandler;
import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel;
import com.jpexs.decompiler.flash.helpers.HighlightedText;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.graph.CompilationException;
@@ -87,6 +90,7 @@ import javax.swing.JToggleButton;
import javax.swing.SwingConstants;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.text.Highlighter;
import javax.swing.tree.TreePath;
import jsyntaxpane.SyntaxDocument;
import jsyntaxpane.Token;
@@ -132,6 +136,9 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
public JLabel decLabel = new HeaderLabel(AppStrings.translate("panel.decompiled"));
public List<Highlighting> decompiledHilights = new ArrayList<>();
public List<Highlighting> specialHighlights = new ArrayList<>();
public List<Highlighting> classHighlights = new ArrayList<>();
public List<Highlighting> methodHighlights = new ArrayList<>();
public List<Highlighting> disassembledHilights = new ArrayList<>();
@@ -467,6 +474,9 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
CachedScript sc = SWF.getCached(asm, actions);
decompiledHilights = sc.hilights;
methodHighlights = sc.methodHilights;
classHighlights = sc.classHilights;
specialHighlights = sc.specialHilights;
lastDecompiled = sc.text;
lastASM = asm;
setDecompiledText(lastASM.getScriptName(), lastDecompiled);
@@ -505,12 +515,92 @@ public class ActionPanel extends JPanel implements SearchListener<ActionSearchRe
public void hilightOffset(long offset) {
}
public int getLocalDeclarationOfPos(int pos) {
Highlighting sh = Highlighting.searchPos(specialHighlights, pos);
Highlighting h = Highlighting.searchPos(decompiledHilights, pos);
if (h == null) {
return -1;
}
List<Highlighting> tms = Highlighting.searchAllPos(methodHighlights, pos);
if (tms.isEmpty()) {
return -1;
}
for (Highlighting tm : tms) {
List<Highlighting> tm_tms = Highlighting.searchAllLocalNames(methodHighlights, tm.getProperties().localName);
//is it already declaration?
if (h.getProperties().declaration || (sh != null && sh.getProperties().declaration)) {
return -1; //no jump
}
String lname = h.getProperties().localName;
if ("this".equals(lname)) {
Highlighting ch = Highlighting.searchPos(classHighlights, pos);
// int cindex = (int) ch.getProperties().index;
return ch.startPos;
}
HighlightData hData = h.getProperties();
HighlightData search = new HighlightData();
search.declaration = hData.declaration;
//search.declaredType = hData.declaredType;
search.localName = hData.localName;
//search.specialValue = hData.specialValue;
if (search.isEmpty()) {
return -1;
}
search.declaration = true;
for (Highlighting tm1 : tm_tms) {
Highlighting rh = Highlighting.search(decompiledHilights, search, tm1.startPos, tm1.startPos + tm1.len);
if (rh != null) {
return rh.startPos;
}
}
}
return -1;
}
public ActionPanel(MainPanel mainPanel) {
this.mainPanel = mainPanel;
editor = new LineMarkedEditorPane();
editor.setEditable(false);
decompiledEditor = new DebuggableEditorPane();
decompiledEditor.setEditable(false);
decompiledEditor.setLinkHandler(new LinkHandler() {
@Override
public boolean isLink(Token token) {
int pos = token.start;
Highlighting h = Highlighting.searchPos(decompiledHilights, pos);
if (h != null) {
if (h.getProperties().localName != null && !h.getProperties().declaration) {
return getLocalDeclarationOfPos(pos) != -1;
}
}
return false;
}
@Override
public void handleLink(Token token) {
int pos = token.start;
int tpos = getLocalDeclarationOfPos(pos);
if (tpos > -1) {
//System.err.println("goto " + tpos);
decompiledEditor.setCaretPosition(tpos);
} else {
//System.err.println("cannot handle");
}
}
@Override
public Highlighter.HighlightPainter linkPainter() {
return decompiledEditor.linkPainter();
}
});
searchPanel = new SearchPanel<>(new FlowLayout(), this);
@@ -39,6 +39,8 @@ import java.util.Map;
import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.plaf.TextUI;
@@ -291,6 +293,37 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
}
public Token tokenAtPos(Point lastPos) {
Document d = getDocument();
if (d instanceof SyntaxDocument) {
SyntaxDocument sd = (SyntaxDocument) d;
//correction of token last character
int pos = viewToModel(lastPos);
Rectangle r;
try {
r = modelToView(pos);
if (lastPos.x < r.x) {
pos--;
}
} catch (BadLocationException ex) {
//ignore
}
Token t = sd.getTokenAt(pos);
//Correction of token of length 1 character
if (pos > 0 && pos < d.getLength() - 1 && t != null && t.length == 1) {
Token tprev = sd.getTokenAt(pos - 1);
if (tprev == t) {
t = sd.getTokenAt(pos + 1);
}
}
return t;
}
return null;
}
private class LinkAdapter extends MouseAdapter implements KeyListener {
private Point lastPos = new Point(0, 0);
@@ -320,38 +353,30 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
private void update() {
if (ctrlDown) {
Document d = getDocument();
if (d instanceof SyntaxDocument) {
SyntaxDocument sd = (SyntaxDocument) d;
int pos = viewToModel(lastPos);
if (pos <= 0) {
return;
}
Token t = sd.getTokenAt(pos);
if (t != lastUnderlined) {
if (t == null || lastUnderlined == null || !t.equals(lastUnderlined)) {
MyMarkers.removeMarkers(LineMarkedEditorPane.this, underLinePainter);
Token t = tokenAtPos(lastPos);
if (t != null && linkHandler.isLink(t)) {
lastUnderlined = t;
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
if (t != lastUnderlined) {
if (t == null || lastUnderlined == null || !t.equals(lastUnderlined)) {
MyMarkers.removeMarkers(LineMarkedEditorPane.this, underLinePainter);
if (t != null && linkHandler.isLink(t)) {
lastUnderlined = t;
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
} else {
lastUnderlined = null;
}
} else {
lastUnderlined = null;
}
}
if (lastUnderlined != null) {
MyMarkers.markToken(LineMarkedEditorPane.this, lastUnderlined, underLinePainter);
} else {
setCursor(Cursor.getDefaultCursor());
lastUnderlined = null;
}
repaint();
}
if (lastUnderlined != null) {
MyMarkers.markToken(LineMarkedEditorPane.this, lastUnderlined, underLinePainter);
} else {
setCursor(Cursor.getDefaultCursor());
}
repaint();
} else {
lastUnderlined = null;
MyMarkers.removeMarkers(LineMarkedEditorPane.this, underLinePainter);
@@ -363,12 +388,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
@Override
public void mouseClicked(MouseEvent e) {
if (ctrlDown) {
SyntaxDocument sd = (SyntaxDocument) getDocument();
int pos = viewToModel(e.getPoint());
if (pos < 0) {
return;
}
Token t = sd.getTokenAt(pos + 1);
Token t = tokenAtPos(lastPos);
if (t != null && linkHandler.isLink(t)) {
linkHandler.handleLink(t);
}