public final class ExpressionUtils
extends Object
Utility methods for reasoning about Groovy AST expressions.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static boolean |
isNullConstant(Expression expression)Checks whether the supplied expression is the null literal. |
|
public static boolean |
isNumberOrArrayOfNumber(ClassNode targetType, boolean recurse)Determines if a type is derived from Number (or array thereof). |
|
public static boolean |
isSuperExpression(Expression expression)Checks whether the supplied expression references super. |
|
public static boolean |
isThisExpression(Expression expression)Checks whether the supplied expression references this. |
|
public static boolean |
isThisOrSuper(Expression expression)Checks whether the supplied expression references this or super. |
|
public static boolean |
isTypeOrArrayOfType(ClassNode targetType, ClassNode type, boolean recurse)Determines if a type matches another type (or array thereof). |
|
public static ConstantExpression |
transformBinaryConstantExpression(BinaryExpression be, ClassNode targetType)Converts expressions like ConstantExpression(40) + ConstantExpression(2) into the simplified ConstantExpression(42) at compile time. |
|
public static Expression |
transformInlineConstants(Expression exp)Transforms constants that would appear in annotations so they aren't lost. |
|
public static Expression |
transformInlineConstants(Expression exp, ClassNode attrType)Converts simple expressions of constants into pre-evaluated simple constants. |
|
public static Expression |
transformListOfConstants(ListExpression origList, ClassNode attrType)Given a list of constants, transform each item in the list. |
Checks whether the supplied expression is the null literal.
expression - the expression to inspecttrue if the expression is a null constantDetermines if a type is derived from Number (or array thereof).
targetType - the candidate typerecurse - true if we can have multi-dimension arrays; should be false for annotation member types Checks whether the supplied expression references super.
expression - the expression to inspecttrue if the expression is a super reference Checks whether the supplied expression references this.
expression - the expression to inspecttrue if the expression is a this reference Checks whether the supplied expression references this or super.
expression - the expression to inspecttrue if the expression is either a this or super referenceDetermines if a type matches another type (or array thereof).
targetType - the candidate typetype - the type we are checking againstrecurse - true if we can have multi-dimension arrays; should be false for annotation member typesConverts expressions like ConstantExpression(40) + ConstantExpression(2) into the simplified ConstantExpression(42) at compile time.
be - the binary expressiontargetType - the type of the resultTransforms 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.
exp - the original expressionConverts simple expressions of constants into pre-evaluated simple constants. Handles:
exp - the original expressionattrType - the type that the final constant should beGiven a list of constants, transform each item in the list.
origList - the list to transformattrType - the target type