Package: org.codehaus.groovy.ast.expr

## [Java] Class Expression

- org.codehaus.groovy.ast.expr.Expression

-     public abstract class Expression
      extends AnnotatedNode

  Base class for all expression nodes in the Groovy AST. Expressions represent values and computations that can be evaluated at runtime, supporting type information and transformation operations. All concrete expression types inherit from this abstract class and must implement the transformExpression(ExpressionTransformer) method for AST transformation support.

  See Also:
    Statement
    ExpressionTransformer
    GroovyCodeVisitor

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static Expression[]` | `EMPTY_ARRAY` |

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public ClassNode` | `getType()` Returns the type of this expression.
    `` | `public void` | `setType(ClassNode type)` Sets the type information for this expression.
    `` | `public abstract Expression` | `transformExpression(ExpressionTransformer transformer)` Transforms this expression and any nested expressions according to the provided transformer.
    `` | `protected List<Expression>` | `transformExpressions(List<? extends Expression> expressions, ExpressionTransformer transformer)` Transforms a list of expressions by applying the provided transformer to each element.
    `<T extends Expression>` | `protected List<T>` | `transformExpressions(List<? extends Expression> expressions, ExpressionTransformer transformer, Class<T> targetType)` Transforms a list of expressions and verifies that all transformed expressions have a specific type.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `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`

- - ### Field Detail

    - #### public static final Expression[] EMPTY_ARRAY

  - ### Method Detail

    - #### public ClassNode getType()

      Returns the type of this expression. If the type has not been explicitly set, this method returns a dynamic type to support dynamic typing.

      Returns:
        the ClassNode representing this expression's type

    - #### public void setType(ClassNode type)

      Sets the type information for this expression. Used during type checking and compilation phases to associate a specific type with this expression result.

      Parameters:
        `type` - the ClassNode representing this expression's type

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

      Transforms this expression and any nested expressions according to the provided transformer. This method is called during AST transformation phases and must recursively transform any nested expressions to support full AST tree transformation.

      Parameters:
        `transformer` - the ExpressionTransformer to apply
      Returns:
        a transformed copy of this expression (or this expression itself if no changes are needed)

    - #### protected List<Expression> transformExpressions(List<? extends Expression> expressions, ExpressionTransformer transformer)

      Transforms a list of expressions by applying the provided transformer to each element. Handles null expressions gracefully by including them in the result.

      Parameters:
        `expressions` - the list of Expressions to transform
        `transformer` - the ExpressionTransformer to apply
      Returns:
        a new list containing transformed expressions

    - #### <T extends Expression> protected List<T> transformExpressions(List<? extends Expression> expressions, ExpressionTransformer transformer, Class<T> targetType)

      Transforms a list of expressions and verifies that all transformed expressions have a specific type. This variant provides type safety during transformations by enforcing that transformed expressions conform to a target type. Throws GroovyBugError if any expression has an incompatible type.

      throws:
        GroovyBugError if any transformed expression is not an instance of targetType
      Parameters:
        `expressions` - the list of Expressions to transform
        `transformer` - the ExpressionTransformer to apply
        `targetType` - the expected type of all transformed expressions
      Type Parameters:
        `T` - the target expression type parameter
      Returns:
        a new type-safe list of transformed expressions