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

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:
  • 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 ASTTransformations.
      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