Package org.codehaus.groovy.ast.expr

# Class Expression

java.lang.Object
org.codehaus.groovy.ast.ASTNode
org.codehaus.groovy.ast.AnnotatedNode
org.codehaus.groovy.ast.expr.Expression

All Implemented Interfaces:
  `GroovydocHolder<AnnotatedNode>`, `NodeMetaDataHandler`

Direct Known Subclasses:
  `AbstractGinqExpression`, `ArrayExpression`, `BinaryExpression`, `BitwiseNegationExpression`, `BooleanExpression`, `BytecodeExpression`, `CastExpression`, `ClassExpression`, `ClosureExpression`, `ConstantExpression`, `ConstructorCallExpression`, `EmptyExpression`, `FieldExpression`, `GStringExpression`, `ListExpression`, `ListOfExpressionsExpression`, `MapEntryExpression`, `MapExpression`, `MethodCallExpression`, `MethodPointerExpression`, `PostfixExpression`, `PrefixExpression`, `PropertyExpression`, `RangeExpression`, `SpreadExpression`, `SpreadMapExpression`, `StaticMethodCallExpression`, `TemporaryVariableExpression`, `TernaryExpression`, `TupleExpression`, `UnaryMinusExpression`, `UnaryPlusExpression`, `VariableExpression`

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
  Modifier and Type
  Field
  Description
  `static final Expression[]`
  `EMPTY_ARRAY`

  ### Fields inherited from interface groovy.lang.groovydoc.GroovydocHolder

  `DOC_COMMENT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Expression()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ClassNode`
  `getType()`
  Returns the type of this expression.
  `void`
  `setType(ClassNode type)`
  Sets the type information for this expression.
  `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.
  `protected <T extends Expression>
  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.

  ### Methods inherited from class org.codehaus.groovy.ast.AnnotatedNode

  `addAnnotation, addAnnotation, addAnnotations, getAnnotations, getAnnotations, getDeclaringClass, getGroovydoc, getInstance, hasNoRealSourcePosition, isSynthetic, setDeclaringClass, setHasNoRealSourcePosition, setSynthetic`

  ### Methods inherited from class org.codehaus.groovy.ast.ASTNode

  `copyNodeMetaData, getColumnNumber, getLastColumnNumber, getLastLineNumber, getLineNumber, getMetaDataMap, getText, setColumnNumber, setLastColumnNumber, setLastLineNumber, setLineNumber, setMetaDataMap, setSourcePosition, visit`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.NodeMetaDataHandler

  `copyNodeMetaData, getNodeMetaData, getNodeMetaData, getNodeMetaData, newMetaDataMap, putNodeMetaData, removeNodeMetaData, setNodeMetaData`

- ## Field Details

  - ### EMPTY_ARRAY

    public static final Expression[] EMPTY_ARRAY

- ## Constructor Details

  - ### Expression

    public Expression()

- ## Method Details

  - ### getType

    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

  - ### setType

    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

  - ### transformExpression

    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)

  - ### transformExpressions

    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 `Expression`s to transform
      `transformer` - the `ExpressionTransformer` to apply
    Returns:
      a new list containing transformed expressions

  - ### transformExpressions

    protected <T extends Expression> 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.
    Type Parameters:
      `T` - the target expression type parameter
    Parameters:
      `expressions` - the list of `Expression`s to transform
      `transformer` - the `ExpressionTransformer` to apply
      `targetType` - the expected type of all transformed expressions
    Returns:
      a new type-safe list of transformed expressions
    Throws:
      `GroovyBugError` - if any transformed expression is not an instance of targetType