Package org.codehaus.groovy.ast.stmt

# Class BlockStatement

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.stmt.Statement
org.codehaus.groovy.ast.stmt.BlockStatement

All Implemented Interfaces:
  `NodeMetaDataHandler`

public class BlockStatement extends Statement
Represents a compound statement consisting of an ordered sequence of `Statement`s within a specific `VariableScope`. A block statement is the fundamental grouping mechanism in the Groovy AST and is used to represent the body of methods, classes, loops, conditionals, try-catch blocks, and any other scoped code region.

See Also:
  - `Statement`
  - `VariableScope`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BlockStatement()`
  Constructs an empty BlockStatement with a new default scope.
  `BlockStatement(List<Statement> statements, VariableScope scope)`
  Constructs a BlockStatement with a list of statements and a variable scope.
  `BlockStatement(Statement[] statements, VariableScope scope)`
  Constructs a BlockStatement with an array of statements and a variable scope.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addStatement(Statement statement)`
  Appends a `Statement` to this block.
  `void`
  `addStatements(List<Statement> listOfStatements)`
  Appends all `Statement`s from the provided list to this block.
  `List<Statement>`
  `getStatements()`
  Returns the list of `Statement`s in this block.
  `String`
  `getText()`
  Returns a human-readable text representation of this AST node.
  `VariableScope`
  `getVariableScope()`
  Returns the `VariableScope` associated with this block, which contains variable declarations, type information, and scope metadata.
  `boolean`
  `isEmpty()`
  Checks whether this block contains no statements.
  `void`
  `setVariableScope(VariableScope scope)`
  Sets the `VariableScope` for this block.
  `String`
  `toString()`
  `void`
  `visit(GroovyCodeVisitor visitor)`
  Accepts a code visitor for AST traversal and transformation.

  ### Methods inherited from class org.codehaus.groovy.ast.stmt.Statement

  `addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, setStatementLabel`

  ### Methods inherited from class org.codehaus.groovy.ast.ASTNode

  `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition`

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

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

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

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

- ## Constructor Details

  - ### BlockStatement

    public BlockStatement()
    Constructs an empty BlockStatement with a new default scope.

  - ### BlockStatement

    public BlockStatement(Statement[] statements, VariableScope scope)
    Constructs a BlockStatement with an array of statements and a variable scope. The provided array is copied internally; subsequent modifications to the array will not affect this BlockStatement.
    Parameters:
      `statements` - an array of `Statement`s to include in this block; must not be null or a NullPointerException will be raised
      `scope` - the `VariableScope` for this block, typically containing local variable declarations and type information

  - ### BlockStatement

    public BlockStatement(List<Statement> statements, VariableScope scope)
    Constructs a BlockStatement with a list of statements and a variable scope. A reference to the provided list is maintained; modifications to the list after construction will be reflected in this BlockStatement.
    Parameters:
      `statements` - a `List` of `Statement`s to include in this block; pass an empty list, not null, to avoid NullPointerException later
      `scope` - the `VariableScope` for this block, containing variable binding and type metadata

- ## Method Details

  - ### visit

    public void visit(GroovyCodeVisitor visitor)
    Description copied from class: `ASTNode`
    Accepts a code visitor for AST traversal and transformation. Subclasses must implement this method to support visitor pattern-based processing. The visitor pattern enables decoupling of AST structure from processing logic.
    Overrides:
      `visit` in class `ASTNode`
    Parameters:
      `visitor` - the `GroovyCodeVisitor` to process this node

  - ### getStatements

    public List<Statement> getStatements()
    Returns the list of `Statement`s in this block.
    Returns:
      an unmodifiable view or direct reference to the statements list

  - ### addStatement

    public void addStatement(Statement statement)
    Appends a `Statement` to this block.
    Parameters:
      `statement` - the `Statement` to add; must not be null

  - ### addStatements

    public void addStatements(List<Statement> listOfStatements)
    Appends all `Statement`s from the provided list to this block.
    Parameters:
      `listOfStatements` - a `List` of `Statement`s to append; must not be null

  - ### getText

    public String getText()
    Description copied from class: `ASTNode`
    Returns a human-readable text representation of this AST node. Used for debugging and error messages. Default implementation returns a message indicating the representation is not yet implemented for this node type.
    Overrides:
      `getText` in class `ASTNode`
    Returns:
      text representation of this node, or placeholder for unimplemented types

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### isEmpty

    public boolean isEmpty()
    Checks whether this block contains no statements.
    Overrides:
      `isEmpty` in class `Statement`
    Returns:
      true if the statement list is empty, false otherwise

  - ### getVariableScope

    public VariableScope getVariableScope()
    Returns the `VariableScope` associated with this block, which contains variable declarations, type information, and scope metadata.
    Returns:
      the `VariableScope` for this block

  - ### setVariableScope

    public void setVariableScope(VariableScope scope)
    Sets the `VariableScope` for this block.
    Parameters:
      `scope` - the `VariableScope` to associate with this block