Package: org.codehaus.groovy.ast.stmt

## [Java] Class Statement

- org.codehaus.groovy.ast.stmt.Statement

-     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

- - ### Methods Summary

    Methods
    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.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ASTNode` | `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

- - ### Method Detail

    - #### 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.

      throws:
        NullPointerException if annotation is null
      Parameters:
        `annotation` - the AnnotationNode to attach (never null)
      Since:
        6.0.0

    - #### 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.

      throws:
        NullPointerException if label is null
      Parameters:
        `label` - the label to attach (never null)

    - #### 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

    - #### 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 ASTTransformations.

      Returns:
        an unmodifiable view of the annotations list, never `null`
      Since:
        6.0.0

    - #### @Deprecated
      public String getStatementLabel()

      Returns the first label attached to this statement (added last by the parser), or null if no labels are present.

      deprecated:
        Use getStatementLabels() instead for access to all labels
      Returns:
        the statement label, or null

    - #### 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

    - #### 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

    - #### 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).

      throws:
        NullPointerException if label is null
      Parameters:
        `label` - the label to attach (never null)