Class TemplateLiteral

All Implemented Interfaces:
Comparable<AstNode>, Iterable<Node>

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

Node type is Token.TEMPLATE_LITERAL.

  • Constructor Details

    • TemplateLiteral

      public TemplateLiteral()
    • TemplateLiteral

      public TemplateLiteral(int pos)
    • TemplateLiteral

      public TemplateLiteral(int pos, int len)
  • Method Details

    • getTemplateStrings

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

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

      public 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(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:
      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:
      IndexOutOfBoundsException - if the index is invalid
    • toSource

      public 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