public final class ExpressionUtils
extends java.lang.Object
Expression instancesUtils| Constructor and Description |
|---|
ExpressionUtils() |
| Modifier and Type | Method and Description |
|---|---|
BinaryExpression |
asBinaryExpr(Expression expr)
Unsafe cast of a given @{link Expression} to a
BinaryExpression |
<T> T |
asBinaryExpr(Expression expr,
T defaultValue,
Closure<T> func)
Executes a given computation if the expression is of type
BinaryExpression if not, then a default value is
provided |
<U extends Expression> |
getArgumentByIndexAs(ArgumentListExpression args,
java.lang.Integer index,
java.lang.Class<U> asType)
Return the element in the specified index from the
ArgumentListExpression passed as argument as the expected
type. |
<U extends Expression> |
getArgumentByIndexAs(MethodCallExpression methodCallExpr,
java.lang.Integer index,
java.lang.Class<U> asType)
Return the element in the specified index from the
ArgumentListExpression passed as argument as the expected
type. |
ArgumentListExpression |
getArgumentList(MethodCallExpression methodCallExpr)
Given a
MethodCallExpression it returns a list of arguments |
<U extends Expression> |
getFirstArgumentAs(ArgumentListExpression args,
java.lang.Class<U> asType)
Return the first element of the
ArgumentListExpression
passed as parameters as the expected type. |
<U extends Expression> |
getFirstArgumentAs(MethodCallExpression methodCallExpr,
java.lang.Class<U> asType)
Return the first element of the
ArgumentListExpression
passed as parameters as the expected type. |
<U extends Expression> |
getLastArgumentAs(ArgumentListExpression args,
java.lang.Class<U> asType)
Return the last element of the
ArgumentListExpression
passed as parameters as the expected type. |
<U extends Expression> |
getLastArgumentAs(MethodCallExpression methodCallExpr,
java.lang.Class<U> asType)
Return the last element of the
ArgumentListExpression
passed as parameters as the expected type. |
java.lang.String |
getText(Expression expression)
Extracts the String value of a given expression
|
boolean |
hasArguments(MethodCallExpression methodCallExpr)
Given a
MethodCallExpression it returns whether it has arguments
or not |
boolean |
isBinaryExpr(Expression expr)
Checks whether an expression is of type
BinaryExpression |
boolean |
isBinaryExpr(Expression expr,
int operator)
Checks whether an expression is of type
BinaryExpression using
a specific binary operator |
boolean |
isListExpr(Expression expr)
Checks whether an expression is of type
ListExpression |
boolean |
isMethodCallExpr(Expression expr)
Checks whether an expression is of type
MethodCallExpression |
<T> T |
leftExprAs(BinaryExpression binaryExpr,
java.lang.Class<T> type)
From a
BinaryExpression gets the left expression as if
it were of a given type |
<T> T |
rightExprAs(BinaryExpression binaryExpr,
java.lang.Class<T> type)
From a
BinaryExpression gets the right expression as if
it were of a given type |
public boolean hasArguments(MethodCallExpression methodCallExpr)
MethodCallExpression it returns whether it has arguments
or notmethodCallExpr - a method call we want the arguments frompublic ArgumentListExpression getArgumentList(MethodCallExpression methodCallExpr)
MethodCallExpression it returns a list of argumentsmethodCallExpr - a method call we want the arguments fromArgumentListExpressionpublic <U extends Expression> U getFirstArgumentAs(MethodCallExpression methodCallExpr, java.lang.Class<U> asType)
ArgumentListExpression
passed as parameters as the expected type.methodCallExpr - a method call we want the arguments fromasType - the expected typepublic <U extends Expression> U getFirstArgumentAs(ArgumentListExpression args, java.lang.Class<U> asType)
ArgumentListExpression
passed as parameters as the expected type.args - the list of argumentsasType - the expected typepublic <U extends Expression> U getArgumentByIndexAs(MethodCallExpression methodCallExpr, java.lang.Integer index, java.lang.Class<U> asType)
ArgumentListExpression passed as argument as the expected
type.methodCallExpr - a method call we want the arguments fromindex - the index where the expression is locatedasType - the Class of the expected expressionpublic <U extends Expression> U getArgumentByIndexAs(ArgumentListExpression args, java.lang.Integer index, java.lang.Class<U> asType)
ArgumentListExpression passed as argument as the expected
type.args - the argument list expression we want the argument fromindex - the index where the expression is locatedasType - the Class of the expected expressionpublic <U extends Expression> U getLastArgumentAs(MethodCallExpression methodCallExpr, java.lang.Class<U> asType)
ArgumentListExpression
passed as parameters as the expected type.asType - the expected typepublic <U extends Expression> U getLastArgumentAs(ArgumentListExpression args, java.lang.Class<U> asType)
ArgumentListExpression
passed as parameters as the expected type.args - the list of argumentsasType - the expected typepublic boolean isMethodCallExpr(Expression expr)
MethodCallExpressionexpr - the evaluated expressionMethodCallExpressionpublic boolean isListExpr(Expression expr)
ListExpressionexpr - the evaluated expressionListExpressionpublic boolean isBinaryExpr(Expression expr)
BinaryExpressionexpr - the evaluated expressionBinaryExpressionpublic boolean isBinaryExpr(Expression expr, int operator)
BinaryExpression using
a specific binary operatorexpr - the evaluated expressionoperator - int value taken from TypesBinaryExpressionpublic <T> T asBinaryExpr(Expression expr, T defaultValue, Closure<T> func)
BinaryExpression if not, then a default value is
providedexpr - the expression we want to compute overdefaultValue - a value in case the expression is not of type BinaryExpressionfunc - function executed in case expression is not of type BinaryExpressionpublic BinaryExpression asBinaryExpr(Expression expr)
BinaryExpressionexpr - the expression we want to castBinaryExpressionpublic <T> T leftExprAs(BinaryExpression binaryExpr, java.lang.Class<T> type)
BinaryExpression gets the left expression as if
it were of a given typebinaryExpr - the binary expression we want the left expr fromtype - the type we would like to cast the left expr topublic <T> T rightExprAs(BinaryExpression binaryExpr, java.lang.Class<T> type)
BinaryExpression gets the right expression as if
it were of a given typebinaryExpr - the binary expression we want the right expr fromtype - the type we would like to cast the right expr topublic java.lang.String getText(Expression expression)
expression - expression to get text fromString of a given Expression