Package: org.codehaus.groovy.ast.expr

## [Java] Class ClosureExpression

- org.codehaus.groovy.ast.expr.ClosureExpression

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

  See Also:
    Expression
    Parameter
    VariableScope
    MethodCallExpression

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class Expression` | `EMPTY_ARRAY`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ClosureExpression(Parameter[] parameters, Statement code)` Creates a closure expression with the specified parameters and code body.

  - ### Methods Summary

    Methods
    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)`

  - ### Inherited Methods Summary

    Inherited Methods
    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`

- - ### Constructor Detail

    - #### public ClosureExpression(Parameter[] parameters, Statement code)

      Creates a closure expression with the specified parameters and code body.

      Parameters:
        `parameters` - an array of Parameter definitions for this closure, or null if the closure has no explicit parameters (allowing implicit it parameter); may be empty for a closure with no parameters
        `code` - the Statement representing the body of the closure; must not be null

  - ### Method Detail

    - #### public Statement getCode()

      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 code Statement representing the closure body; may be null

    - #### public Parameter[] getParameters()

      Returns the parameter definitions for this closure.

      Returns:
        an array of Parameter definitions, empty if no explicit parameters are provided (allowing implicit it parameter), or null if the closure has no parameters at all

    - #### public String getText()

    - #### public VariableScope getVariableScope()

      Returns the variable scope associated with this closure. The variable scope tracks accessible variables within the closure's execution context, including captured variables.

      Returns:
        the VariableScope for this closure; may be null if not yet initialized

    - #### public boolean isParameterSpecified()

      Indicates whether one or more explicit parameters are specified for this closure.

      Returns:
        true if explicit parameters are present; false if no explicit parameters are specified (in which case an implicit 'it' parameter may be available)

    - #### public void setCode(Statement code)

      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.

      Parameters:
        `code` - the new Statement representing the closure body; must not be null

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

      Sets the variable scope for this closure.

      Parameters:
        `variableScope` - the VariableScope to associate with this closure; may be null

    - #### public String toString()

    - #### public Expression transformExpression(ExpressionTransformer transformer)

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