mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 07:50:47 +00:00
Goto declaration fixes
JSyntaxPane updated JFlex for unicode ranges Goto this declarations
This commit is contained in:
@@ -49,8 +49,7 @@ public class TextPanel extends JPanel implements ActionListener {
|
||||
|
||||
public TextPanel(MainPanel mainPanel) {
|
||||
super(new BorderLayout());
|
||||
|
||||
DefaultSyntaxKit.initKit();
|
||||
|
||||
|
||||
this.mainPanel = mainPanel;
|
||||
textSearchPanel = new SearchPanel<>(new FlowLayout(), mainPanel);
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.localregs.GetLocal0Ins;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ReturnVoidIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushScopeIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.parser.script.Reference;
|
||||
import com.jpexs.decompiler.flash.abc.types.ABCException;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodBody;
|
||||
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
|
||||
@@ -37,6 +38,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.Traits;
|
||||
import com.jpexs.decompiler.flash.abc.usages.MultinameUsage;
|
||||
import com.jpexs.decompiler.flash.abc.usages.TraitMultinameUsage;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.gui.AppStrings;
|
||||
import com.jpexs.decompiler.flash.gui.HeaderLabel;
|
||||
@@ -112,7 +114,9 @@ import javax.swing.table.TableModel;
|
||||
import javax.swing.text.Highlighter;
|
||||
import javax.swing.tree.TreePath;
|
||||
import jsyntaxpane.DefaultSyntaxKit;
|
||||
import jsyntaxpane.SyntaxDocument;
|
||||
import jsyntaxpane.Token;
|
||||
import jsyntaxpane.TokenType;
|
||||
|
||||
public class ABCPanel extends JPanel implements ItemListener, ActionListener, SearchListener<ABCPanelSearchResult>, Freed {
|
||||
|
||||
@@ -356,9 +360,10 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
|
||||
Helper.emptyObject(this);
|
||||
}
|
||||
|
||||
public ABCPanel(MainPanel mainPanel) {
|
||||
DefaultSyntaxKit.initKit();
|
||||
public ABCPanel(MainPanel mainPanel) {
|
||||
|
||||
DefaultSyntaxKit.initKit();
|
||||
|
||||
this.mainPanel = mainPanel;
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
@@ -368,12 +373,12 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
|
||||
|
||||
@Override
|
||||
public boolean isLink(Token token) {
|
||||
return hasDeclaration(token.start);
|
||||
return hasDeclaration(token.length==1?token.start:token.start+1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLink(Token token) {
|
||||
gotoDeclaration(token.start);
|
||||
gotoDeclaration(token.length==1?token.start:token.start+1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -538,6 +543,22 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
|
||||
}
|
||||
|
||||
private boolean hasDeclaration(int pos) {
|
||||
|
||||
SyntaxDocument sd = (SyntaxDocument)decompiledTextArea.getDocument();
|
||||
Token t = sd.getTokenAt(pos);
|
||||
if(t==null || (t.type != TokenType.IDENTIFIER && t.type!=TokenType.KEYWORD && t.type!=TokenType.REGEX)){
|
||||
return false;
|
||||
}
|
||||
Reference<Integer> abcIndex=new Reference<>(0);
|
||||
Reference<Integer> classIndex=new Reference<>(0);
|
||||
Reference<Integer> traitIndex=new Reference<>(0);
|
||||
Reference<Integer> multinameIndexRef=new Reference<>(0);
|
||||
Reference<Boolean> classTrait=new Reference<>(false);
|
||||
|
||||
|
||||
if(decompiledTextArea.getPropertyTypeAtPos(pos, abcIndex, classIndex, traitIndex, classTrait,multinameIndexRef)){
|
||||
return true;
|
||||
}
|
||||
int multinameIndex = decompiledTextArea.getMultinameAtPos(pos);
|
||||
if (multinameIndex > -1) {
|
||||
if(multinameIndex == 0){
|
||||
@@ -566,10 +587,22 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
|
||||
}
|
||||
}
|
||||
|
||||
return decompiledTextArea.getLocalDeclarationOfPos(pos) != -1;
|
||||
return decompiledTextArea.getLocalDeclarationOfPos(pos,new Reference<>("")) != -1;
|
||||
}
|
||||
|
||||
private void gotoDeclaration(int pos) {
|
||||
Reference<Integer> abcIndex=new Reference<>(0);
|
||||
Reference<Integer> classIndex=new Reference<>(0);
|
||||
Reference<Integer> traitIndex=new Reference<>(0);
|
||||
Reference<Boolean> classTrait=new Reference<>(false);
|
||||
Reference<Integer> multinameIndexRef=new Reference<>(0);
|
||||
|
||||
|
||||
if(decompiledTextArea.getPropertyTypeAtPos(pos, abcIndex, classIndex, traitIndex, classTrait,multinameIndexRef)){
|
||||
UsageFrame.gotoUsage(ABCPanel.this, new TraitMultinameUsage(swf.abcList, swf.abcList.get(abcIndex.getVal()).getABC(), multinameIndexRef.getVal(),classIndex.getVal(), traitIndex.getVal(), classTrait.getVal(), null, -1) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
int multinameIndex = decompiledTextArea.getMultinameAtPos(pos);
|
||||
if (multinameIndex > -1) {
|
||||
List<MultinameUsage> usages = abc.findMultinameDefinition(swf.abcList, multinameIndex);
|
||||
@@ -600,7 +633,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
|
||||
}
|
||||
}
|
||||
|
||||
int dpos = decompiledTextArea.getLocalDeclarationOfPos(pos);
|
||||
int dpos = decompiledTextArea.getLocalDeclarationOfPos(pos,new Reference<>(""));
|
||||
if (dpos > -1) {
|
||||
decompiledTextArea.setCaretPosition(dpos);
|
||||
}
|
||||
@@ -825,11 +858,9 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se
|
||||
if (oldSp != null) {
|
||||
hilightScript(swf, oldSp);
|
||||
}
|
||||
//decompiledTextArea.setClassIndex(-1);
|
||||
//navigator.setClassIndex(-1, oldIndex);
|
||||
setDecompiledEditMode(false);
|
||||
View.showMessageDialog(this, AppStrings.translate("message.action.saved"));
|
||||
//reload();
|
||||
reload();
|
||||
View.showMessageDialog(this, AppStrings.translate("message.action.saved"));
|
||||
} catch (AVM2ParseException ex) {
|
||||
abc.script_info.get(oldIndex).delete(abc, false);
|
||||
decompiledTextArea.gotoLine((int) ex.line);
|
||||
|
||||
@@ -23,6 +23,9 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.construction.ConstructSuperIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallSuperIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallSuperVoidIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.parser.script.Reference;
|
||||
import com.jpexs.decompiler.flash.abc.types.ClassInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.InstanceInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.Multiname;
|
||||
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
|
||||
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
|
||||
@@ -47,6 +50,9 @@ import java.util.TimerTask;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.CaretEvent;
|
||||
import javax.swing.event.CaretListener;
|
||||
import jsyntaxpane.SyntaxDocument;
|
||||
import jsyntaxpane.Token;
|
||||
import jsyntaxpane.TokenType;
|
||||
|
||||
public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretListener {
|
||||
|
||||
@@ -235,25 +241,34 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
|
||||
return getMultinameAtPos(getCaretPosition());
|
||||
}
|
||||
|
||||
public int getLocalDeclarationOfPos(int pos) {
|
||||
public int getLocalDeclarationOfPos(int pos,Reference<String> type) {
|
||||
Highlighting sh = Highlighting.search(specialHighlights, pos);
|
||||
Highlighting h = Highlighting.search(highlights, pos);
|
||||
|
||||
if (h == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
List<Highlighting> tms = Highlighting.searchAll(methodHighlights, pos, null, null, -1, -1);
|
||||
if (tms.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
for (Highlighting tm : tms) {
|
||||
|
||||
List<Highlighting> tm_tms = Highlighting.searchAll(methodHighlights, -1, "index", tm.getPropertyString("index"), -1, -1);
|
||||
if (h == null) {
|
||||
return -1;
|
||||
}
|
||||
List<Highlighting> tm_tms = Highlighting.searchAll(methodHighlights, -1, "index", tm.getPropertyString("index"), -1, -1);
|
||||
//is it already declaration?
|
||||
if ("true".equals(h.getPropertyString("declaration")) || (sh != null && "true".equals(sh.getPropertyString("declaration")))) {
|
||||
return -1; //no jump
|
||||
}
|
||||
|
||||
String lname=h.getPropertyString("localName");
|
||||
if("this".equals(lname)){
|
||||
Highlighting ch= Highlighting.search(classHighlights, pos);
|
||||
int cindex=(int)(long)ch.getPropertyLong("index");
|
||||
type.setVal(abc.instance_info.get(cindex).getName(abc.constants).getNameWithNamespace(abc.constants, true));
|
||||
return ch.startPos;
|
||||
}
|
||||
|
||||
Map<String, String> search = h.getProperties();
|
||||
search.remove("index");
|
||||
search.remove("subtype");
|
||||
@@ -269,6 +284,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
|
||||
rh = Highlighting.search(specialHighlights, search, tm1.startPos, tm1.startPos + tm1.len);
|
||||
}
|
||||
if (rh != null) {
|
||||
type.setVal(rh.getPropertyString("declaredType"));
|
||||
return rh.startPos;
|
||||
}
|
||||
}
|
||||
@@ -277,13 +293,101 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean getPropertyTypeAtPos(int pos, Reference<Integer> abcIndex,Reference<Integer> classIndex, Reference<Integer> traitIndex, Reference<Boolean> classTrait, Reference<Integer> multinameIndex){
|
||||
|
||||
int m = getMultinameAtPos(pos,true);
|
||||
if (m <= 0) {
|
||||
return false;
|
||||
}
|
||||
SyntaxDocument sd=(SyntaxDocument)getDocument();
|
||||
Token t = sd.getTokenAt(pos+1);
|
||||
Token lastToken = t;
|
||||
Token prev = null;
|
||||
while(t.type == TokenType.IDENTIFIER || t.type == TokenType.KEYWORD){
|
||||
prev = sd.getPrevToken(t);
|
||||
if(prev!=null){
|
||||
if(!".".equals(prev.getString(sd))){
|
||||
break;
|
||||
}
|
||||
t = sd.getPrevToken(prev);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(t.type != TokenType.IDENTIFIER && t.type != TokenType.KEYWORD){
|
||||
return false;
|
||||
}
|
||||
Reference<String> locTypeRef = new Reference<>("");
|
||||
getLocalDeclarationOfPos(t.start,locTypeRef);
|
||||
String currentType=locTypeRef.getVal();
|
||||
if(currentType.equals("*")){
|
||||
return false;
|
||||
}
|
||||
boolean found=false;
|
||||
t = sd.getNextToken(t);
|
||||
while(t!=lastToken && !currentType.equals("*")){
|
||||
t = sd.getNextToken(t);
|
||||
String ident=t.getString(sd);
|
||||
found = false;
|
||||
loopi:for(int i=0;i<abcList.size();i++){
|
||||
ABC a = abcList.get(i).getABC();
|
||||
int cindex=a.findClassByName(currentType);
|
||||
if(cindex>-1){
|
||||
InstanceInfo ii = a.instance_info.get(cindex);
|
||||
for(int j=0;j<ii.instance_traits.traits.size();j++){
|
||||
Trait tr = ii.instance_traits.traits.get(j);
|
||||
if(ident.equals(tr.getName(a).getName(a.constants, new ArrayList<String>(), true))){
|
||||
classIndex.setVal(cindex);
|
||||
abcIndex.setVal(i);
|
||||
traitIndex.setVal(j);
|
||||
classTrait.setVal(false);
|
||||
multinameIndex.setVal(tr.name_index);
|
||||
currentType = ii.getName(a.constants).getNameWithNamespace(a.constants, true);
|
||||
found = true;
|
||||
break loopi;
|
||||
}
|
||||
}
|
||||
|
||||
ClassInfo ci = a.class_info.get(cindex);
|
||||
for(int j=0;j<ci.static_traits.traits.size();j++){
|
||||
Trait tr = ci.static_traits.traits.get(j);
|
||||
if(ident.equals(tr.getName(a).getName(a.constants, new ArrayList<String>(), true))){
|
||||
classIndex.setVal(cindex);
|
||||
abcIndex.setVal(i);
|
||||
traitIndex.setVal(j);
|
||||
classTrait.setVal(true);
|
||||
multinameIndex.setVal(tr.name_index);
|
||||
currentType = ii.getName(a.constants).getNameWithNamespace(a.constants, true);
|
||||
found = true;
|
||||
break loopi;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!found){
|
||||
return false;
|
||||
}
|
||||
|
||||
t = sd.getNextToken(t);
|
||||
if(!".".equals(t.getString(sd))){
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getMultinameAtPos(int pos) {
|
||||
return getMultinameAtPos(pos, false);
|
||||
}
|
||||
|
||||
public int getMultinameAtPos(int pos, boolean codeOnly) {
|
||||
Highlighting tm = Highlighting.search(methodHighlights, pos);
|
||||
Trait currentTrait = null;
|
||||
int currentMethod = -1;
|
||||
if (tm != null) {
|
||||
|
||||
int mi = (int) (long) tm.getPropertyLong("index");
|
||||
currentMethod = mi;
|
||||
int bi = abc.findBodyIndex(mi);
|
||||
Highlighting h = Highlighting.search(highlights, pos);
|
||||
if (h != null) {
|
||||
@@ -304,7 +408,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
|
||||
lastIns = ins;
|
||||
}
|
||||
if (selIns != null) {
|
||||
if ((selIns.definition instanceof ConstructSuperIns) || (selIns.definition instanceof CallSuperIns)|| (selIns.definition instanceof CallSuperVoidIns)) {
|
||||
if (!codeOnly && ((selIns.definition instanceof ConstructSuperIns) || (selIns.definition instanceof CallSuperIns)|| (selIns.definition instanceof CallSuperVoidIns))) {
|
||||
Highlighting tc = Highlighting.search(classHighlights, pos);
|
||||
if(tc!=null){
|
||||
int cindex = (int)(long)tc.getPropertyLong("index");
|
||||
@@ -321,14 +425,23 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentTrait = getCurrentTrait();
|
||||
if (currentTrait instanceof TraitMethodGetterSetter) {
|
||||
currentMethod = ((TraitMethodGetterSetter) currentTrait).method_info;
|
||||
}
|
||||
if (currentMethodHighlight != null) {
|
||||
currentMethod = (int) (long) currentMethodHighlight.getPropertyLong("index");
|
||||
|
||||
}
|
||||
if(codeOnly){
|
||||
return -1;
|
||||
}
|
||||
|
||||
Highlighting ch = Highlighting.search(classHighlights, pos);
|
||||
if(ch!=null){
|
||||
Highlighting th = Highlighting.search(traitHighlights, pos);
|
||||
if (th != null) {
|
||||
currentTrait = abc.findTraitByTraitId((int) (long) ch.getPropertyLong("index"), (int) (long) th.getPropertyLong("index"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (currentTrait instanceof TraitMethodGetterSetter) {
|
||||
currentMethod = ((TraitMethodGetterSetter) currentTrait).method_info;
|
||||
}
|
||||
Highlighting sh = Highlighting.search(specialHighlights, pos);
|
||||
if (sh != null) {
|
||||
|
||||
@@ -177,7 +177,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
|
||||
if (d instanceof SyntaxDocument) {
|
||||
SyntaxDocument sd = (SyntaxDocument) d;
|
||||
int pos = viewToModel(lastPos);
|
||||
if (pos < 0) {
|
||||
if (pos <= 0) {
|
||||
return;
|
||||
}
|
||||
Token t = sd.getTokenAt(pos);
|
||||
@@ -211,7 +211,6 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
|
||||
setCursor(Cursor.getDefaultCursor());
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,7 +221,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
|
||||
if (pos < 0) {
|
||||
return;
|
||||
}
|
||||
Token t = sd.getTokenAt(pos);
|
||||
Token t = sd.getTokenAt(pos + 1);
|
||||
if (t != null && linkHandler.isLink(t)) {
|
||||
linkHandler.handleLink(t);
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene
|
||||
|
||||
SyntaxDocument sDoc = ActionUtils.getSyntaxDocument(decompiledEditor);
|
||||
if (sDoc != null) {
|
||||
Token t = sDoc.getTokenAt(pos);
|
||||
Token t = sDoc.getTokenAt(pos+1);
|
||||
String ident = null;
|
||||
//It should be identifier or obfuscated identifier
|
||||
if (t != null && (t.type == TokenType.IDENTIFIER || t.type == TokenType.REGEX)) {
|
||||
|
||||
Reference in New Issue
Block a user