Package org.codehaus.groovy.ast.tools
Class GeneralUtils
java.lang.Object
org.codehaus.groovy.ast.tools.GeneralUtils
Handy methods when working with the Groovy AST
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic BinaryExpression
andX
(Expression lhv, Expression rhv) static ArgumentListExpression
static ArgumentListExpression
args
(List<Expression> expressions) static ArgumentListExpression
args
(Expression... expressions) static ArgumentListExpression
static Statement
assignS
(Expression target, Expression value) static Expression
assignX
(Expression target, Expression value) static Expression
attrX
(Expression oe, Expression prop) static BinaryExpression
binX
(Expression left, Token token, Expression right) static BlockStatement
static BlockStatement
block
(VariableScope varScope, List<Statement> stmts) static BlockStatement
block
(VariableScope varScope, Statement... stmts) static MethodCallExpression
callSuperX
(String methodName) static MethodCallExpression
callSuperX
(String methodName, Expression args) static MethodCallExpression
static MethodCallExpression
callThisX
(String methodName, Expression args) static StaticMethodCallExpression
static StaticMethodCallExpression
callX
(ClassNode receiver, String methodName, Expression args) static MethodCallExpression
callX
(Expression receiver, String methodName) static MethodCallExpression
callX
(Expression receiver, String methodName, Expression args) static MethodCallExpression
callX
(Expression receiver, Expression method, Expression args) static CastExpression
castX
(ClassNode type, Expression expression) static CastExpression
castX
(ClassNode type, Expression expression, boolean ignoreAutoboxing) static CatchStatement
static ClassExpression
static ClassExpression
static Parameter[]
cloneParams
(Parameter[] source) static ClosureExpression
static ClosureExpression
static BinaryExpression
cmpX
(Expression lhv, Expression rhv) static ConstantExpression
static ConstantExpression
static void
copyAnnotatedNodeAnnotations
(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied) Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIME
andRetentionPolicy.CLASS
.static Statement
static Statement
static Statement
ctorSuperS
(Expression args) static Statement
static Statement
ctorThisS
(Expression args) static ConstructorCallExpression
static ConstructorCallExpression
ctorX
(ClassNode type, Expression args) static Statement
declS
(Expression target, Expression init) static BooleanExpression
equalsNullX
(Expression argExpr) static BinaryExpression
eqX
(Expression lhv, Expression rhv) static FieldExpression
static FieldExpression
static Expression
static List<MethodNode>
getAllMethods
(ClassNode type) static List<PropertyNode>
getAllProperties
(ClassNode type) static String
getGetterName
(PropertyNode pNode) static List<PropertyNode>
getInstanceProperties
(ClassNode cNode) getSuperPropertyFields
(ClassNode cNode) static Expression
getterThisX
(ClassNode annotatedNode, PropertyNode pNode) This method is similar topropX(Expression, Expression)
but will make sure that if the property being accessed is defined inside the classnode provided as a parameter, then a getter call is generated instead of a field access.static Expression
getterX
(ClassNode annotatedNode, Expression receiver, PropertyNode pNode) This method is similar topropX(Expression, Expression)
but will make sure that if the property being accessed is defined inside the classnode provided as a parameter, then a getter call is generated instead of a field access.static Expression
getterX
(ClassNode annotatedNode, PropertyNode pNode) Deprecated.use getterThisX insteadstatic BinaryExpression
hasClassX
(Expression instance, ClassNode cNode) static boolean
hasDeclaredMethod
(ClassNode cNode, String name, int argsCount) static BinaryExpression
hasEqualFieldX
(FieldNode fNode, Expression other) static BinaryExpression
hasEqualPropertyX
(PropertyNode pNode, Expression other) static BooleanExpression
hasSameFieldX
(FieldNode fNode, Expression other) static BooleanExpression
hasSamePropertyX
(PropertyNode pNode, Expression other) static Statement
ifElseS
(Expression cond, Statement thenStmt, Statement elseStmt) static Statement
ifS
(Expression cond, Expression trueExpr) static Statement
ifS
(Expression cond, Statement trueStmt) static Expression
indexX
(Expression target, Expression value) static BooleanExpression
isInstanceOfX
(Expression objectExpression, ClassNode cNode) static BooleanExpression
isOneX
(Expression expr) static boolean
isOrImplements
(ClassNode type, ClassNode interfaceType) static BooleanExpression
isTrueX
(Expression argExpr) static BooleanExpression
isZeroX
(Expression expr) static BinaryExpression
ltX
(Expression lhv, Expression rhv) static String
static BinaryExpression
neX
(Expression lhv, Expression rhv) static BooleanExpression
notNullX
(Expression argExpr) static NotExpression
notX
(Expression expr) static BinaryExpression
orX
(Expression lhv, Expression rhv) static Parameter
static Parameter
param
(ClassNode type, String name, Expression initialExpression) static Parameter[]
static BinaryExpression
plusX
(Expression lhv, Expression rhv) static Expression
propX
(Expression owner, String property) static Expression
propX
(Expression owner, Expression property) static Statement
returnS
(Expression expr) static Statement
safeExpression
(Expression fieldExpr, Expression expression) static BooleanExpression
sameX
(Expression self, Expression other) static Statement
stmt
(Expression expr) static TernaryExpression
ternaryX
(Expression cond, Expression trueExpr, Expression elseExpr) static ThrowStatement
throwS
(Expression expr) static VariableExpression
static VariableExpression
static VariableExpression
-
Field Details
-
ASSIGN
-
EQ
-
NE
-
LT
-
AND
-
OR
-
CMP
-
-
Constructor Details
-
GeneralUtils
public GeneralUtils()
-
-
Method Details
-
andX
-
args
-
args
-
args
-
args
-
assignS
-
assignX
-
attrX
-
binX
-
block
-
block
-
block
-
callSuperX
-
callSuperX
-
callThisX
-
callThisX
-
callX
-
callX
-
callX
-
callX
public static StaticMethodCallExpression callX(ClassNode receiver, String methodName, Expression args) -
callX
-
castX
-
castX
-
classX
-
classX
-
closureX
-
closureX
-
cloneParams
-
cmpX
-
constX
-
constX
-
copyAnnotatedNodeAnnotations
public static void copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied) Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIME
andRetentionPolicy.CLASS
.Annotations with
GeneratedClosure
members are not supported at present. -
createConstructorStatementDefault
-
ctorX
-
ctorX
-
ctorSuperS
-
ctorThisS
-
ctorSuperS
-
ctorThisS
-
declS
-
eqX
-
equalsNullX
-
fieldX
-
fieldX
-
findArg
-
getAllMethods
-
getAllProperties
-
getGetterName
-
getInstanceNonPropertyFields
-
getInstanceProperties
-
getInstancePropertyFields
-
getInterfacesAndSuperInterfaces
-
getSuperNonPropertyFields
-
getSuperPropertyFields
-
hasClassX
-
hasDeclaredMethod
-
hasEqualFieldX
-
hasEqualPropertyX
-
hasSameFieldX
-
hasSamePropertyX
-
ifElseS
-
ifS
-
ifS
-
indexX
-
isInstanceOfX
-
isOneX
-
isOrImplements
-
isTrueX
-
isZeroX
-
ltX
-
makeDescriptorWithoutReturnType
-
neX
-
notNullX
-
notX
-
orX
-
param
-
param
-
params
-
plusX
-
propX
-
propX
-
returnS
-
safeExpression
-
sameX
-
stmt
-
ternaryX
-
varX
-
varX
-
varX
-
throwS
-
catchS
-
getterX
Deprecated.use getterThisX instead -
getterThisX
This method is similar topropX(Expression, Expression)
but will make sure that if the property being accessed is defined inside the classnode provided as a parameter, then a getter call is generated instead of a field access.- Parameters:
annotatedNode
- the class node where the property node is accessed frompNode
- the property being accessed- Returns:
- a method call expression or a property expression
-
getterX
This method is similar topropX(Expression, Expression)
but will make sure that if the property being accessed is defined inside the classnode provided as a parameter, then a getter call is generated instead of a field access.- Parameters:
annotatedNode
- the class node where the property node is accessed fromreceiver
- the object having the propertypNode
- the property being accessed- Returns:
- a method call expression or a property expression
-