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:
| 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. |
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.
other - the source node to copy metadata fromReturns 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 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 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 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 metadata map for this node. Metadata stores arbitrary phase-specific information attached during compilation. Returns null if no metadata has been set.
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.
Sets the starting column number for this AST node in the source file. Column numbers are 0-indexed. Use -1 to indicate unavailable position.
columnNumber - the starting column number to setSets 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).
lastColumnNumber - the ending column number to setSets 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).
lastLineNumber - the ending line number to setSets the starting line number for this AST node in the source file. Line numbers are 1-indexed. Use -1 to indicate unavailable position.
lineNumber - the starting line number to setSets the metadata map for this node. Replaces any existing metadata. Metadata stores arbitrary phase-specific information for inter-phase communication during compilation.
metaDataMap - the metadata map to setSets 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.
node - the reference node providing position informationAccepts 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.
visitor - the GroovyCodeVisitor to process this node