diff --git a/RSTALanguageSupport/build.gradle b/RSTALanguageSupport/build.gradle index 5d2b01d..87f8cc3 100644 --- a/RSTALanguageSupport/build.gradle +++ b/RSTALanguageSupport/build.gradle @@ -5,9 +5,9 @@ plugins { ['java', 'distribution', 'maven-publish', 'signing'].each { apply plugin: it } dependencies { - api 'com.fifesoft:rsyntaxtextarea:3.6.0' - api 'com.fifesoft:autocomplete:3.3.2' - implementation 'org.mozilla:rhino-all:1.8.0' + api 'com.fifesoft:rsyntaxtextarea:3.6.1' + api 'com.fifesoft:autocomplete:3.3.3' + implementation 'org.mozilla:rhino-all:1.9.0' } base { diff --git a/RSTALanguageSupport/src/main/java/org/fife/rsta/ac/js/tree/JavaScriptOutlineTreeGenerator.java b/RSTALanguageSupport/src/main/java/org/fife/rsta/ac/js/tree/JavaScriptOutlineTreeGenerator.java index 5b3b856..aace639 100644 --- a/RSTALanguageSupport/src/main/java/org/fife/rsta/ac/js/tree/JavaScriptOutlineTreeGenerator.java +++ b/RSTALanguageSupport/src/main/java/org/fife/rsta/ac/js/tree/JavaScriptOutlineTreeGenerator.java @@ -20,19 +20,7 @@ import org.fife.rsta.ac.js.util.RhinoUtil; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.mozilla.javascript.Token; -import org.mozilla.javascript.ast.Assignment; -import org.mozilla.javascript.ast.AstNode; -import org.mozilla.javascript.ast.AstRoot; -import org.mozilla.javascript.ast.ExpressionStatement; -import org.mozilla.javascript.ast.FunctionCall; -import org.mozilla.javascript.ast.FunctionNode; -import org.mozilla.javascript.ast.Name; -import org.mozilla.javascript.ast.NodeVisitor; -import org.mozilla.javascript.ast.ObjectLiteral; -import org.mozilla.javascript.ast.ObjectProperty; -import org.mozilla.javascript.ast.PropertyGet; -import org.mozilla.javascript.ast.VariableDeclaration; -import org.mozilla.javascript.ast.VariableInitializer; +import org.mozilla.javascript.ast.*; /** @@ -319,17 +307,21 @@ else if (rhs instanceof FunctionCall) { tn.setText(clazz + "()"); ObjectLiteral value = (ObjectLiteral)rhs; - List properties = value.getElements(); - for (ObjectProperty property : properties) { - - AstNode propertyKey = property.getLeft(); - tn = createTreeNode(propertyKey); - - String memberName = RhinoUtil.getPropertyName(propertyKey); - AstNode propertyValue = property.getRight(); - visitPrototypeMember(tn, clazz, - memberName, propertyValue); + List properties = value.getElements(); + for (AbstractObjectProperty property : properties) { + + if (property instanceof ObjectProperty) { + ObjectProperty propObj = (ObjectProperty)property; + AstNode propertyKey = propObj.getKey(); + tn = createTreeNode(propertyKey); + + String memberName = RhinoUtil.getPropertyName(propertyKey); + AstNode propertyValue = propObj.getValue(); + visitPrototypeMember(tn, clazz, + memberName, propertyValue); + } + // TODO: Also handle SpreadObjectProperty } } @@ -416,23 +408,27 @@ else if (rhs instanceof FunctionNode) { private void visitPropertyDescriptors(ObjectLiteral descriptorObjLit, String clazz) { - List descriptors = descriptorObjLit.getElements(); - for (ObjectProperty prop : descriptors) { + List descriptors = descriptorObjLit.getElements(); + for (AbstractObjectProperty prop : descriptors) { - AstNode propertyKey = prop.getLeft(); - AstNode propertyValue = prop.getRight(); + // TODO: Handle SpreadObjectPropertys, though they're not commonly used in + // property descriptors + if (prop instanceof ObjectProperty) { + ObjectProperty propObj = (ObjectProperty)prop; + AstNode propertyKey = propObj.getKey(); + AstNode propertyValue = propObj.getValue(); - // Should always be true, as this should be a property descriptor - if (propertyValue instanceof ObjectLiteral) { + // Should always be true, as this should be a property descriptor + if (propertyValue instanceof ObjectLiteral) { - JavaScriptTreeNode tn = createTreeNode(propertyKey); + JavaScriptTreeNode tn = createTreeNode(propertyKey); - String memberName = RhinoUtil.getPropertyName(propertyKey); - visitPropertyDescriptor(tn, clazz, - memberName, (ObjectLiteral)propertyValue); + String memberName = RhinoUtil.getPropertyName(propertyKey); + visitPropertyDescriptor(tn, clazz, + memberName, (ObjectLiteral) propertyValue); + } } - } } @@ -454,45 +450,50 @@ private void visitPropertyDescriptor(JavaScriptTreeNode tn, String clazz, // TODO: Glean more information than just the value, for a more // detailed icon. - List propDescProperties = propDesc.getElements(); - for (ObjectProperty propDescProperty : propDescProperties) { - - AstNode propertyKey = propDescProperty.getLeft(); - String propName = RhinoUtil.getPropertyName(propertyKey); - if ("value".equals(propName)) { + List propDescProperties = propDesc.getElements(); + for (AbstractObjectProperty propDescProperty : propDescProperties) { + + // TODO: Decide if we can/should look through SpreadObjectPropertys + if (propDescProperty instanceof ObjectProperty) { + + ObjectProperty objectProp = (ObjectProperty) propDescProperty; + AstNode propertyKey = objectProp.getKey(); + String propName = RhinoUtil.getPropertyName(propertyKey); + if ("value".equals(propName)) { + + AstNode propertyValue = objectProp.getValue(); + boolean isFunction = propertyValue instanceof FunctionNode; + String text = memberName; + if (isFunction) { + FunctionNode func = (FunctionNode) propertyValue; + text += RhinoUtil.getFunctionArgsString(func); + tn.setIcon(IconFactory.getIcon(IconFactory.PUBLIC_METHOD_ICON)); + tn.setSortPriority(JavaScriptOutlineTree.PRIORITY_FUNCTION); + } + else { + tn.setIcon(IconFactory.getIcon(IconFactory.PUBLIC_FIELD_ICON)); + tn.setSortPriority(JavaScriptOutlineTree.PRIORITY_VARIABLE); + } - AstNode propertyValue = propDescProperty.getRight(); - boolean isFunction = propertyValue instanceof FunctionNode; - String text = memberName; - if (isFunction) { - FunctionNode func = (FunctionNode)propertyValue; - text += RhinoUtil.getFunctionArgsString(func); - tn.setIcon(IconFactory.getIcon(IconFactory.PUBLIC_METHOD_ICON)); - tn.setSortPriority(JavaScriptOutlineTree.PRIORITY_FUNCTION); - } - else { - tn.setIcon(IconFactory.getIcon(IconFactory.PUBLIC_FIELD_ICON)); - tn.setSortPriority(JavaScriptOutlineTree.PRIORITY_VARIABLE); - } + tn.setText(text); + if (prototypeAdditions == null) { + prototypeAdditions = new HashMap<>(); + } + List list = prototypeAdditions.computeIfAbsent(clazz, k -> new ArrayList<>()); - tn.setText(text); - if (prototypeAdditions==null) { - prototypeAdditions = new HashMap<>(); - } - List list = prototypeAdditions.computeIfAbsent(clazz, k -> new ArrayList<>()); + list.add(tn); - list.add(tn); + if (isFunction) { + JavaScriptTreeNode prevScopeTreeNode = curScopeTreeNode; + curScopeTreeNode = tn; + FunctionNode func = (FunctionNode) propertyValue; + func.getBody().visit(this); + curScopeTreeNode = prevScopeTreeNode; + } - if (isFunction) { - JavaScriptTreeNode prevScopeTreeNode = curScopeTreeNode; - curScopeTreeNode = tn; - FunctionNode func = (FunctionNode)propertyValue; - func.getBody().visit(this); - curScopeTreeNode = prevScopeTreeNode; } } - } } @@ -501,17 +502,23 @@ private void visitPropertyDescriptor(JavaScriptTreeNode tn, String clazz, private void visitPrototypeMembers(ObjectLiteral objLiteral, String clazz) { - List properties = objLiteral.getElements(); - for (ObjectProperty property : properties) { - - AstNode propertyKey = property.getLeft(); - JavaScriptTreeNode tn = createTreeNode(propertyKey); + List properties = objLiteral.getElements(); + for (AbstractObjectProperty property : properties) { - String memberName = RhinoUtil.getPropertyName(propertyKey); - AstNode propertyValue = property.getRight(); - visitPrototypeMember(tn, clazz, - memberName, propertyValue); + if (property instanceof ObjectProperty) { + ObjectProperty objProperty = (ObjectProperty)property; + AstNode propertyKey = objProperty.getKey(); + JavaScriptTreeNode tn = createTreeNode(propertyKey); + String memberName = RhinoUtil.getPropertyName(propertyKey); + AstNode propertyValue = objProperty.getValue(); + visitPrototypeMember(tn, clazz, + memberName, propertyValue); + } + else if (property instanceof SpreadObjectProperty) { + // TODO: Implement me + // SpreadObjectProperty sop = (SpreadObjectProperty)property; + } } }