Package: org.codehaus.groovy.syntax

## [Java] Class Reduction

- org.codehaus.groovy.syntax.Reduction

-     public class Reduction
      extends CSTNode

  A syntax reduction produced by the Parser during syntactic analysis. Represents a node in the concrete syntax tree (CST) that contains a root Token and zero or more child CSTNode elements.

  See Also:
    Token
    CSTNode
    Types

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static Reduction` | `EMPTY` | Singleton empty reduction (read-only).

  - ### Constructor Summary

    Constructors
    Constructor and description
    `Reduction(Token root)` Constructs a Reduction with the specified root token.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public CSTNode` | `add(CSTNode element)` Adds an element to the end of this reduction.
    `` | `public Reduction` | `asReduction()` Creates a `Reduction` from this node.
    `` | `public CSTNode` | `get(int index)` Returns the element at the specified index, or `null` if the index is out of bounds.
    `` | `public Token` | `getRoot()` Returns the root token of this reduction.
    `` | `public boolean` | `isAnExpression()` Returns `true` if this node represents a complete expression.
    `` | `public boolean` | `isEmpty()` Returns `true` if this reduction is completely empty (no elements, not even a root).
    `` | `public void` | `markAsExpression()` Marks this reduction as a complete expression.
    `` | `public static Reduction` | `newContainer()` Creates a new Reduction with Token.NULL as its root.
    `` | `public CSTNode` | `remove(int index)` Removes the element at the specified index.
    `` | `public CSTNode` | `set(int index, CSTNode element)` Sets the element at the specified index.
    `` | `public int` | `size()` Returns the number of elements in this reduction (including the root token).

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class CSTNode` | `add, addChildrenOf, asReduction, canMean, children, get, get, getDescription, getMeaning, getMeaningAs, getRoot, getRoot, getRootText, getStartColumn, getStartLine, getType, hasChildren, isA, isAllOf, isAnExpression, isEmpty, isOneOf, markAsExpression, set, setMeaning, size, toString, write, write`

- - ### Field Detail

    - #### public static final Reduction EMPTY

      Singleton empty reduction (read-only).

  - ### Constructor Detail

    - #### public Reduction(Token root)

      Constructs a Reduction with the specified root token.

      Parameters:
        `root` - the root Token of this reduction

  - ### Method Detail

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

      Adds an element to the end of this reduction.

      Parameters:
        `element` - the element to add
      Returns:
        the added element

    - #### public Reduction asReduction()

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

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

      Returns the element at the specified index, or `null` if the index is out of bounds.

      Parameters:
        `index` - the element index (0 for root)
      Returns:
        the element at the index, or `null` if not found

    - #### public Token getRoot()

      Returns the root token of this reduction. The root is always at index 0 and indicates the syntactic type.

      Returns:
        the root token, or `null` if this reduction is empty

    - #### public boolean isAnExpression()

      Returns `true` if this node represents a complete expression. A reduction is considered an expression if it has the Types.COMPLEX_EXPRESSION meaning or has been explicitly marked as an expression.

      Returns:
        `true` if this is an expression

    - #### public boolean isEmpty()

      Returns `true` if this reduction is completely empty (no elements, not even a root).

      Returns:
        `true` if empty

    - #### public void markAsExpression()

      Marks this reduction as a complete expression. This flag is used by the parser to distinguish complete expressions from partial constructs.

    - #### public static Reduction newContainer()

      Creates a new Reduction with Token.NULL as its root. Useful for creating container nodes with no specific type.

      Returns:
        a new Reduction with a null root token

    - #### public CSTNode remove(int index)

      Removes the element at the specified index. Cannot remove the root element (index 0).

      throws:
        GroovyBugError if trying to remove the root element
      Parameters:
        `index` - the element index (must be > 0)
      Returns:
        the removed element

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

      Sets the element at the specified index. If the index is beyond the current size, intermediate positions are filled with `null`. The root element (index 0) must be a Token.

      throws:
        GroovyBugError if trying to set a non-Token as root, or if operating on EMPTY
      Parameters:
        `index` - the element index
        `element` - the element to set
      Returns:
        the set element

    - #### public int size()

      Returns the number of elements in this reduction (including the root token).

      Returns:
        the number of elements