diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/CatchScope.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/CatchScope.java index 8bb4f329b..121f53620 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/CatchScope.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/CatchScope.java @@ -25,28 +25,23 @@ import java.util.List; */ public class CatchScope implements Scope { - private final List privateItems; - private final List sharedItems; + private final List items = new ArrayList<>(); private final int position; private final int endPosition; public CatchScope(int position, int endPosition, Variable catchVariable, List catchBody) { - this.privateItems = new ArrayList<>(); - this.privateItems.add(catchVariable); - this.sharedItems = catchBody; + items.add(new VariableOrScopeWithAccess(catchVariable, false)); + for (VariableOrScope s : catchBody) { + items.add(new VariableOrScopeWithAccess(s, true)); + } this.position = position; this.endPosition = endPosition; } @Override - public List getSharedItems() { - return sharedItems; - } - - @Override - public List getPrivateItems() { - return privateItems; - } + public List getScopeItems() { + return items; + } @Override public int getPosition() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/ClassScope.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/ClassScope.java index 481490183..278b8d74b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/ClassScope.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/ClassScope.java @@ -25,25 +25,22 @@ import java.util.List; */ public class ClassScope implements Scope { - private final List privateItems; + private final List items = new ArrayList<>(); private final int position; private final int endPosition; public ClassScope(int position, int endPosition, List traits) { - this.privateItems = traits; + for (VariableOrScope s : traits) { + items.add(new VariableOrScopeWithAccess(s, false)); + } this.position = position; this.endPosition = endPosition; } @Override - public List getSharedItems() { - return new ArrayList<>(); - } - - @Override - public List getPrivateItems() { - return privateItems; - } + public List getScopeItems() { + return items; + } @Override public int getPosition() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/FunctionScope.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/FunctionScope.java index 3a242dedc..ab57af00c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/FunctionScope.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/FunctionScope.java @@ -25,13 +25,15 @@ import java.util.List; */ public class FunctionScope implements Scope { - private final List privateItems; + private final List items = new ArrayList<>(); private final boolean isStatic; private final int position; private final int endPosition; public FunctionScope(int position, int endPosition, List functionBody, boolean isStatic) { - this.privateItems = functionBody; + for (VariableOrScope s : functionBody) { + items.add(new VariableOrScopeWithAccess(s, false)); + } this.isStatic = isStatic; this.position = position; this.endPosition = endPosition; @@ -41,15 +43,6 @@ public class FunctionScope implements Scope { return isStatic; } - @Override - public List getSharedItems() { - return new ArrayList<>(); - } - - @Override - public List getPrivateItems() { - return privateItems; - } @Override public int getPosition() { @@ -60,5 +53,10 @@ public class FunctionScope implements Scope { public int getEndPosition() { return endPosition; } + + @Override + public List getScopeItems() { + return items; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/Path.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/Path.java index 4348106f9..e02afaa8a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/Path.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/Path.java @@ -32,6 +32,8 @@ public class Path { public static Path PATH_PARENTHESIS = new Path(PART_PARENTHESIS); public static Path PATH_BRACKETS = new Path(PART_BRACKETS); + + private Integer cachedHashCode = null; @Override public String toString() { @@ -133,9 +135,12 @@ public class Path { @Override public int hashCode() { + if (cachedHashCode != null) { + return cachedHashCode; + } int hash = 5; hash = 89 * hash + Objects.hashCode(this.parts); - return hash; + return cachedHashCode = hash; } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/Scope.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/Scope.java index 187f6c415..6348414af 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/Scope.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/Scope.java @@ -24,9 +24,7 @@ import java.util.List; */ public interface Scope extends VariableOrScope { - public List getSharedItems(); - - public List getPrivateItems(); + public List getScopeItems(); public int getEndPosition(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/SimpleParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/SimpleParser.java index dd2f1ca42..42e0832ec 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/SimpleParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/SimpleParser.java @@ -314,21 +314,8 @@ public interface SimpleParser { } } } - - List list = new ArrayList<>(); - for (VariableOrScope it : vs.getPrivateItems()) { - list.add(new VariableOrScopeWithAccess(it, false)); - } - for (VariableOrScope it : vs.getSharedItems()) { - list.add(new VariableOrScopeWithAccess(it, true)); - } - list.sort(new Comparator() { - @Override - public int compare(VariableOrScopeWithAccess o1, VariableOrScopeWithAccess o2) { - return o1.var.getPosition() - o2.var.getPosition(); - } - }); - parseVariablesList(list, definitionPosToReferences, referenceToDefinition, privateVarFullNameToDefinitionPosition, privateVarNameToDefinitionPosition, positionToStatic, subStatic, errors, vs, innerFunctionCanUseTraits, externalSimpleTypes, externalFullTypes, referenceToExternalTypeIndex, definitionToType, definitionToCallType, definitionToSubType, definitionToCallSubType, traitFullNameToDefinition, linkHandler, simpleExternalClassNameToFullClassName, referenceToExternalTraitKey, externalTraitKeyToReference, separatorPosToType, separatorIsStatic, caretPosition, variableSuggestions, vs.getPosition(), vs.getEndPosition()); + + parseVariablesList(vs.getScopeItems(), definitionPosToReferences, referenceToDefinition, privateVarFullNameToDefinitionPosition, privateVarNameToDefinitionPosition, positionToStatic, subStatic, errors, vs, innerFunctionCanUseTraits, externalSimpleTypes, externalFullTypes, referenceToExternalTypeIndex, definitionToType, definitionToCallType, definitionToSubType, definitionToCallSubType, traitFullNameToDefinition, linkHandler, simpleExternalClassNameToFullClassName, referenceToExternalTraitKey, externalTraitKeyToReference, separatorPosToType, separatorIsStatic, caretPosition, variableSuggestions, vs.getPosition(), vs.getEndPosition()); } if (vt2 != null && caretPosition != null && variableSuggestions.isEmpty()) { @@ -409,15 +396,8 @@ public interface SimpleParser { parentVarNameToDefinitionPosition.put(ct.getLastName(), ct.position); } if (v instanceof Scope) { - Scope s = (Scope) v; - List list = new ArrayList<>(); - for (VariableOrScope it : s.getPrivateItems()) { - list.add(new VariableOrScopeWithAccess(it, false)); - } - for (VariableOrScope it : s.getSharedItems()) { - list.add(new VariableOrScopeWithAccess(it, true)); - } - findClassTraits(list, traitFullNameToDefinition, definitionPosToReferences, positionToStatic, definitionToType, definitionToCallType, definitionToSubType, definitionToCallSubType, parentVarFullNameToDefinitionPosition, parentVarNameToDefinitionPosition); + Scope s = (Scope) v; + findClassTraits(s.getScopeItems(), traitFullNameToDefinition, definitionPosToReferences, positionToStatic, definitionToType, definitionToCallType, definitionToSubType, definitionToCallSubType, parentVarFullNameToDefinitionPosition, parentVarNameToDefinitionPosition); } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/TraitVarConstValueScope.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/TraitVarConstValueScope.java index 3f021acec..b4548986f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/TraitVarConstValueScope.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/simpleparser/TraitVarConstValueScope.java @@ -28,30 +28,22 @@ public class TraitVarConstValueScope implements Scope { private final int position; private final int endPosition; - private List sharedItems; + private final List items = new ArrayList<>(); private final boolean isStatic; public TraitVarConstValueScope(int position, int endPosition, List sharedItems, boolean isStatic) { this.position = position; this.endPosition = endPosition; - this.sharedItems = sharedItems; + for (VariableOrScope s : sharedItems) { + items.add(new VariableOrScopeWithAccess(s, true)); + } this.isStatic = isStatic; } public boolean isStatic() { return isStatic; } - - @Override - public List getSharedItems() { - return sharedItems; - } - - @Override - public List getPrivateItems() { - return new ArrayList<>(); - } - + @Override public int getPosition() { return position; @@ -61,6 +53,11 @@ public class TraitVarConstValueScope implements Scope { public int getEndPosition() { return endPosition; } + + @Override + public List getScopeItems() { + return items; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/DottedChain.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/DottedChain.java index 3b8e7966a..0f0b19b4f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/DottedChain.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/DottedChain.java @@ -255,6 +255,18 @@ public class DottedChain implements Serializable, Comparable { return parts.get(index).name; } + + /** + * Gets string parts as list. + * @return String parts + */ + public List getStringParts() { + List ret = new ArrayList<>(); + for (int i = 0; i < parts.size(); i++) { + ret.add(parts.get(i).name); + } + return ret; + } /** * Checks whether the part at the given index is an attribute. diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index 9a575bbcd..6400b6d85 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -1779,5 +1779,17 @@ public class Helper { } return Integer.parseInt(version); } + + public static List splitString(String delimiter, String str) { + List result = new ArrayList<>(); + int start = 0; + int end; + while ((end = str.indexOf(delimiter, start)) != -1) { + result.add(str.substring(start, end)); + start = end + 1; + } + result.add(str.substring(start)); + return result; + } } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 6ee8a304d..817f72cae 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -1074,7 +1074,11 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener errors = new LinkedHashMap<>(); public static final long ERROR_DELAY = 2000; private Timer errorsTimer; + private Timer parseTimer; private Map> definitionPosToReferences = new LinkedHashMap<>(); private Map referenceToDefinition = new LinkedHashMap<>(); @@ -534,6 +535,7 @@ public class VariableMarker implements SyntaxComponent, CaretListener, PropertyC } } + @SuppressWarnings("unchecked") private void showCodeCompletion() { SyntaxDocument sDoc = (SyntaxDocument) pane.getDocument(); sDoc.readLock(); @@ -615,7 +617,7 @@ public class VariableMarker implements SyntaxComponent, CaretListener, PropertyC if (suggestions.isEmpty()) { codeCompletionPopup.setVisible(false); return; - } + } Collections.sort(suggestions, new NaturalOrderComparator()); if (!identText.isEmpty()) { for (int i = suggestions.size() - 1; i >= 0; i--) { @@ -698,6 +700,7 @@ public class VariableMarker implements SyntaxComponent, CaretListener, PropertyC View.execInEventDispatch(new Runnable() { @Override public void run() { + reParse(); showCodeCompletion(); } }); @@ -965,15 +968,17 @@ public class VariableMarker implements SyntaxComponent, CaretListener, PropertyC } } - private void documentUpdated() { + private synchronized void reParse() { errors.clear(); removeErrorMarkers(); highlightsPanel.repaint(); try { SyntaxDocument sDoc = (SyntaxDocument) pane.getDocument(); + sDoc.readLock();; + int pos = pane.getCaretPosition(); String fullText = sDoc.getText(0, sDoc.getLength()); - + sDoc.readUnlock(); if (!(pane instanceof LineMarkedEditorPane)) { return; } @@ -1011,7 +1016,7 @@ public class VariableMarker implements SyntaxComponent, CaretListener, PropertyC newLocalTypeTraitNames, newDefinitionToType, newDefinitionToCallType, - pane.getCaretPosition(), + pos, newVariableSuggestions ); @@ -1062,6 +1067,22 @@ public class VariableMarker implements SyntaxComponent, CaretListener, PropertyC errorsTimer = tim; markTokenAt(pane.getCaretPosition()); } + + private void documentUpdated() { + Timer pTimer = parseTimer; + if (pTimer != null) { + pTimer.cancel(); + } + pTimer = new Timer(); + + pTimer.schedule(new TimerTask() { + @Override + public void run() { + reParse(); + } + }, 100); + parseTimer = pTimer; + } @Override public void insertUpdate(DocumentEvent e) {