Class TemplateLiteral

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

    public class TemplateLiteral
    extends AstNode
    AST node for a Template literal.

    Node type is Token.TEMPLATE_LITERAL.

    • Field Detail

      • elements

        private java.util.List<AstNode> elements
    • Constructor Detail

      • TemplateLiteral

        public TemplateLiteral()
      • TemplateLiteral

        public TemplateLiteral​(int pos)
      • TemplateLiteral

        public TemplateLiteral​(int pos,
                               int len)
    • Method Detail

      • getTemplateStrings

        public java.util.List<TemplateCharacters> getTemplateStrings()
        Returns a list of all literal sections of this template literal
      • getSubstitutions

        public java.util.List<AstNode> getSubstitutions()
        Returns a list of all substitutions of this template literal
      • getElements

        public java.util.List<AstNode> getElements()
        Returns the element list
        Returns:
        the element list. If there are no elements, returns an immutable empty list.
      • setElements

        public void setElements​(java.util.List<AstNode> elements)
        Sets the element list, and sets each element's parent to this node.
        Parameters:
        elements - the element list. Can be null.
      • addElement

        public void addElement​(AstNode element)
        Adds an element to the list, and sets its parent to this node.
        Parameters:
        element - the element to add
        Throws:
        java.lang.IllegalArgumentException - if element is null.
      • getSize

        public int getSize()
        Returns the number of elements in this TemplateLiteral literal.
      • getElement

        public AstNode getElement​(int index)
        Returns element at specified index.
        Parameters:
        index - the index of the element to retrieve
        Returns:
        the element
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid
      • 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.

        Specified by:
        toSource in class AstNode
        Parameters:
        depth - the current recursion depth, typically beginning at 0 when called on the root node.
      • visit

        public void visit​(NodeVisitor v)
        Visits this node.
        Specified by:
        visit in class AstNode
        Parameters:
        v - the object to call with this node and its children