CSTNode (Groovy 5.0.8)

Package: org.codehaus.groovy.syntax

## [Java] Class CSTNode

- org.codehaus.groovy.syntax.CSTNode

-     public abstract class CSTNode
      extends Object

  An abstract base class for nodes in the concrete syntax tree that is the result of parsing. Note that the CSTNode is inextricably linked with the Token in that every CSTNode has a Token as its root.

  See Also:
    Token
    Reduction
    Types

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public CSTNode` | `add(CSTNode element)` Adds an element to the node.
    `` | `public void` | `addChildrenOf(CSTNode of)` Adds all children of the specified node to this one.
    `` | `public abstract Reduction` | `asReduction()` Creates a `Reduction` from this node.
    `` | `public boolean` | `canMean(int type)` Returns true if the node can be coerced to the specified type.
    `` | `public int` | `children()` Returns the number of non-root elements in the node.
    `` | `public abstract CSTNode` | `get(int index)` Returns the specified element, or null.
    `` | `public CSTNode` | `get(int index, boolean safe)` Returns the specified element, or Token.NULL if safe is set and the specified element is null (or doesn't exist).
    `` | `public String` | `getDescription()` Returns a description of the node.
    `` | `public int` | `getMeaning()` Returns the meaning of this node.
    `` | `public int` | `getMeaningAs(int[] types)` Returns the first matching meaning of the specified types.
    `` | `public abstract Token` | `getRoot()` Returns the root of the node.
    `` | `public Token` | `getRoot(boolean safe)` Returns the root of the node, the Token that indicates its type.
    `` | `public String` | `getRootText()` Returns the text of the root.
    `` | `public int` | `getStartColumn()` Returns the starting column of the node.
    `` | `public int` | `getStartLine()` Returns the starting line of the node.
    `` | `public int` | `getType()` Returns the actual type of the node.
    `` | `public boolean` | `hasChildren()` Returns true if the node has any non-root elements.
    `` | `public boolean` | `isA(int type)` Returns true if the node's meaning matches the specified type.
    `` | `public boolean` | `isAllOf(int[] types)` Returns true if the node's meaning matches all of the specified types.
    `` | `public boolean` | `isAnExpression()` Returns true if the node is a complete expression.
    `` | `public boolean` | `isEmpty()` Returns true if the node is completely empty (no root, even).
    `` | `public boolean` | `isOneOf(int[] types)` Returns true if the node's meaning matches any of the specified types.
    `` | `public void` | `markAsExpression()` Marks the node a complete expression.
    `` | `public CSTNode` | `set(int index, CSTNode element)` Sets an element node in at the specified index.
    `` | `public CSTNode` | `setMeaning(int meaning)` Sets the meaning for this node (and its root Token).
    `` | `public abstract int` | `size()` Returns the number of elements in the node (including root).
    `` | `public String` | `toString()` Formats the node as a `String` and returns it.
    `` | `public void` | `write(PrintWriter writer)` Formats the node and writes it to the specified `Writer`.
    `` | `protected void` | `write(PrintWriter writer, String indent)` Formats the node and writes it to the specified `Writer`.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### public CSTNode add(CSTNode element)

      Adds an element to the node. Returns the element for convenience. Not all nodes support this operation!

    - #### public void addChildrenOf(CSTNode of)

      Adds all children of the specified node to this one. Not all nodes support this operation!

    - #### public abstract Reduction asReduction()

      Creates a `Reduction` from this node. Returns self if the node is already a `Reduction`.

    - #### public boolean canMean(int type)

      Returns true if the node can be coerced to the specified type.

    - #### public int children()

      Returns the number of non-root elements in the node.

    - #### public abstract CSTNode get(int index)

      Returns the specified element, or null.

    - #### public CSTNode get(int index, boolean safe)

      Returns the specified element, or Token.NULL if safe is set and the specified element is null (or doesn't exist).

    - #### public String getDescription()

      Returns a description of the node.

    - #### public int getMeaning()

      Returns the meaning of this node. If the node isEmpty(), returns the type of Token.NULL.

    - #### public int getMeaningAs(int[] types)

      Returns the first matching meaning of the specified types. Returns Types.UNKNOWN if there are no matches.

    - #### public abstract Token getRoot()

      Returns the root of the node. By convention, all nodes have a Token as the first element (or root), which indicates the type of the node. May return null if the node `isEmpty()`.

    - #### public Token getRoot(boolean safe)

      Returns the root of the node, the Token that indicates its type. Returns a Token.NULL if safe and the actual root is null.

    - #### public String getRootText()

      Returns the text of the root. Uses `getRoot(true)` to get the root, so you will only receive null in return if the root token returns it.

    - #### public int getStartColumn()

      Returns the starting column of the node. Returns -1 if not known.

    - #### public int getStartLine()

      Returns the starting line of the node. Returns -1 if not known.

    - #### public int getType()

      Returns the actual type of the node. If the node isEmpty(), returns the type of Token.NULL.

    - #### public boolean hasChildren()

      Returns true if the node has any non-root elements.

    - #### public boolean isA(int type)

      Returns true if the node's meaning matches the specified type.

    - #### public boolean isAllOf(int[] types)

      Returns true if the node's meaning matches all of the specified types.

    - #### public boolean isAnExpression()

      Returns true if the node is a complete expression.

    - #### public boolean isEmpty()

      Returns true if the node is completely empty (no root, even).

    - #### public boolean isOneOf(int[] types)

      Returns true if the node's meaning matches any of the specified types.

    - #### public void markAsExpression()

      Marks the node a complete expression. Not all nodes support this operation!

    - #### public CSTNode set(int index, CSTNode element)

      Sets an element node in at the specified index. Returns the element for convenience. Not all nodes support this operation!

    - #### public CSTNode setMeaning(int meaning)

      Sets the meaning for this node (and its root Token). Not valid if the node isEmpty(). Returns the node, for convenience.

    - #### public abstract int size()

      Returns the number of elements in the node (including root).

    - #### @Override
      public String toString()

      Formats the node as a `String` and returns it.

    - #### public void write(PrintWriter writer)

      Formats the node and writes it to the specified `Writer`.

    - #### protected void write(PrintWriter writer, String indent)

      Formats the node and writes it to the specified `Writer`. The indent is prepended to each output line, and is increased for each recursion.