Top Fields Constructors Methods
org.apache.groovy.ast.tools

public final Class ExpressionUtils

extends Object
Class Inheritance
Imports
org.codehaus.groovy.ast.ClassHelper, .ClassNode, .FieldNode, org.codehaus.groovy.ast.expr.BinaryExpression, .ClassExpression, .ConstantExpression, .Expression, .ListExpression, .PropertyExpression, .VariableExpression, org.codehaus.groovy.runtime.DefaultGroovyMethods, org.codehaus.groovy.runtime.typehandling.NumberMath, java.lang.reflect.Field, .Modifier, java.util.Arrays

Field Summary

Modifier and TypeField and Description
private static final int[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static ConstantExpression
configure(final Expression origX, final ConstantExpression newX)

private static Expression
public static boolean
public static boolean

Returns:

true if the type equals the targetType or array thereof
isNumberOrArrayOfNumber
(final ClassNode
the candidate type
targetType
,
final boolean
true if we can have multi-dimension arrays; should be false for annotation member types
recurse
)

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

public static boolean
isSuperExpression(final Expression expression)

public static boolean
isThisExpression(final Expression expression)

public static boolean
isThisOrSuper(final Expression expression)

public static boolean

Returns:

true if the type equals the targetType or array thereof
isTypeOrArrayOfType
(final ClassNode
the candidate type
targetType
,
final ClassNode
the type we are checking against
type
,
final boolean
true if we can have multi-dimension arrays; should be false for annotation member types
recurse
)

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

private static Number
public static ConstantExpression

Returns:

the transformed expression or the original if no transformation was performed
transformBinaryConstantExpression
(final BinaryExpression
the binary expression
be
,
final ClassNode
the type of the result
targetType
)

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

public static Expression

Returns:

the transformed type or the original if no transformation was possible
transformInlineConstants
(final Expression
the original expression
exp
,
final ClassNode
the type that the final constant should be
attrType
)

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

public static Expression

Returns:

the converted expression
transformInlineConstants
(final Expression
the original expression
exp
)

The attribute values of annotations must be primitive, String or Enum constants.

public static Expression

Returns:

the transformed list or the original if nothing was changed
transformListOfConstants
(final ListExpression
the list to transform
origList
,
final ClassNode
the target type
attrType
)

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HANDLED_TYPESback to summary
private static final int[] HANDLED_TYPES

Constructor Detail

ExpressionUtilsback to summary
private ExpressionUtils()

Method Detail

configureback to summary
private static ConstantExpression configure(final Expression origX, final ConstantExpression newX)
findConstantback to summary
private static Expression findConstant(final FieldNode fn)
isNullConstantback to summary
public static boolean isNullConstant(final Expression expr)
isNumberOrArrayOfNumberback to summary
public static boolean isNumberOrArrayOfNumber(final ClassNode targetType, final boolean recurse)

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

Parameters
targetType:ClassNode

the candidate type

recurse:boolean

true if we can have multi-dimension arrays; should be false for annotation member types

Returns:boolean

true if the type equals the targetType or array thereof

isSuperExpressionback to summary
public static boolean isSuperExpression(final Expression expression)
isThisExpressionback to summary
public static boolean isThisExpression(final Expression expression)
isThisOrSuperback to summary
public static boolean isThisOrSuper(final Expression expression)
isTypeOrArrayOfTypeback to summary
public static boolean isTypeOrArrayOfType(final ClassNode targetType, final ClassNode type, final boolean recurse)

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

Parameters
targetType:ClassNode

the candidate type

type:ClassNode

the type we are checking against

recurse:boolean

true if we can have multi-dimension arrays; should be false for annotation member types

Returns:boolean

true if the type equals the targetType or array thereof

safeNumberback to summary
private static Number safeNumber(final ConstantExpression constX)
transformBinaryConstantExpressionback to summary
public static ConstantExpression transformBinaryConstantExpression(final BinaryExpression be, final ClassNode targetType)

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

Parameters
be:BinaryExpression

the binary expression

targetType:ClassNode

the type of the result

Returns:ConstantExpression

the transformed expression or the original if no transformation was performed

transformInlineConstantsback to summary
public static Expression transformInlineConstants(final Expression exp, final 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:Expression

the original expression

attrType:ClassNode

the type that the final constant should be

Returns:Expression

the transformed type or the original if no transformation was possible

transformInlineConstantsback to summary
public static Expression transformInlineConstants(final 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:Expression

the original expression

Returns:Expression

the converted expression

transformListOfConstantsback to summary
public static Expression transformListOfConstants(final ListExpression origList, final ClassNode attrType)

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

Parameters
origList:ListExpression

the list to transform

attrType:ClassNode

the target type

Returns:Expression

the transformed list or the original if nothing was changed