public class ClosureExpression
extends Expression
Represents a closure expression such as { statement } or { i -> statement } or
{ i, x, String y -> statement }. A closure is an anonymous function that can capture
local variables from its enclosing scope (closure variables). Closures support zero or more
parameters, with optional type annotations, and are executed in their own variable scope.
| Fields inherited from class | Fields |
|---|---|
class Expression |
EMPTY_ARRAY |
| Constructor and description |
|---|
ClosureExpression(Parameter[] parameters, Statement code)Creates a closure expression with the specified parameters and code body. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public Statement |
getCode()Returns the code statement that represents the body of this closure. |
|
public Parameter[] |
getParameters()Returns the parameter definitions for this closure. |
|
public String |
getText() |
|
public VariableScope |
getVariableScope()Returns the variable scope associated with this closure. |
|
public boolean |
isParameterSpecified()Indicates whether one or more explicit parameters are specified for this closure. |
|
public void |
setCode(Statement code)Sets the code statement for this closure body. |
|
public void |
setVariableScope(VariableScope variableScope)Sets the variable scope for this closure. |
|
public String |
toString() |
|
public Expression |
transformExpression(ExpressionTransformer transformer) |
|
public void |
visit(GroovyCodeVisitor visitor) |
| Methods inherited from class | Name |
|---|---|
class Expression |
getType, setType, transformExpression, transformExpressions, transformExpressions |
class AnnotatedNode |
addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic |
class ASTNode |
copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit |
Returns the code statement that represents the body of this closure. This method can be used to inspect or analyze what actions the closure will perform.
Returns the parameter definitions for this closure.
Returns the variable scope associated with this closure. The variable scope tracks accessible variables within the closure's execution context, including captured variables.
Indicates whether one or more explicit parameters are specified for this closure.
Sets the code statement for this closure body. This method can be used to modify or add additional actions during closure execution, typically during AST transformations.
code - the new Statement representing the closure body; must not be nullSets the variable scope for this closure.
variableScope - the VariableScope to associate with this closure; may be nullCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.