Package: org.codehaus.groovy.ast.stmt

## [Java] Class BlockStatement

- org.codehaus.groovy.ast.stmt.BlockStatement

-     public class BlockStatement
      extends Statement

  Represents a compound statement consisting of an ordered sequence of Statements 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 and description
    `BlockStatement()` Constructs an empty BlockStatement with a new default scope.
    `BlockStatement(Statement[] statements, VariableScope scope)` Constructs a BlockStatement with an array of statements and a variable scope.
    `BlockStatement(List<Statement> statements, VariableScope scope)` Constructs a BlockStatement with a list of statements and a variable scope.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addStatement(Statement statement)` Appends a Statement to this block.
    `` | `public void` | `addStatements(List<Statement> listOfStatements)` Appends all Statements from the provided list to this block.
    `` | `public List<Statement>` | `getStatements()` Returns the list of Statements in this block.
    `` | `public String` | `getText()`
    `` | `public VariableScope` | `getVariableScope()` Returns the VariableScope associated with this block, which contains variable declarations, type information, and scope metadata.
    `` | `public boolean` | `isEmpty()` Checks whether this block contains no statements.
    `` | `public void` | `setVariableScope(VariableScope scope)` Sets the VariableScope for this block.
    `` | `public String` | `toString()`
    `` | `public void` | `visit(GroovyCodeVisitor visitor)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Statement` | `addStatementAnnotation, addStatementLabel, copyStatementLabels, getStatementAnnotations, getStatementLabel, getStatementLabels, isEmpty, setStatementLabel`
    `class ASTNode` | `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

- - ### Constructor Detail

    - #### public BlockStatement()

      Constructs an empty BlockStatement with a new default scope.

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

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

    - #### public void addStatement(Statement statement)

      Appends a Statement to this block.

      Parameters:
        `statement` - the Statement to add; must not be null

    - #### public void addStatements(List<Statement> listOfStatements)

      Appends all Statements from the provided list to this block.

      Parameters:
        `listOfStatements` - a List of Statements to append; must not be null

    - #### public List<Statement> getStatements()

      Returns the list of Statements in this block.

      Returns:
        an unmodifiable view or direct reference to the statements list

    - #### public String getText()

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

    - #### public boolean isEmpty()

      Checks whether this block contains no statements.

      Returns:
        true if the statement list is empty, false otherwise

    - #### public void setVariableScope(VariableScope scope)

      Sets the VariableScope for this block.

      Parameters:
        `scope` - the VariableScope to associate with this block

    - #### public String toString()

    - #### public void visit(GroovyCodeVisitor visitor)