Package org.fife.rsta.ac.js.tree
Class JavaScriptOutlineTreeGenerator
java.lang.Object
org.fife.rsta.ac.js.tree.JavaScriptOutlineTreeGenerator
- All Implemented Interfaces:
org.mozilla.javascript.ast.NodeVisitor
class JavaScriptOutlineTreeGenerator
extends Object
implements org.mozilla.javascript.ast.NodeVisitor
Generates the root node for a
JavaScriptOutlineTree based on a
Rhino AST of RSyntaxTextArea code.- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JavaScriptTreeNodeprivate Map<String, List<JavaScriptTreeNode>> private JavaScriptTreeNodeprivate org.fife.ui.rsyntaxtextarea.RSyntaxTextArea -
Constructor Summary
ConstructorsConstructorDescriptionJavaScriptOutlineTreeGenerator(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea, org.mozilla.javascript.ast.AstRoot ast) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidWhile parsing JS code, this class identifies members added to prototypes.private JavaScriptTreeNodecreateTreeNode(List<org.mozilla.javascript.ast.AstNode> nodes) Creates and returns a node for the outline tree that corresponds to specific AST nodes.private JavaScriptTreeNodecreateTreeNode(org.mozilla.javascript.ast.AstNode node) Creates and returns a node for the outline tree that corresponds to a specific AST node.private List<org.mozilla.javascript.ast.AstNode> getChainedPropertyGetNodes(org.mozilla.javascript.ast.PropertyGet pg) private voidgetChainedPropertyGetNodesImpl(org.mozilla.javascript.ast.PropertyGet pg, List<org.mozilla.javascript.ast.AstNode> nodes) booleanvisit(org.mozilla.javascript.ast.AstNode node) private booleanvisitExpressionStatement(org.mozilla.javascript.ast.ExpressionStatement exprStmt) private booleanvisitFunction(org.mozilla.javascript.ast.FunctionNode fn) Visits a function AST node.private voidvisitPropertyDescriptor(JavaScriptTreeNode tn, String clazz, String memberName, org.mozilla.javascript.ast.ObjectLiteral propDesc) Parses an AST node that represents a property descriptor.private voidvisitPropertyDescriptors(org.mozilla.javascript.ast.ObjectLiteral descriptorObjLit, String clazz) It is assumed thatdescriptorObjectLithas been identified as an object literal containing property descriptors.private voidvisitPrototypeMember(JavaScriptTreeNode tn, String clazz, String memberName, org.mozilla.javascript.ast.AstNode memberValue) Visits a node representing a member being defined on a prototype.private voidvisitPrototypeMembers(org.mozilla.javascript.ast.ObjectLiteral objLiteral, String clazz) private booleanvisitVariableDeclaration(org.mozilla.javascript.ast.VariableDeclaration varDec) Visits a variable AST node.
-
Field Details
-
root
-
textArea
private org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea -
curScopeTreeNode
-
prototypeAdditions
-
-
Constructor Details
-
JavaScriptOutlineTreeGenerator
JavaScriptOutlineTreeGenerator(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea, org.mozilla.javascript.ast.AstRoot ast)
-
-
Method Details
-
addPrototypeAdditionsToRoot
private void addPrototypeAdditionsToRoot()While parsing JS code, this class identifies members added to prototypes. After all parsing is done, this method is called to create tree nodes for those prototype members identified. -
createTreeNode
Creates and returns a node for the outline tree that corresponds to a specific AST node.- Parameters:
node- The AST node.- Returns:
- The outline tree node.
-
createTreeNode
Creates and returns a node for the outline tree that corresponds to specific AST nodes.- Parameters:
nodes- The AST nodes.- Returns:
- The outline tree node.
-
getChainedPropertyGetNodes
private List<org.mozilla.javascript.ast.AstNode> getChainedPropertyGetNodes(org.mozilla.javascript.ast.PropertyGet pg) -
getChainedPropertyGetNodesImpl
private void getChainedPropertyGetNodesImpl(org.mozilla.javascript.ast.PropertyGet pg, List<org.mozilla.javascript.ast.AstNode> nodes) -
getTreeRoot
-
visit
public boolean visit(org.mozilla.javascript.ast.AstNode node) - Specified by:
visitin interfaceorg.mozilla.javascript.ast.NodeVisitor
-
visitExpressionStatement
private boolean visitExpressionStatement(org.mozilla.javascript.ast.ExpressionStatement exprStmt) -
visitPropertyDescriptors
private void visitPropertyDescriptors(org.mozilla.javascript.ast.ObjectLiteral descriptorObjLit, String clazz) It is assumed thatdescriptorObjectLithas been identified as an object literal containing property descriptors. Any property descriptors found as properties of that literal are parsed and tree nodes are created for them.- Parameters:
descriptorObjLit- The object literal containing property descriptors (for example, the object parameter toObject.create()).clazz- The class that the properties belong to.
-
visitPropertyDescriptor
private void visitPropertyDescriptor(JavaScriptTreeNode tn, String clazz, String memberName, org.mozilla.javascript.ast.ObjectLiteral propDesc) Parses an AST node that represents a property descriptor.- Parameters:
tn- The tree node representing the property defined by the property descriptor. This is configured by this method, and added to the list of nodes to ultimately add to the tree.clazz- The class that the property belongs to.memberName- The name of the property.propDesc- The node representing the property descriptor.
-
visitPrototypeMembers
private void visitPrototypeMembers(org.mozilla.javascript.ast.ObjectLiteral objLiteral, String clazz) -
visitPrototypeMember
private void visitPrototypeMember(JavaScriptTreeNode tn, String clazz, String memberName, org.mozilla.javascript.ast.AstNode memberValue) Visits a node representing a member being defined on a prototype.- Parameters:
tn- The tree node to extend, representing this member.clazz- The class that the property belongs to.memberName- The name of the member.memberValue- The AST node representing the value of the member.
-
visitFunction
private boolean visitFunction(org.mozilla.javascript.ast.FunctionNode fn) Visits a function AST node. This will create a tree node for the function, and also visit the AST nodes in the function's body, to identify local variables, nested functions, etc.- Parameters:
fn- The function node.- Returns:
falsealways, as this method manually visits the function AST node's child nodes.
-
visitVariableDeclaration
private boolean visitVariableDeclaration(org.mozilla.javascript.ast.VariableDeclaration varDec) Visits a variable AST node. This will create a tree node for the variable, and if it also has an initializer, it is parsed.- Parameters:
varDec- The variable declaration AST node.- Returns:
falsealways, as this method manually visits the variable AST node's child nodes.
-