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`, `YieldStatement`

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.

See Also:
  - `Expression`
  - `GroovyCodeVisitor`
  - `BlockStatement`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Statement()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addStatementAnnotation(AnnotationNode annotation)`
  Attaches a statement-level annotation to this statement.
  `void`
  `addStatementLabel(String label)`
  Adds a label to this statement.
  `void`
  `copyStatementLabels(Statement that)`
  Copies all labels from another statement to this statement.
  `List<AnnotationNode>`
  `getStatementAnnotations()`
  Returns the list of statement-level annotations attached to this statement.
  `String`
  `getStatementLabel()`
  Deprecated.
  Use `getStatementLabels()` instead for access to all labels
  `List<String>`
  `getStatementLabels()`
  Returns the list of labels attached to this statement, or null if no labels are present.
  `boolean`
  `isEmpty()`
  Returns true if this statement is empty or produces no side effects.
  `void`
  `setStatementLabel(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, visit`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

- ## Constructor Details

  - ### Statement

    public Statement()

- ## Method Details

  - ### getStatementLabels

    public List<String> 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 public String getStatementLabel()
    Deprecated.
    Use `getStatementLabels()` instead for access to all labels
    Returns 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

    public void setStatementLabel(String label)
    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)`.
    Parameters:
      `label` - the label to attach (never null)
    Throws:
      `NullPointerException` - if label is null

  - ### addStatementLabel

    public void addStatementLabel(String label)
    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

    public void copyStatementLabels(Statement that)
    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 source `Statement` to copy labels from

  - ### getStatementAnnotations

    public List<AnnotationNode> 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 registered `ASTTransformation`s.
    Returns:
      an unmodifiable view of the annotations list, never `null`
    Since:
      6.0.0

  - ### addStatementAnnotation

    public void addStatementAnnotation(AnnotationNode annotation)
    Attaches a statement-level annotation to this statement. These annotations are stored in node metadata and processed by AST transformations.
    Parameters:
      `annotation` - the `AnnotationNode` to 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 only `EmptyStatement` returns true.
    Returns:
      true if this statement is empty