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.
| 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. |
| 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) |
| 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 |
Constructs an empty BlockStatement with a new default 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.
statements
- an array of Statements to include in this block; must not be null
or a NullPointerException will be raisedscope
- the VariableScope for this block, typically containing local variable
declarations and type informationConstructs 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.
statements
- a List of Statements to include in this block; pass an empty list,
not null, to avoid NullPointerException laterscope
- the VariableScope for this block, containing variable binding and type metadataAppends a Statement to this block.
statement
- the Statement to add; must not be nullAppends all Statements from the provided list to this block.
Returns the list of Statements in this block.
Returns the VariableScope associated with this block, which contains variable declarations, type information, and scope metadata.
Checks whether this block contains no statements.
Sets the VariableScope for this block.
scope
- the VariableScope to associate with this blockCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.