Class Node

java.lang.Object
com.oracle.js.parser.ir.Node
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
Block, CaseNode, ExportNode, ExportSpecifierNode, Expression, FromNode, ImportClauseNode, ImportNode, ImportSpecifierNode, NamedExportsNode, NamedImportsNode, NameSpaceImportNode, PropertyNode, Statement

public abstract class Node extends Object implements Cloneable
Nodes are used to compose Abstract Syntax Trees.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
    End of source range.
    protected final int
    Start of source range.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Node(long token, int finish)
    Constructor
    protected
    Node(long token, int start, int finish)
    Constructor
    protected
    Node(Node node)
    Copy constructor
    protected
    Node(Node node, int finish)
    Copy constructor that overrides finish
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Node
    accept(NodeVisitor<? extends LexicalContext> visitor)
    Provides a means to navigate the IR.
    abstract <R> R
    Provides a means to navigate the IR.
    protected Object
     
    final boolean
    equals(Object other)
     
    int
    Get the finish position for this node in the source string
    int
    Integer to sort nodes in source order.
    int
    Get start position for node
    long
    Get the token for this node.
    final int
     
    boolean
    Is this an assignment node - for example a var node with an init or a binary node that writes to a destination
    boolean
    Is this a loop node?
    boolean
    Tests if this node has the specific token type.
    Returns this node's token's type.
    final String
     
    final String
    toString(boolean includeTypeInfo)
    Return String representation of this Node.
    abstract void
    toString(StringBuilder sb, boolean printType)
    Print logic that decides whether to show the optimistic type or not - for example it should not be printed after just parse, when it hasn't been computed, or has been set to a trivially provable value

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • start

      protected final int start
      Start of source range.
    • finish

      protected final int finish
      End of source range.
  • Constructor Details

    • Node

      public Node(long token, int finish)
      Constructor
      Parameters:
      token - token
      finish - finish
    • Node

      protected Node(long token, int start, int finish)
      Constructor
      Parameters:
      token - token
      start - start
      finish - finish
    • Node

      protected Node(Node node)
      Copy constructor
      Parameters:
      node - source node
    • Node

      protected Node(Node node, int finish)
      Copy constructor that overrides finish
      Parameters:
      node - source node
      finish - Last character
  • Method Details

    • isLoop

      public boolean isLoop()
      Is this a loop node?
      Returns:
      true if atom
    • isAssignment

      public boolean isAssignment()
      Is this an assignment node - for example a var node with an init or a binary node that writes to a destination
      Returns:
      true if assignment
    • accept

      public abstract Node accept(NodeVisitor<? extends LexicalContext> visitor)
      Provides a means to navigate the IR.
      Parameters:
      visitor - Node visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • accept

      public abstract <R> R accept(TranslatorNodeVisitor<? extends LexicalContext,R> visitor)
      Provides a means to navigate the IR.
      Parameters:
      visitor - Node visitor.
      Returns:
      node the node or its replacement after visitation, null if no further visitations are required
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • toString

      public final String toString(boolean includeTypeInfo)
      Return String representation of this Node.
      Parameters:
      includeTypeInfo - include type information or not
    • toString

      public abstract void toString(StringBuilder sb, boolean printType)
      Print logic that decides whether to show the optimistic type or not - for example it should not be printed after just parse, when it hasn't been computed, or has been set to a trivially provable value
      Parameters:
      sb - string builder
      printType - print type?
    • getFinish

      public int getFinish()
      Get the finish position for this node in the source string
      Returns:
      finish
    • getStart

      public int getStart()
      Get start position for node
      Returns:
      start position
    • getSourceOrder

      public int getSourceOrder()
      Integer to sort nodes in source order. This order is used by parser API to sort statements in correct order. By default, this is the start position of this node.
      Returns:
      int code to sort this node.
    • clone

      protected Object clone()
      Overrides:
      clone in class Object
    • equals

      public final boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • tokenType

      public TokenType tokenType()
      Returns this node's token's type. If you want to check for the node having a specific token type, consider using isTokenType(TokenType) instead.
      Returns:
      type of token.
    • isTokenType

      public boolean isTokenType(TokenType type)
      Tests if this node has the specific token type.
      Parameters:
      type - a token type to check this node's token type against
      Returns:
      true if token types match.
    • getToken

      public long getToken()
      Get the token for this node. If you want to retrieve the token's type, consider using tokenType() or isTokenType(TokenType) instead.
      Returns:
      the token