Class JavaScriptOutlineTreeGenerator

  • All Implemented Interfaces:
    org.mozilla.javascript.ast.NodeVisitor

    class JavaScriptOutlineTreeGenerator
    extends java.lang.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
    • 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 void addPrototypeAdditionsToRoot()
      While parsing JS code, this class identifies members added to prototypes.
      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.
      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.
      private java.util.List<org.mozilla.javascript.ast.AstNode> getChainedPropertyGetNodes​(org.mozilla.javascript.ast.PropertyGet pg)  
      private void getChainedPropertyGetNodesImpl​(org.mozilla.javascript.ast.PropertyGet pg, java.util.List<org.mozilla.javascript.ast.AstNode> nodes)  
      JavaScriptTreeNode getTreeRoot()  
      boolean visit​(org.mozilla.javascript.ast.AstNode node)  
      private boolean visitExpressionStatement​(org.mozilla.javascript.ast.ExpressionStatement exprStmt)  
      private boolean visitFunction​(org.mozilla.javascript.ast.FunctionNode fn)
      Visits a function AST node.
      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.
      private void visitPropertyDescriptors​(org.mozilla.javascript.ast.ObjectLiteral descriptorObjLit, java.lang.String clazz)
      It is assumed that descriptorObjectLit has been identified as an object literal containing property descriptors.
      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.
      private void visitPrototypeMembers​(org.mozilla.javascript.ast.ObjectLiteral objLiteral, java.lang.String clazz)  
      private boolean visitVariableDeclaration​(org.mozilla.javascript.ast.VariableDeclaration varDec)
      Visits a variable AST node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • textArea

        private org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea
      • prototypeAdditions

        private java.util.Map<java.lang.String,​java.util.List<JavaScriptTreeNode>> prototypeAdditions
    • Constructor Detail

      • JavaScriptOutlineTreeGenerator

        JavaScriptOutlineTreeGenerator​(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea,
                                       org.mozilla.javascript.ast.AstRoot ast)
    • 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)
      • visit

        public boolean visit​(org.mozilla.javascript.ast.AstNode node)
        Specified by:
        visit in interface org.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 that descriptorObjectLit has 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 to Object.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:
        false always, 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:
        false always, as this method manually visits the variable AST node's child nodes.