mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 02:30:44 +00:00
AS3 Goto definition of static properties.
Link type enum
This commit is contained in:
@@ -66,6 +66,7 @@ import com.jpexs.decompiler.flash.gui.View;
|
||||
import com.jpexs.decompiler.flash.gui.ViewMessages;
|
||||
import com.jpexs.decompiler.flash.gui.controls.JPersistentSplitPane;
|
||||
import com.jpexs.decompiler.flash.gui.editor.LinkHandler;
|
||||
import com.jpexs.decompiler.flash.gui.editor.LinkType;
|
||||
import com.jpexs.decompiler.flash.gui.editor.VariableMarker;
|
||||
import com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTree;
|
||||
import com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTreeModel;
|
||||
@@ -905,7 +906,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<Scr
|
||||
|
||||
decompiledTextArea.setLinkHandler(new LinkHandler() {
|
||||
@Override
|
||||
public boolean isLink(Token token) {
|
||||
public LinkType isLink(Token token) {
|
||||
return hasDeclaration(token);
|
||||
}
|
||||
|
||||
@@ -1233,13 +1234,13 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<Scr
|
||||
cancelDecompiledButton.setEnabled(value);
|
||||
}
|
||||
|
||||
private boolean hasDeclaration(Token t) {
|
||||
private LinkType hasDeclaration(Token t) {
|
||||
if (decompiledTextArea == null) {
|
||||
return false; //?
|
||||
return LinkType.NO_LINK; //?
|
||||
}
|
||||
|
||||
if (t == null || (t.type != TokenType.IDENTIFIER && t.type != TokenType.KEYWORD && t.type != TokenType.REGEX)) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
int pos = t.start;
|
||||
Reference<Integer> abcIndex = new Reference<>(0);
|
||||
@@ -1249,21 +1250,22 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<Scr
|
||||
Reference<Boolean> classTrait = new Reference<>(false);
|
||||
Reference<ABC> usedAbcRef = new Reference<>(null);
|
||||
if (getSwf() == null) {
|
||||
return false;
|
||||
}
|
||||
if (decompiledTextArea.getPropertyTypeAtPos(getSwf().getAbcIndex(), pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef, usedAbcRef)) {
|
||||
return true;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
LinkType propLinkType = decompiledTextArea.getPropertyTypeAtPos(getSwf().getAbcIndex(), pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef, usedAbcRef, false);
|
||||
if (propLinkType != LinkType.NO_LINK) {
|
||||
return propLinkType;
|
||||
}
|
||||
ABC usedAbc = usedAbcRef.getVal();
|
||||
int multinameIndex = decompiledTextArea.getMultinameAtPos(pos, usedAbcRef);
|
||||
if (multinameIndex > -1) {
|
||||
if (multinameIndex == 0) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
|
||||
Multiname m = usedAbc.constants.getMultiname(multinameIndex);
|
||||
if (m == null) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
if (m.kind == Multiname.TYPENAME) { //Assuming it's a Vector with single parameter
|
||||
multinameIndex = m.params[0];
|
||||
@@ -1288,11 +1290,11 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<Scr
|
||||
|
||||
//more than one? display list
|
||||
if (!usages.isEmpty()) {
|
||||
return true;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
}
|
||||
|
||||
return decompiledTextArea.getLocalDeclarationOfPos(pos, new Reference<>(null)) != -1;
|
||||
return decompiledTextArea.getLocalDeclarationOfPos(pos, new Reference<>(null)) != -1 ? LinkType.LINK_OTHER_SCRIPT : LinkType.NO_LINK;
|
||||
}
|
||||
|
||||
private void gotoDeclaration(int pos) {
|
||||
@@ -1304,7 +1306,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<Scr
|
||||
Reference<Boolean> classTrait = new Reference<>(false);
|
||||
Reference<Integer> multinameIndexRef = new Reference<>(0);
|
||||
Reference<ABC> usedAbcRef = new Reference<>(null);
|
||||
if (decompiledTextArea.getPropertyTypeAtPos(getSwf().getAbcIndex(), pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef, usedAbcRef)) {
|
||||
if (decompiledTextArea.getPropertyTypeAtPos(getSwf().getAbcIndex(), pos, abcIndex, classIndex, traitIndex, classTrait, multinameIndexRef, usedAbcRef, false) != LinkType.NO_LINK) {
|
||||
UsageFrame.gotoUsage(ABCPanel.this, new TraitMultinameUsage(getAbcList().get(abcIndex.getVal()).getABC(), multinameIndexRef.getVal(), decompiledTextArea.getScriptLeaf().scriptIndex, classIndex.getVal(), traitIndex.getVal(), classTrait.getVal() ? TraitMultinameUsage.TRAITS_TYPE_CLASS : TraitMultinameUsage.TRAITS_TYPE_INSTANCE, null, -1) {
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.jpexs.decompiler.flash.gui.AppStrings;
|
||||
import com.jpexs.decompiler.flash.gui.Main;
|
||||
import com.jpexs.decompiler.flash.gui.View;
|
||||
import com.jpexs.decompiler.flash.gui.editor.DebuggableEditorPane;
|
||||
import com.jpexs.decompiler.flash.gui.editor.LinkType;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.flash.helpers.HighlightedText;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
|
||||
@@ -337,14 +338,14 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean getPropertyTypeAtPos(AbcIndexing indexing, int pos, Reference<Integer> abcIndex, Reference<Integer> classIndex, Reference<Integer> traitIndex, Reference<Boolean> classTrait, Reference<Integer> multinameIndex, Reference<ABC> abcUsed) {
|
||||
}
|
||||
|
||||
public LinkType getPropertyTypeAtPos(AbcIndexing indexing, int pos, Reference<Integer> abcIndex, Reference<Integer> classIndex, Reference<Integer> traitIndex, Reference<Boolean> classTrait, Reference<Integer> multinameIndex, Reference<ABC> abcUsed, boolean currentSwfOnly) {
|
||||
|
||||
int m = getMultinameAtPos(pos, true, abcUsed);
|
||||
|
||||
if (indexing == null) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
/*int m = getMultinameAtPos(pos, true, abcUsed);
|
||||
if (m <= 0) {
|
||||
@@ -356,64 +357,68 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
|
||||
Token prev;
|
||||
String propName = t.getString(sd);
|
||||
if (!(t.type == TokenType.IDENTIFIER || t.type == TokenType.KEYWORD || t.type == TokenType.REGEX)) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
prev = sd.getPrevToken(t);
|
||||
if (prev == null) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
if (!".".equals(prev.getString(sd))) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
Highlighting sh = Highlighting.search(highlightedText.getSpecialHighlights(), new HighlightData(), prev.start, prev.start);
|
||||
if (sh == null) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
|
||||
HighlightData data = sh.getProperties();
|
||||
|
||||
String parentType = data.propertyType;
|
||||
if (parentType.equals("*")) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
AbcIndexing.TraitIndex propertyTraitIndex = indexing.findProperty(new AbcIndexing.PropertyDef(propName, new TypeItem(parentType), getABC(), data.namespaceIndex), data.isStatic, !data.isStatic, true);
|
||||
Reference<Boolean> foundStatic = new Reference<>(null);
|
||||
AbcIndexing.TraitIndex propertyTraitIndex = indexing.findProperty(new AbcIndexing.PropertyDef(propName, new TypeItem(parentType), getABC(), data.namespaceIndex), true, !data.isStatic, true, foundStatic);
|
||||
if (propertyTraitIndex == null) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
|
||||
List<ABCContainerTag> abcs = getABC().getSwf().getAbcList();
|
||||
int index = 0;
|
||||
boolean found = false;
|
||||
boolean isCurrentSwf = false;
|
||||
for (ABCContainerTag cnt : abcs) {
|
||||
if (cnt.getABC() == propertyTraitIndex.abc) {
|
||||
abcIndex.setVal(index);
|
||||
found = true;
|
||||
isCurrentSwf = true;
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (!found) {
|
||||
return false;
|
||||
|
||||
if (currentSwfOnly) {
|
||||
if (!isCurrentSwf) {
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
}
|
||||
|
||||
abcUsed.setVal(propertyTraitIndex.abc);
|
||||
|
||||
index = propertyTraitIndex.abc.findClassByName(propertyTraitIndex.objType.toString());
|
||||
if (index == -1) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
classIndex.setVal(index);
|
||||
|
||||
classTrait.setVal(data.isStatic);
|
||||
classTrait.setVal(foundStatic.getVal());
|
||||
|
||||
Traits ts;
|
||||
if (data.isStatic) {
|
||||
if (foundStatic.getVal()) {
|
||||
ts = propertyTraitIndex.abc.class_info.get(index).static_traits;
|
||||
} else {
|
||||
ts = propertyTraitIndex.abc.instance_info.get(index).instance_traits;
|
||||
}
|
||||
|
||||
found = false;
|
||||
|
||||
boolean found = false;
|
||||
for (int i = 0; i < ts.traits.size(); i++) {
|
||||
if (ts.traits.get(i) == propertyTraitIndex.trait) {
|
||||
traitIndex.setVal(i);
|
||||
@@ -422,12 +427,12 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
return false;
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
|
||||
multinameIndex.setVal(propertyTraitIndex.trait.name_index);
|
||||
|
||||
return true;
|
||||
return isCurrentSwf ? LinkType.LINK_OTHER_SCRIPT : LinkType.LINK_OTHER_FILE;
|
||||
/*
|
||||
if (t.type != TokenType.IDENTIFIER && t.type != TokenType.KEYWORD && t.type != TokenType.REGEX) {
|
||||
return false;
|
||||
|
||||
@@ -49,6 +49,7 @@ import javax.swing.text.View;
|
||||
import jsyntaxpane.SyntaxDocument;
|
||||
import jsyntaxpane.SyntaxStyle;
|
||||
import jsyntaxpane.Token;
|
||||
import jsyntaxpane.TokenType;
|
||||
import jsyntaxpane.actions.ActionUtils;
|
||||
|
||||
/**
|
||||
@@ -382,8 +383,8 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLink(Token token) {
|
||||
return false;
|
||||
public LinkType isLink(Token token) {
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,7 @@ import jsyntaxpane.Token;
|
||||
*/
|
||||
public interface LinkHandler {
|
||||
|
||||
public boolean isLink(Token token);
|
||||
public LinkType isLink(Token token);
|
||||
|
||||
public void handleLink(Token token);
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2025 JPEXS
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.gui.editor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public enum LinkType {
|
||||
NO_LINK,
|
||||
LINK_THIS_SCRIPT,
|
||||
LINK_OTHER_SCRIPT,
|
||||
LINK_OTHER_FILE;
|
||||
}
|
||||
@@ -115,14 +115,7 @@ public class VariableMarker implements SyntaxComponent, CaretListener, PropertyC
|
||||
private UnderlinePainter underLineExternalMarkOccurencesPainter = new UnderlinePainter(new Color(0, 255, 0), DEFAULT_COLOR);
|
||||
|
||||
private Token lastUnderlined;
|
||||
private LinkType lastUnderlinedLinkType = LinkType.NO_LINK;
|
||||
|
||||
|
||||
public static enum LinkType {
|
||||
NO_LINK,
|
||||
LINK_THIS_SCRIPT,
|
||||
LINK_OTHER_SCRIPT;
|
||||
}
|
||||
private LinkType lastUnderlinedLinkType = LinkType.NO_LINK;
|
||||
|
||||
/**
|
||||
* Constructs a new Token highlighter
|
||||
@@ -629,10 +622,7 @@ public class VariableMarker implements SyntaxComponent, CaretListener, PropertyC
|
||||
if (pane.isEditable()) {
|
||||
return LinkType.NO_LINK;
|
||||
}
|
||||
if (((LineMarkedEditorPane) pane).getLinkHandler().isLink(token)) {
|
||||
return LinkType.LINK_OTHER_SCRIPT;
|
||||
}
|
||||
return LinkType.NO_LINK;
|
||||
return ((LineMarkedEditorPane) pane).getLinkHandler().isLink(token);
|
||||
}
|
||||
|
||||
public void handleLink(Token token) {
|
||||
|
||||
Reference in New Issue
Block a user