Package: org.codehaus.groovy.ast

## [Java] Class ASTNode

- org.codehaus.groovy.ast.ASTNode

- All Implemented Interfaces and Traits:
    NodeMetaDataHandler

      public class ASTNode
      extends Object
      implements NodeMetaDataHandler

  Base class for any AST node. This class supports basic information used in all nodes of the AST:

  - line and column number information. Usually a node represents a certain area in a text file determined by a starting position and an ending position. For nodes that do not represent this, this information will be -1. A node can also be configured in its line/col information using another node through setSourcePosition(otherNode).
  - every node can store meta data. A phase operation or transform can use this to transport arbitrary information to another phase operation or transform. The only requirement is that the other phase operation or transform runs after the part storing the information. If the information transport is done it is strongly recommended to remove that meta data.
  - a text representation of this node trough getText(). This was in the past used for assertion messages. Since the usage of power asserts this method will not be called for this purpose anymore and might be removed in future versions of Groovy

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `copyNodeMetaData(ASTNode other)` Copies all node metadata from another ASTNode.
    `` | `public int` | `getColumnNumber()` Returns the column number where this AST node begins in the source file.
    `` | `public int` | `getLastColumnNumber()` Returns the column number where this AST node ends in the source file.
    `` | `public int` | `getLastLineNumber()` Returns the line number where this AST node ends in the source file.
    `` | `public int` | `getLineNumber()` Returns the line number where this AST node begins in the source file.
    `` | `public Map<?, ?>` | `getMetaDataMap()` Returns the metadata map for this node.
    `` | `public String` | `getText()` Returns a human-readable text representation of this AST node.
    `` | `public void` | `setColumnNumber(int columnNumber)` Sets the starting column number for this AST node in the source file.
    `` | `public void` | `setLastColumnNumber(int lastColumnNumber)` Sets the ending column number for this AST node in the source file.
    `` | `public void` | `setLastLineNumber(int lastLineNumber)` Sets the ending line number for this AST node in the source file.
    `` | `public void` | `setLineNumber(int lineNumber)` Sets the starting line number for this AST node in the source file.
    `` | `public void` | `setMetaDataMap(Map<?, ?> metaDataMap)` Sets the metadata map for this node.
    `` | `public void` | `setSourcePosition(ASTNode node)` Sets the source position information using another ASTNode as reference.
    `` | `public void` | `visit(GroovyCodeVisitor visitor)` Accepts a code visitor for AST traversal and transformation.

  - ### Inherited Methods Summary

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

- - ### Method Detail

    - #### public void copyNodeMetaData(ASTNode other)

      Copies all node metadata from another ASTNode. Metadata is arbitrary information attached by compiler phases or AST transforms for inter-phase communication. This method performs a deep metadata transfer.

      Parameters:
        `other` - the source node to copy metadata from

    - #### public int getColumnNumber()

      Returns the column number where this AST node begins in the source file. Column numbers are 0-indexed. Returns -1 if position information is unavailable (for synthetic or generated nodes).

      Returns:
        the starting column number, or -1 if not available

    - #### public int getLastColumnNumber()

      Returns the column number where this AST node ends in the source file. Column numbers are 0-indexed. Returns -1 if position information is unavailable. The end position is typically exclusive (one past the last character).

      Returns:
        the ending column number, or -1 if not available

    - #### public int getLastLineNumber()

      Returns the line number where this AST node ends in the source file. Line numbers start from 1. Returns -1 if position information is unavailable. The end position is typically inclusive (last line of the node's span).

      Returns:
        the ending line number, or -1 if not available

    - #### public int getLineNumber()

      Returns the line number where this AST node begins in the source file. Line numbers start from 1. Returns -1 if position information is not available (for synthetic or generated nodes).

      Returns:
        the starting line number, or -1 if not available

    - #### public Map<?, ?> getMetaDataMap()

      Returns the metadata map for this node. Metadata stores arbitrary phase-specific information attached during compilation. Returns null if no metadata has been set.

      Returns:
        the metadata map, or null if empty

    - #### public String getText()

      Returns a human-readable text representation of this AST node. Used for debugging and error messages. Default implementation returns a message indicating the representation is not yet implemented for this node type.

      Returns:
        text representation of this node, or placeholder for unimplemented types

    - #### public void setColumnNumber(int columnNumber)

      Sets the starting column number for this AST node in the source file. Column numbers are 0-indexed. Use -1 to indicate unavailable position.

      Parameters:
        `columnNumber` - the starting column number to set

    - #### public void setLastColumnNumber(int lastColumnNumber)

      Sets the ending column number for this AST node in the source file. Column numbers are 0-indexed. Use -1 to indicate unavailable position. The end position should typically be exclusive (one past the last character).

      Parameters:
        `lastColumnNumber` - the ending column number to set

    - #### public void setLastLineNumber(int lastLineNumber)

      Sets the ending line number for this AST node in the source file. Line numbers are 1-indexed. Use -1 to indicate unavailable position. The end position should typically be inclusive (last line of the node's span).

      Parameters:
        `lastLineNumber` - the ending line number to set

    - #### public void setLineNumber(int lineNumber)

      Sets the starting line number for this AST node in the source file. Line numbers are 1-indexed. Use -1 to indicate unavailable position.

      Parameters:
        `lineNumber` - the starting line number to set

    - #### public void setMetaDataMap(Map<?, ?> metaDataMap)

      Sets the metadata map for this node. Replaces any existing metadata. Metadata stores arbitrary phase-specific information for inter-phase communication during compilation.

      Parameters:
        `metaDataMap` - the metadata map to set

    - #### public void setSourcePosition(ASTNode node)

      Sets the source position information using another ASTNode as reference. Copies all position data (line/column start and end) from the source node, enabling consistent source location tracking for synthetic or transformed nodes.

      Parameters:
        `node` - the reference node providing position information

    - #### public void visit(GroovyCodeVisitor visitor)

      Accepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.

      throws:
        RuntimeException if visitor pattern support is not implemented for this node type
      Parameters:
        `visitor` - the GroovyCodeVisitor to process this node