Class 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:
  • 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 Expressions 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 Expressions 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