Handy methods when working with the Groovy AST
Type Params | Return Type | Name and description |
---|---|---|
|
static BinaryExpression |
andX(Expression lhv, Expression rhv) |
|
static ArgumentListExpression |
args(Expression... expressions) |
|
static ArgumentListExpression |
args(List<Expression> expressions) |
|
static ArgumentListExpression |
args(Parameter[] parameters) |
|
static ArgumentListExpression |
args(String... names) |
|
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 |
block(VariableScope varScope, Statement... stmts) |
|
static BlockStatement |
block(VariableScope varScope, List<Statement> stmts) |
|
static BlockStatement |
block(Statement... stmts) |
|
static BooleanExpression |
boolX(Expression boolExpr) |
|
static MethodCallExpression |
callSuperX(String methodName, Expression args) |
|
static MethodCallExpression |
callSuperX(String methodName) |
|
static MethodCallExpression |
callThisX(String methodName, Expression args) |
|
static MethodCallExpression |
callThisX(String methodName) |
|
static MethodCallExpression |
callX(Expression receiver, String methodName, Expression args) |
|
static MethodCallExpression |
callX(Expression receiver, Expression method, Expression args) |
|
static MethodCallExpression |
callX(Expression receiver, String methodName) |
|
static StaticMethodCallExpression |
callX(org.codehaus.groovy.ast.ClassNode receiver, String methodName, Expression args) |
|
static StaticMethodCallExpression |
callX(org.codehaus.groovy.ast.ClassNode receiver, String methodName) |
|
static CastExpression |
castX(org.codehaus.groovy.ast.ClassNode type, Expression expression) |
|
static CastExpression |
castX(org.codehaus.groovy.ast.ClassNode type, Expression expression, boolean ignoreAutoboxing) |
|
static CatchStatement |
catchS(Parameter variable, Statement code) |
|
static ListExpression |
classList2args(List<String> args) |
|
static ClassExpression |
classX(org.codehaus.groovy.ast.ClassNode clazz) |
|
static ClassExpression |
classX(Class clazz) |
|
static Parameter[] |
cloneParams(Parameter[] source) |
|
static ClosureExpression |
closureX(Parameter[] params, Statement code) |
|
static ClosureExpression |
closureX(Statement code) |
|
static BinaryExpression |
cmpX(Expression lhv, Expression rhv) Build a binary expression that compares two values |
|
static ConstantExpression |
constX(Object val) |
|
static ConstantExpression |
constX(Object val, boolean keepPrimitive) |
|
static String |
convertASTToSource(ReaderSource readerSource, ASTNode expression) Converts an expression into the String source. |
|
static void |
copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied) Copies all candidateAnnotations with retention policy RetentionPolicy.RUNTIME and RetentionPolicy.CLASS. |
|
static void |
copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied, boolean includeGenerated) Copies all candidateAnnotations with retention policy RetentionPolicy.RUNTIME and RetentionPolicy.CLASS. |
|
static boolean |
copyStatementsWithSuperAdjustment(ClosureExpression pre, BlockStatement body) |
|
static Statement |
createConstructorStatementDefault(FieldNode fNode) |
|
static Statement |
ctorSuperS(Expression args) |
|
static Statement |
ctorSuperS() |
|
static Statement |
ctorThisS(Expression args) |
|
static Statement |
ctorThisS() |
|
static ConstructorCallExpression |
ctorX(org.codehaus.groovy.ast.ClassNode type, Expression args) |
|
static ConstructorCallExpression |
ctorX(org.codehaus.groovy.ast.ClassNode type) |
|
static Statement |
declS(Expression target, Expression init) |
|
static MapEntryExpression |
entryX(Expression key, Expression value) |
|
static BinaryExpression |
eqX(Expression lhv, Expression rhv) |
|
static BooleanExpression |
equalsNullX(Expression argExpr) |
|
static FieldExpression |
fieldX(FieldNode fieldNode) |
|
static FieldExpression |
fieldX(org.codehaus.groovy.ast.ClassNode owner, String fieldName) |
|
static Expression |
findArg(String argName) |
|
static List<org.codehaus.groovy.ast.MethodNode> |
getAllMethods(org.codehaus.groovy.ast.ClassNode type) |
|
static List<PropertyNode> |
getAllProperties(org.codehaus.groovy.ast.ClassNode type) |
|
static List<PropertyNode> |
getAllProperties(Set<String> names, org.codehaus.groovy.ast.ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly) |
|
static List<PropertyNode> |
getAllProperties(Set<String> names, org.codehaus.groovy.ast.ClassNode origType, org.codehaus.groovy.ast.ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly) |
|
static List<PropertyNode> |
getAllProperties(Set<String> names, org.codehaus.groovy.ast.ClassNode origType, org.codehaus.groovy.ast.ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly, boolean reverse, boolean allNames, boolean includeStatic) |
|
static String |
getGetterName(PropertyNode pNode) |
|
static List<String> |
getInstanceNonPropertyFieldNames(org.codehaus.groovy.ast.ClassNode cNode) |
|
static List<FieldNode> |
getInstanceNonPropertyFields(org.codehaus.groovy.ast.ClassNode cNode) |
|
static List<PropertyNode> |
getInstanceProperties(org.codehaus.groovy.ast.ClassNode cNode) |
|
static List<FieldNode> |
getInstancePropertyFields(org.codehaus.groovy.ast.ClassNode cNode) |
|
static List<String> |
getInstancePropertyNames(org.codehaus.groovy.ast.ClassNode cNode) |
|
static Set<org.codehaus.groovy.ast.ClassNode> |
getInterfacesAndSuperInterfaces(org.codehaus.groovy.ast.ClassNode type) |
|
static String |
getSetterName(String name) |
|
static List<FieldNode> |
getSuperNonPropertyFields(org.codehaus.groovy.ast.ClassNode cNode) |
|
static List<FieldNode> |
getSuperPropertyFields(org.codehaus.groovy.ast.ClassNode cNode) |
|
static Expression |
getterThisX(org.codehaus.groovy.ast.ClassNode annotatedNode, PropertyNode pNode) This method is similar to propX(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(org.codehaus.groovy.ast.ClassNode annotatedNode, Expression receiver, PropertyNode pNode) This method is similar to propX(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 BinaryExpression |
hasClassX(Expression instance, org.codehaus.groovy.ast.ClassNode cNode) |
|
static boolean |
hasDeclaredMethod(org.codehaus.groovy.ast.ClassNode cNode, String name, int argsCount) |
|
static BinaryExpression |
hasEqualFieldX(FieldNode fNode, Expression other) |
|
static BinaryExpression |
hasEqualPropertyX(org.codehaus.groovy.ast.ClassNode annotatedNode, PropertyNode pNode, VariableExpression 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 boolean |
inSamePackage(org.codehaus.groovy.ast.ClassNode first, org.codehaus.groovy.ast.ClassNode second) |
|
static boolean |
inSamePackage(Class first, Class second) |
|
static Expression |
indexX(Expression target, Expression value) |
|
static boolean |
isDefaultVisibility(int modifiers) |
|
static BooleanExpression |
isInstanceOfX(Expression objectExpression, org.codehaus.groovy.ast.ClassNode cNode) |
|
static BooleanExpression |
isNullX(Expression expr) |
|
static BooleanExpression |
isOneX(Expression expr) |
|
static boolean |
isOrImplements(org.codehaus.groovy.ast.ClassNode type, org.codehaus.groovy.ast.ClassNode interfaceType) |
|
static BooleanExpression |
isTrueX(Expression argExpr) |
|
static BooleanExpression |
isZeroX(Expression expr) |
|
static ListExpression |
list2args(List args) |
|
static ListExpression |
listX(List<Expression> args) |
|
static VariableExpression |
localVarX(String name) |
|
static VariableExpression |
localVarX(String name, org.codehaus.groovy.ast.ClassNode type) |
|
static BinaryExpression |
ltX(Expression lhv, Expression rhv) |
|
static String |
makeDescriptorWithoutReturnType(org.codehaus.groovy.ast.MethodNode mn) @deprecated use MethodNodeUtils#methodDescriptorWithoutReturnType(MethodNode) instead |
|
static MapExpression |
mapX(List<MapEntryExpression> expressions) |
|
static BinaryExpression |
neX(Expression lhv, Expression rhv) |
|
static BinaryExpression |
notIdenticalX(Expression lhv, Expression rhv) |
|
static BooleanExpression |
notNullX(Expression argExpr) |
|
static NotExpression |
notX(Expression expr) |
|
static ConstantExpression |
nullX() |
|
static BinaryExpression |
orX(Expression lhv, Expression rhv) |
|
static Parameter |
param(org.codehaus.groovy.ast.ClassNode type, String name) |
|
static Parameter |
param(org.codehaus.groovy.ast.ClassNode type, String name, Expression initialExpression) |
|
static Parameter[] |
params(Parameter... params) |
|
static BinaryExpression |
plusX(Expression lhv, Expression rhv) |
|
static PropertyExpression |
propX(Expression owner, String property) |
|
static PropertyExpression |
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 PropertyExpression |
thisPropX(boolean implicit, String property) |
|
static ThrowStatement |
throwS(Expression expr) |
|
static TryCatchStatement |
tryCatchS(Statement tryStatement) |
|
static TryCatchStatement |
tryCatchS(Statement tryStatement, Statement finallyStatement) |
|
static VariableExpression |
varX(String name) |
|
static VariableExpression |
varX(Variable variable) |
|
static VariableExpression |
varX(String name, org.codehaus.groovy.ast.ClassNode type) |
Build a binary expression that compares two values
lhv
- expression for the value to compare fromrhv
- expression for the value value to compare toConverts an expression into the String source. Only some specific expressions like closure expression support this.
readerSource
- a sourceexpression
- an expression. Can't be nullCopies all candidateAnnotations with retention policy RetentionPolicy.RUNTIME and RetentionPolicy.CLASS.
Annotations with GeneratedClosure members are not supported at present.
Copies all candidateAnnotations with retention policy RetentionPolicy.RUNTIME
and RetentionPolicy.CLASS.
Generated annotations will be copied if includeGenerated
is true.
Annotations with GeneratedClosure members are not supported at present.
This method is similar to propX(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.
annotatedNode
- the class node where the property node is accessed frompNode
- the property being accessedThis method is similar to propX(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.
annotatedNode
- the class node where the property node is accessed fromreceiver
- the object having the propertypNode
- the property being accessed