Class AstRoot

  • All Implemented Interfaces:
    java.lang.Comparable<AstNode>, java.lang.Iterable<Node>

    public class AstRoot
    extends ScriptNode
    Node for the root of a parse tree. It contains the statements and functions in the script, and a list of Comment nodes associated with the script as a whole. Node type is Token.SCRIPT.

    Note that the tree itself does not store errors. To collect the parse errors and warnings, pass an ErrorReporter to the Parser via the CompilerEnvirons.

    • Constructor Detail

      • AstRoot

        public AstRoot()
      • AstRoot

        public AstRoot​(int pos)
    • Method Detail

      • getComments

        public java.util.SortedSet<Comment> getComments()
        Returns comment set
        Returns:
        comment set, sorted by start position. Can be null.
      • setComments

        public void setComments​(java.util.SortedSet<Comment> comments)
        Sets comment list, and updates the parent of each entry to point to this node. Replaces any existing comments.
        Parameters:
        comments - comment list. can be null.
      • addComment

        public void addComment​(Comment comment)
        Add a comment to the comment set.
        Parameters:
        comment - the comment node.
        Throws:
        java.lang.IllegalArgumentException - if comment is null
      • setInStrictMode

        public void setInStrictMode​(boolean inStrictMode)
      • isInStrictMode

        public boolean isInStrictMode()
      • visitComments

        public void visitComments​(NodeVisitor visitor)
        Visits the comment nodes in the order they appear in the source code. The comments are not visited by the ScriptNode.visit(org.mozilla.javascript.ast.NodeVisitor) function - you must use this function to visit them.
        Parameters:
        visitor - the callback object. It is passed each comment node. The return value is ignored.
      • toSource

        public java.lang.String toSource​(int depth)
        Description copied from class: AstNode
        Emits source code for this node. Callee is responsible for calling this function recursively on children, incrementing indent as appropriate.

        Note: if the parser was in error-recovery mode, some AST nodes may have null children that are expected to be non-null when no errors are present. In this situation, the behavior of the toSource method is undefined: toSource implementations may assume that the AST node is error-free, since it is intended to be invoked only at runtime after a successful parse.

        Overrides:
        toSource in class Scope
        Parameters:
        depth - the current recursion depth, typically beginning at 0 when called on the root node.
      • debugPrint

        public java.lang.String debugPrint()
        A debug-printer that includes comments (at the end).
        Overrides:
        debugPrint in class AstNode
        Returns:
        a very verbose indented printout of the tree. The format of each line is: abs-pos name position length [identifier]
      • checkParentLinks

        public void checkParentLinks()
        Debugging function to check that the parser has set the parent link for every node in the tree.
        Throws:
        java.lang.IllegalStateException - if a parent link is missing