Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions RSTALanguageSupport/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;


/**
Expand Down Expand Up @@ -319,17 +307,21 @@ else if (rhs instanceof FunctionCall) {
tn.setText(clazz + "()");

ObjectLiteral value = (ObjectLiteral)rhs;
List<ObjectProperty> 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<AbstractObjectProperty> 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
}

}
Expand Down Expand Up @@ -416,23 +408,27 @@ else if (rhs instanceof FunctionNode) {
private void visitPropertyDescriptors(ObjectLiteral descriptorObjLit,
String clazz) {

List<ObjectProperty> descriptors = descriptorObjLit.getElements();
for (ObjectProperty prop : descriptors) {
List<AbstractObjectProperty> 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);

}
}

}

}
Expand All @@ -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<ObjectProperty> propDescProperties = propDesc.getElements();
for (ObjectProperty propDescProperty : propDescProperties) {

AstNode propertyKey = propDescProperty.getLeft();
String propName = RhinoUtil.getPropertyName(propertyKey);
if ("value".equals(propName)) {
List<AbstractObjectProperty> 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<JavaScriptTreeNode> list = prototypeAdditions.computeIfAbsent(clazz, k -> new ArrayList<>());

tn.setText(text);
if (prototypeAdditions==null) {
prototypeAdditions = new HashMap<>();
}
List<JavaScriptTreeNode> 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;
}

}

}

}
Expand All @@ -501,17 +502,23 @@ private void visitPropertyDescriptor(JavaScriptTreeNode tn, String clazz,
private void visitPrototypeMembers(ObjectLiteral objLiteral,
String clazz) {

List<ObjectProperty> properties = objLiteral.getElements();
for (ObjectProperty property : properties) {

AstNode propertyKey = property.getLeft();
JavaScriptTreeNode tn = createTreeNode(propertyKey);
List<AbstractObjectProperty> 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;
}
}

}
Expand Down