Package: org.apache.groovy.ast.tools

## [Java] Class ExpressionUtils

- org.apache.groovy.ast.tools.ExpressionUtils

-     public final class ExpressionUtils
      extends Object

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static boolean` | `isNullConstant(Expression expr)`
    `` | `public static boolean` | `isNumberOrArrayOfNumber(ClassNode targetType, boolean recurse)` Determine if a type is derived from Number (or array thereof).
    `` | `public static boolean` | `isSuperExpression(Expression expression)`
    `` | `public static boolean` | `isThisExpression(Expression expression)`
    `` | `public static boolean` | `isThisOrSuper(Expression expression)`
    `` | `public static boolean` | `isTypeOrArrayOfType(ClassNode targetType, ClassNode type, boolean recurse)` Determine if a type matches another type (or array thereof).
    `` | `public static ConstantExpression` | `transformBinaryConstantExpression(BinaryExpression be, ClassNode targetType)` Turns expressions of the form ConstantExpression(40) + ConstantExpression(2) into the simplified ConstantExpression(42) at compile time.
    `` | `public static Expression` | `transformInlineConstants(Expression exp, ClassNode attrType)` Converts simple expressions of constants into pre-evaluated simple constants.
    `` | `public static Expression` | `transformInlineConstants(Expression exp)` The attribute values of annotations must be primitive, String or Enum constants.
    `` | `public static Expression` | `transformListOfConstants(ListExpression origList, ClassNode attrType)` Given a list of constants, transform each item in the list.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Method Detail

    - #### public static boolean isNullConstant(Expression expr)

    - #### public static boolean isNumberOrArrayOfNumber(ClassNode targetType, boolean recurse)

      Determine if a type is derived from Number (or array thereof).

      Parameters:
        `targetType` - the candidate type
        `recurse` - true if we can have multi-dimension arrays; should be false for annotation member types
      Returns:
        true if the type equals the targetType or array thereof

    - #### public static boolean isSuperExpression(Expression expression)

    - #### public static boolean isThisExpression(Expression expression)

    - #### public static boolean isThisOrSuper(Expression expression)

    - #### public static boolean isTypeOrArrayOfType(ClassNode targetType, ClassNode type, boolean recurse)

      Determine if a type matches another type (or array thereof).

      Parameters:
        `targetType` - the candidate type
        `type` - the type we are checking against
        `recurse` - true if we can have multi-dimension arrays; should be false for annotation member types
      Returns:
        true if the type equals the targetType or array thereof

    - #### public static ConstantExpression transformBinaryConstantExpression(BinaryExpression be, ClassNode targetType)

      Turns expressions of the form ConstantExpression(40) + ConstantExpression(2) into the simplified ConstantExpression(42) at compile time.

      Parameters:
        `be` - the binary expression
        `targetType` - the type of the result
      Returns:
        the transformed expression or the original if no transformation was performed

    - #### public static Expression transformInlineConstants(Expression exp, ClassNode attrType)

      Converts simple expressions of constants into pre-evaluated simple constants. Handles:

      - Property expressions - referencing constants
      - Simple binary expressions - String concatenation and numeric +, -, /, *
      - List expressions - list of constants
      - Variable expressions - referencing constants
      Parameters:
        `exp` - the original expression
        `attrType` - the type that the final constant should be
      Returns:
        the transformed type or the original if no transformation was possible

    - #### public static Expression transformInlineConstants(Expression exp)

      The attribute values of annotations must be primitive, String or Enum constants. In various places, such constants can be seen during type resolution but won't be readily accessible in later phases, e.g. they might be embedded into constructor code. This method transforms constants that would appear in annotations early so they aren't lost. Subsequent processing determines whether they are valid, this method simply retains the constant value as a constant expression.

      Parameters:
        `exp` - the original expression
      Returns:
        the converted expression

    - #### public static Expression transformListOfConstants(ListExpression origList, ClassNode attrType)

      Given a list of constants, transform each item in the list.

      Parameters:
        `origList` - the list to transform
        `attrType` - the target type
      Returns:
        the transformed list or the original if nothing was changed