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 java.lang.Object implements org.mozilla.javascript.ast.NodeVisitorGenerates the root node for aJavaScriptOutlineTreebased on a Rhino AST ofRSyntaxTextAreacode.- Version:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private JavaScriptTreeNodecurScopeTreeNodeprivate java.util.Map<java.lang.String,java.util.List<JavaScriptTreeNode>>prototypeAdditionsprivate JavaScriptTreeNoderootprivate org.fife.ui.rsyntaxtextarea.RSyntaxTextAreatextArea
-
Constructor Summary
Constructors Constructor Description JavaScriptOutlineTreeGenerator(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea, org.mozilla.javascript.ast.AstRoot ast)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddPrototypeAdditionsToRoot()While parsing JS code, this class identifies members added to prototypes.private JavaScriptTreeNodecreateTreeNode(java.util.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 java.util.List<org.mozilla.javascript.ast.AstNode>getChainedPropertyGetNodes(org.mozilla.javascript.ast.PropertyGet pg)private voidgetChainedPropertyGetNodesImpl(org.mozilla.javascript.ast.PropertyGet pg, java.util.List<org.mozilla.javascript.ast.AstNode> nodes)JavaScriptTreeNodegetTreeRoot()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, java.lang.String clazz, java.lang.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, java.lang.String clazz)It is assumed thatdescriptorObjectLithas been identified as an object literal containing property descriptors.private voidvisitPrototypeMember(JavaScriptTreeNode tn, java.lang.String clazz, java.lang.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, java.lang.String clazz)private booleanvisitVariableDeclaration(org.mozilla.javascript.ast.VariableDeclaration varDec)Visits a variable AST node.
-
-
-
Field Detail
-
root
private JavaScriptTreeNode root
-
textArea
private org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea
-
curScopeTreeNode
private JavaScriptTreeNode curScopeTreeNode
-
prototypeAdditions
private java.util.Map<java.lang.String,java.util.List<JavaScriptTreeNode>> prototypeAdditions
-
-
Method Detail
-
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
private JavaScriptTreeNode createTreeNode(org.mozilla.javascript.ast.AstNode node)
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
private JavaScriptTreeNode createTreeNode(java.util.List<org.mozilla.javascript.ast.AstNode> nodes)
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 java.util.List<org.mozilla.javascript.ast.AstNode> getChainedPropertyGetNodes(org.mozilla.javascript.ast.PropertyGet pg)
-
getChainedPropertyGetNodesImpl
private void getChainedPropertyGetNodesImpl(org.mozilla.javascript.ast.PropertyGet pg, java.util.List<org.mozilla.javascript.ast.AstNode> nodes)
-
getTreeRoot
public JavaScriptTreeNode 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, java.lang.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, java.lang.String clazz, java.lang.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, java.lang.String clazz)
-
visitPrototypeMember
private void visitPrototypeMember(JavaScriptTreeNode tn, java.lang.String clazz, java.lang.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.
-
-