Package org.codehaus.groovy.ast.stmt
Class Statement
java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.stmt.Statement
- All Implemented Interfaces:
NodeMetaDataHandler
- Direct Known Subclasses:
AssertStatement,BlockStatement,BreakStatement,BytecodeSequence,CaseStatement,CatchStatement,ContinueStatement,DoWhileStatement,EmptyStatement,ExpressionStatement,ForStatement,IfStatement,ReturnStatement,SwitchStatement,SynchronizedStatement,ThrowStatement,TryCatchStatement,WhileStatement
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.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStatementAnnotation(AnnotationNode annotation) Attaches a statement-level annotation to this statement.voidaddStatementLabel(String label) Adds a label to this statement.voidcopyStatementLabels(Statement that) Copies all labels from another statement to this statement.Returns the list of statement-level annotations attached to this statement.Deprecated.Returns the list of labels attached to this statement, or null if no labels are present.booleanisEmpty()Returns true if this statement is empty or produces no side effects.voidsetStatementLabel(String label) Adds a label to this statement.Methods inherited from class org.codehaus.groovy.ast.ASTNode
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visitMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler
copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData
-
Constructor Details
-
Statement
public Statement()
-
-
Method Details
-
getStatementLabels
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:
- a list of label strings, or null if no labels are attached
-
getStatementLabel
Deprecated.UsegetStatementLabels()instead for access to all labelsReturns the first label attached to this statement (added last by the parser), or null if no labels are present.- Returns:
- the statement label, or null
-
setStatementLabel
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 deprecatedsetStatementLabel(String).- Parameters:
label- the label to attach (never null)- Throws:
NullPointerException- if label is null
-
addStatementLabel
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.- Parameters:
label- the label to attach (never null)- Throws:
NullPointerException- if label is null
-
copyStatementLabels
Copies all labels from another statement to this statement. If the source statement has no labels, no changes are made to this statement.- Parameters:
that- the sourceStatementto copy labels from
-
getStatementAnnotations
Returns 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 registeredASTTransformations.- Returns:
- an unmodifiable view of the annotations list, never
null - Since:
- 6.0.0
-
addStatementAnnotation
Attaches a statement-level annotation to this statement. These annotations are stored in node metadata and processed by AST transformations.- Parameters:
annotation- theAnnotationNodeto attach (never null)- Throws:
NullPointerException- if annotation is null- Since:
- 6.0.0
-
isEmpty
public boolean isEmpty()Returns true if this statement is empty or produces no side effects. Typically onlyEmptyStatementreturns true.- Returns:
- true if this statement is empty
-
getStatementLabels()instead for access to all labels