Package org.codehaus.groovy.ast.tools
Class GeneralUtils
- java.lang.Object
-
- org.codehaus.groovy.ast.tools.GeneralUtils
-
public class GeneralUtils extends Object
Handy methods when working with the Groovy AST
-
-
Constructor Summary
Constructors Constructor Description GeneralUtils()
-
Method Summary
-
-
-
Method Detail
-
andX
public static BinaryExpression andX(Expression lhv, Expression rhv)
-
args
public static ArgumentListExpression args(Expression... expressions)
-
args
public static ArgumentListExpression args(List<Expression> expressions)
-
args
public static ArgumentListExpression args(Parameter[] parameters)
-
args
public static ArgumentListExpression args(String... names)
-
assignNullS
public static Statement assignNullS(Expression target)
-
assignS
public static Statement assignS(Expression target, Expression value)
-
assignX
public static Expression assignX(Expression target, Expression value)
-
attrX
public static Expression attrX(Expression oe, Expression prop)
-
binX
public static BinaryExpression binX(Expression left, Token token, Expression right)
-
block
public static BlockStatement block(VariableScope scope, Statement... stmts)
-
block
public static BlockStatement block(VariableScope scope, List<Statement> stmts)
-
block
public static BlockStatement block(Statement... stmts)
-
boolX
public static BooleanExpression boolX(Expression expr)
-
callSuperX
public static MethodCallExpression callSuperX(String methodName)
-
callSuperX
public static MethodCallExpression callSuperX(String methodName, Expression args)
-
callThisX
public static MethodCallExpression callThisX(String methodName)
-
callThisX
public static MethodCallExpression callThisX(String methodName, Expression args)
-
callX
public static MethodCallExpression callX(Expression receiver, String methodName)
-
callX
public static MethodCallExpression callX(Expression receiver, String methodName, Expression args)
-
callX
public static MethodCallExpression callX(Expression receiver, Expression method, Expression args)
-
callX
public static StaticMethodCallExpression callX(ClassNode receiver, String methodName)
-
callX
public static StaticMethodCallExpression callX(ClassNode receiver, String methodName, Expression args)
-
castX
public static CastExpression castX(ClassNode type, Expression expression)
-
castX
public static CastExpression castX(ClassNode type, Expression expression, boolean ignoreAutoboxing)
-
catchS
public static CatchStatement catchS(Parameter variable, Statement code)
-
classX
public static ClassExpression classX(ClassNode clazz)
-
classX
public static ClassExpression classX(Class clazz)
-
closureX
public static ClosureExpression closureX(Parameter[] params, Statement code)
-
closureX
public static ClosureExpression closureX(Statement code)
-
cmpX
public static BinaryExpression cmpX(Expression lhv, Expression rhv)
Builds a binary expression that compares two values.- Parameters:
lhv
- expression for the value to compare fromrhv
- expression for the value value to compare to- Returns:
- the expression comparing two values
-
constX
public static ConstantExpression constX(Object val)
-
constX
public static ConstantExpression constX(Object val, boolean keepPrimitive)
-
ctorX
public static ConstructorCallExpression ctorX(ClassNode type, Expression args)
-
ctorX
public static ConstructorCallExpression ctorX(ClassNode type)
-
ctorSuperS
public static Statement ctorSuperS()
-
ctorSuperS
public static Statement ctorSuperS(Expression args)
-
ctorSuperX
public static ConstructorCallExpression ctorSuperX()
-
ctorSuperX
public static ConstructorCallExpression ctorSuperX(Expression args)
-
ctorThisS
public static Statement ctorThisS()
-
ctorThisS
public static Statement ctorThisS(Expression args)
-
ctorThisX
public static ConstructorCallExpression ctorThisX()
-
ctorThisX
public static ConstructorCallExpression ctorThisX(Expression args)
-
declS
public static Statement declS(Expression target, Expression init)
-
declX
public static DeclarationExpression declX(Expression target, Expression init)
-
entryX
public static MapEntryExpression entryX(Expression key, Expression value)
-
eqX
public static BinaryExpression eqX(Expression lhv, Expression rhv)
-
equalsNullX
public static BooleanExpression equalsNullX(Expression argExpr)
-
fieldX
public static FieldExpression fieldX(FieldNode fieldNode)
-
fieldX
public static FieldExpression fieldX(ClassNode owner, String fieldName)
-
findArg
public static Expression findArg(String argName)
-
getAllMethods
public static List<MethodNode> getAllMethods(ClassNode type)
-
getAllProperties
public static List<PropertyNode> getAllProperties(ClassNode type)
-
getInstanceNonPropertyFields
public static List<FieldNode> getInstanceNonPropertyFields(ClassNode cNode)
-
getInstanceNonPropertyFieldNames
public static List<String> getInstanceNonPropertyFieldNames(ClassNode cNode)
-
getInstanceProperties
public static List<PropertyNode> getInstanceProperties(ClassNode cNode)
-
getInterfacesAndSuperInterfaces
public static Set<ClassNode> getInterfacesAndSuperInterfaces(ClassNode cNode)
-
getAllProperties
public static List<PropertyNode> getAllProperties(Set<String> names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly)
-
getAllProperties
public static List<PropertyNode> getAllProperties(Set<String> names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly)
-
getAllProperties
public static List<PropertyNode> getAllProperties(Set<String> names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly, boolean reverse, boolean allNames, boolean includeStatic)
-
getterThisX
public 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.- 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
public 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.- 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
-
hasClassX
public static BinaryExpression hasClassX(Expression instance, ClassNode cNode)
-
hasEqualFieldX
public static BinaryExpression hasEqualFieldX(FieldNode fNode, Expression other)
-
hasEqualPropertyX
public static BinaryExpression hasEqualPropertyX(ClassNode annotatedNode, PropertyNode pNode, VariableExpression other)
-
hasEqualPropertyX
@Deprecated public static BinaryExpression hasEqualPropertyX(PropertyNode pNode, Expression other)
Deprecated.
-
hasSameFieldX
public static BooleanExpression hasSameFieldX(FieldNode fNode, Expression other)
-
hasSamePropertyX
public static BooleanExpression hasSamePropertyX(PropertyNode pNode, Expression other)
-
ifElseS$$bridge
@Deprecated public static Statement ifElseS$$bridge(Expression cond, Statement thenStmt, Statement elseStmt)
Deprecated.
-
ifElseS
public static IfStatement ifElseS(Expression cond, Statement thenStmt, Statement elseStmt)
-
ifS$$bridge
@Deprecated public static Statement ifS$$bridge(Expression cond, Expression trueExpr)
Deprecated.
-
ifS
public static IfStatement ifS(Expression cond, Expression trueExpr)
-
ifS$$bridge
@Deprecated public static Statement ifS$$bridge(Expression cond, Statement trueStmt)
Deprecated.
-
ifS
public static IfStatement ifS(Expression cond, Statement trueStmt)
-
indexX
public static Expression indexX(Expression target, Expression value)
-
isInstanceOfX
public static BooleanExpression isInstanceOfX(Expression objectExpression, ClassNode cNode)
-
isNullX
public static BooleanExpression isNullX(Expression expr)
Alias forequalsNullX(Expression)
-
isOneX
public static BooleanExpression isOneX(Expression expr)
-
isTrueX
public static BooleanExpression isTrueX(Expression argExpr)
-
isZeroX
public static BooleanExpression isZeroX(Expression expr)
-
listX
public static ListExpression listX(List<Expression> args)
-
list2args
public static ListExpression list2args(List args)
-
classList2args
public static ListExpression classList2args(List<String> args)
-
localVarX
public static VariableExpression localVarX(String name)
-
localVarX
public static VariableExpression localVarX(String name, ClassNode type)
-
ltX
public static BinaryExpression ltX(Expression lhv, Expression rhv)
-
mapX
public static MapExpression mapX(List<MapEntryExpression> expressions)
-
neX
public static BinaryExpression neX(Expression lhv, Expression rhv)
-
notNullX
public static BooleanExpression notNullX(Expression argExpr)
-
notX
public static NotExpression notX(Expression expr)
-
nullX
public static ConstantExpression nullX()
-
orX
public static BinaryExpression orX(Expression lhv, Expression rhv)
-
param
public static Parameter param(ClassNode type, String name, Expression initialExpression)
-
plusX
public static BinaryExpression plusX(Expression lhv, Expression rhv)
-
propX
public static Expression propX(Expression owner, String property)
-
propX
public static Expression propX(Expression owner, Expression property)
-
propX
public static PropertyExpression propX(Expression owner, Expression property, boolean safe)
-
returnS
public static Statement returnS(Expression expr)
-
safeExpression
public static Statement safeExpression(Expression fieldExpr, Expression expression)
-
sameX
public static BooleanExpression sameX(Expression self, Expression other)
-
stmt
public static Statement stmt(Expression expr)
-
ternaryX
public static TernaryExpression ternaryX(Expression cond, Expression trueExpr, Expression elseExpr)
-
thisPropX
public static PropertyExpression thisPropX(boolean implicit, String property)
-
throwS
public static ThrowStatement throwS(Expression expr)
-
tryCatchS
public static TryCatchStatement tryCatchS(Statement tryStatement)
-
tryCatchS
public static TryCatchStatement tryCatchS(Statement tryStatement, Statement finallyStatement)
-
tryCatchS
public static TryCatchStatement tryCatchS(Statement tryStatement, Statement finallyStatement, CatchStatement... catchStatements)
-
varX
public static VariableExpression varX(String name)
-
varX
public static VariableExpression varX(Variable variable)
-
varX
public static VariableExpression varX(String name, ClassNode type)
-
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.
-
copyAnnotatedNodeAnnotations
public static void copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied, boolean includeGenerated)
Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIME
andRetentionPolicy.CLASS
.Generated
annotations will be copied ifincludeGenerated
is true.Annotations with
GeneratedClosure
members are not supported at present.
-
createConstructorStatementDefault
public static Statement createConstructorStatementDefault(FieldNode fNode)
-
getGetterName
public static String getGetterName(PropertyNode pNode)
-
convertASTToSource
public static String convertASTToSource(ReaderSource readerSource, ASTNode expression) throws Exception
Converts an expression into the String source. Only some specific expressions like closure expression support this.- Parameters:
readerSource
- a sourceexpression
- an expression. Can't be null- Returns:
- the source the closure was created from
- Throws:
IllegalArgumentException
- when expression is nullException
- when closure can't be read from source
-
copyStatementsWithSuperAdjustment
public static boolean copyStatementsWithSuperAdjustment(ClosureExpression pre, BlockStatement body)
-
hasDeclaredMethod
public static boolean hasDeclaredMethod(ClassNode cNode, String name, int argsCount)
-
isDefaultVisibility
public static boolean isDefaultVisibility(int modifiers)
-
makeDescriptorWithoutReturnType
@Deprecated public static String makeDescriptorWithoutReturnType(MethodNode mn)
Deprecated.use MethodNodeUtils#methodDescriptorWithoutReturnType(MethodNode) instead
-
-