Package org.apache.groovy.ast.tools
Class ExpressionUtils
java.lang.Object
org.apache.groovy.ast.tools.ExpressionUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isNullConstant
(Expression expression) static boolean
isNumberOrArrayOfNumber
(ClassNode targetType, boolean recurse) Determines if a type is derived from Number (or array thereof).static boolean
isSuperExpression
(Expression expression) static boolean
isThisExpression
(Expression expression) static boolean
isThisOrSuper
(Expression expression) static boolean
isTypeOrArrayOfType
(ClassNode targetType, ClassNode type, boolean recurse) Determines if a type matches another type (or array thereof).static ConstantExpression
transformBinaryConstantExpression
(BinaryExpression be, ClassNode targetType) Converts expressions like ConstantExpression(40) + ConstantExpression(2) into the simplified ConstantExpression(42) at compile time.static Expression
Transforms constants that would appear in annotations so they aren't lost.static Expression
transformInlineConstants
(Expression exp, ClassNode attrType) Converts simple expressions of constants into pre-evaluated simple constants.static Expression
transformListOfConstants
(ListExpression origList, ClassNode attrType) Given a list of constants, transform each item in the list.
-
Method Details
-
isNullConstant
-
isThisExpression
-
isSuperExpression
-
isThisOrSuper
-
isTypeOrArrayOfType
Determines if a type matches another type (or array thereof).- Parameters:
targetType
- the candidate typetype
- the type we are checking againstrecurse
- 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
-
isNumberOrArrayOfNumber
Determines if a type is derived from Number (or array thereof).- Parameters:
targetType
- the candidate typerecurse
- 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
-
transformBinaryConstantExpression
public static ConstantExpression transformBinaryConstantExpression(BinaryExpression be, ClassNode targetType) Converts expressions like ConstantExpression(40) + ConstantExpression(2) into the simplified ConstantExpression(42) at compile time.- Parameters:
be
- the binary expressiontargetType
- the type of the result- Returns:
- the transformed expression or the original if no transformation was performed
-
transformInlineConstants
Transforms constants that would appear in annotations so they aren't lost. Subsequent processing determines whether they are valid, this retains the constant value as a constant expression.The attribute values of annotations must be primitive, string, annotation or enumeration 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.
- Parameters:
exp
- the original expression- Returns:
- original or transformed expression
-
transformInlineConstants
Converts simple expressions of constants into pre-evaluated simple constants. Handles:- Property expressions - referencing constants
- Variable expressions - referencing constants
- Typecast expressions - referencing constants
- Binary expressions - string concatenation and numeric +, -, /, *
- List expressions - list of constants
- Parameters:
exp
- the original expressionattrType
- the type that the final constant should be- Returns:
- the transformed type or the original if no transformation was possible
-
transformListOfConstants
Given a list of constants, transform each item in the list.- Parameters:
origList
- the list to transformattrType
- the target type- Returns:
- the transformed list or the original if nothing was changed
-