public class Statement
extends ASTNode
Base class for all statement nodes in the Groovy AST. Provides common functionality for statement labels, statement-level annotations (Groovy-specific source-retention annotations for transform processing), and visitor pattern support. All concrete statement types inherit from this class.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
addStatementAnnotation(AnnotationNode annotation)Attaches a statement-level annotation to this statement. |
|
public void |
addStatementLabel(String label)Adds a label to this statement. |
|
public void |
copyStatementLabels(Statement that)Copies all labels from another statement to this statement. |
|
public List<AnnotationNode> |
getStatementAnnotations()Returns the list of statement-level annotations attached to this statement. |
|
public String |
getStatementLabel()Returns the first label attached to this statement (added last by the parser), or null if no labels are present. |
|
public List<String> |
getStatementLabels()Returns the list of labels attached to this statement, or null if no labels are present. |
|
public boolean |
isEmpty()Returns true if this statement is empty or produces no side effects. |
|
public void |
setStatementLabel(String label)Adds a label to this statement. |
| Methods inherited from class | Name |
|---|---|
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Attaches a statement-level annotation to this statement. These annotations are stored in node metadata and processed by AST transformations.
annotation - the AnnotationNode to attach (never null)Adds a label to this statement. If the statement did not previously have labels, a linked list is created to maintain insertion order for label processing.
label - the label to attach (never null)Copies all labels from another statement to this statement. If the source statement has no labels, no changes are made to this statement.
that - the source Statement to copy labels fromReturns the list of statement-level annotations attached to this statement. These are Groovy-only source-retention annotations that do not appear at the JVM level; they are processed by registered ASTTransformations.
nullReturns the first label attached to this statement (added last by the parser), or null if no labels are present.
Returns the list of labels attached to this statement, or null if no labels are present. Labels enable goto-like functionality in loops via break/continue statements.
Returns true if this statement is empty or produces no side effects. Typically only EmptyStatement returns true.
Adds a label to this statement. If the statement did not previously have labels, a linked list is created. This method is preferred over the deprecated setStatementLabel(String).
label - the label to attach (never null)