Package org.codehaus.groovy.ast.tools
Class GeneralUtils
java.lang.Object
org.codehaus.groovy.ast.tools.GeneralUtils
public class GeneralUtils
extends java.lang.Object
Handy methods when working with the Groovy AST
- 
Field Summary
- 
Constructor SummaryConstructors Constructor Description GeneralUtils()
- 
Method SummaryModifier and Type Method Description static BinaryExpressionandX(Expression lhv, Expression rhv)static ArgumentListExpressionargs(java.lang.String... names)static ArgumentListExpressionargs(java.util.List<Expression> expressions)static ArgumentListExpressionargs(Expression... expressions)static ArgumentListExpressionargs(Parameter... parameters)static StatementassignNullS(Expression target)static StatementassignS(Expression target, Expression value)static ExpressionassignX(Expression target, Expression value)static CastExpressionasX(ClassNode type, Expression expression)static ExpressionattrX(Expression oe, Expression prop)static BinaryExpressionbinX(Expression left, Token token, Expression right)static BlockStatementblock(Statement... stmts)static BlockStatementblock(VariableScope scope, java.util.List<Statement> stmts)static BlockStatementblock(VariableScope scope, Statement... stmts)static BooleanExpressionboolX(Expression expr)static BytecodeExpressionbytecodeX(java.util.function.Consumer<org.objectweb.asm.MethodVisitor> writer)static BytecodeExpressionbytecodeX(ClassNode type, java.util.function.Consumer<org.objectweb.asm.MethodVisitor> writer)static MethodCallExpressioncallSuperX(java.lang.String methodName)static MethodCallExpressioncallSuperX(java.lang.String methodName, Expression args)static MethodCallExpressioncallThisX(java.lang.String methodName)static MethodCallExpressioncallThisX(java.lang.String methodName, Expression args)static StaticMethodCallExpressioncallX(ClassNode receiver, java.lang.String methodName)static StaticMethodCallExpressioncallX(ClassNode receiver, java.lang.String methodName, Expression args)static MethodCallExpressioncallX(Expression receiver, java.lang.String methodName)static MethodCallExpressioncallX(Expression receiver, java.lang.String methodName, Expression args)static MethodCallExpressioncallX(Expression receiver, Expression method, Expression args)static CastExpressioncastX(ClassNode type, Expression expression)static CastExpressioncastX(ClassNode type, Expression expression, boolean ignoreAutoboxing)static CatchStatementcatchS(Parameter variable, Statement code)static ListExpressionclassList2args(java.util.List<java.lang.String> args)static ClassExpressionclassX(java.lang.Class<?> clazz)static ClassExpressionclassX(ClassNode clazz)static Parameter[]cloneParams(Parameter[] parameters)static ClosureExpressionclosureX(Parameter[] params, Statement code)static ClosureExpressionclosureX(Statement code)static BinaryExpressioncmpX(Expression lhv, Expression rhv)Builds a binary expression that compares two values.static ConstantExpressionconstX(java.lang.Object val)static ConstantExpressionconstX(java.lang.Object val, boolean keepPrimitive)static java.lang.StringconvertASTToSource(ReaderSource readerSource, ASTNode expression)Converts an expression into the String source.static voidcopyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, java.util.List<AnnotationNode> copied, java.util.List<AnnotationNode> notCopied)Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIMEandRetentionPolicy.CLASS.static voidcopyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, java.util.List<AnnotationNode> copied, java.util.List<AnnotationNode> notCopied, boolean includeGenerated)Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIMEandRetentionPolicy.CLASS.static booleancopyStatementsWithSuperAdjustment(ClosureExpression pre, BlockStatement body)static StatementcreateConstructorStatementDefault(FieldNode fNode)static StatementctorSuperS()static StatementctorSuperS(Expression args)static ConstructorCallExpressionctorSuperX()static ConstructorCallExpressionctorSuperX(Expression args)static StatementctorThisS()static StatementctorThisS(Expression args)static ConstructorCallExpressionctorThisX()static ConstructorCallExpressionctorThisX(Expression args)static ConstructorCallExpressionctorX(ClassNode type)static ConstructorCallExpressionctorX(ClassNode type, Expression args)static StatementdeclS(Expression target, Expression init)static DeclarationExpressiondeclX(Expression target, Expression init)static ElvisOperatorExpressionelvisX(Expression base, Expression otherwise)static MapEntryExpressionentryX(Expression key, Expression value)static BooleanExpressionequalsNullX(Expression argExpr)static BinaryExpressioneqX(Expression lhv, Expression rhv)static FieldExpressionfieldX(ClassNode owner, java.lang.String fieldName)static FieldExpressionfieldX(FieldNode fieldNode)static ExpressionfindArg(java.lang.String argName)static java.util.List<MethodNode>getAllMethods(ClassNode type)static java.util.List<PropertyNode>getAllProperties(java.util.Set<java.lang.String> names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly)static java.util.List<PropertyNode>getAllProperties(java.util.Set<java.lang.String> names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly)static java.util.List<PropertyNode>getAllProperties(java.util.Set<java.lang.String> names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly, boolean reverse, boolean allNames, boolean includeStatic)static java.util.List<PropertyNode>getAllProperties(ClassNode type)static java.lang.StringgetGetterName(PropertyNode pNode)static java.util.List<java.lang.String>getInstanceNonPropertyFieldNames(ClassNode cNode)static java.util.List<FieldNode>getInstanceNonPropertyFields(ClassNode cNode)static java.util.List<PropertyNode>getInstanceProperties(ClassNode cNode)static java.util.List<FieldNode>getInstancePropertyFields(ClassNode cNode)static java.util.List<java.lang.String>getInstancePropertyNames(ClassNode cNode)static java.util.Set<ClassNode>getInterfacesAndSuperInterfaces(ClassNode cNode)static java.lang.StringgetSetterName(java.lang.String name)static java.util.List<FieldNode>getSuperNonPropertyFields(ClassNode cNode)static java.util.List<FieldNode>getSuperPropertyFields(ClassNode cNode)static ExpressiongetterThisX(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 ExpressiongetterX(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 BinaryExpressionhasClassX(Expression instance, ClassNode cNode)static booleanhasDeclaredMethod(ClassNode cNode, java.lang.String name, int argsCount)static BinaryExpressionhasEqualFieldX(FieldNode fNode, Expression other)static BinaryExpressionhasEqualPropertyX(ClassNode annotatedNode, PropertyNode pNode, VariableExpression other)static BinaryExpressionhasEqualPropertyX(PropertyNode pNode, Expression other)Deprecated.static BooleanExpressionhasSameFieldX(FieldNode fNode, Expression other)static BooleanExpressionhasSamePropertyX(PropertyNode pNode, Expression other)static IfStatementifElseS(Expression cond, Statement thenStmt, Statement elseStmt)static StatementifElseS$$bridge(Expression cond, Statement thenStmt, Statement elseStmt)Deprecated.static IfStatementifS(Expression cond, Expression trueExpr)static IfStatementifS(Expression cond, Statement trueStmt)static StatementifS$$bridge(Expression cond, Expression trueExpr)Deprecated.static StatementifS$$bridge(Expression cond, Statement trueStmt)Deprecated.static ExpressionindexX(Expression target, Expression value)static booleaninSamePackage(java.lang.Class<?> first, java.lang.Class<?> second)static booleaninSamePackage(ClassNode first, ClassNode second)static booleanisDefaultVisibility(int modifiers)static BooleanExpressionisInstanceOfX(Expression objectExpression, ClassNode cNode)static BooleanExpressionisNullX(Expression expr)Alias forequalsNullX(Expression)static BooleanExpressionisOneX(Expression expr)static booleanisOrImplements(ClassNode type, ClassNode interfaceType)static BooleanExpressionisTrueX(Expression argExpr)static BooleanExpressionisZeroX(Expression expr)static ListExpressionlist2args(java.util.List<?> args)static ListExpressionlistX(java.util.List<Expression> args)static VariableExpressionlocalVarX(java.lang.String name)static VariableExpressionlocalVarX(java.lang.String name, ClassNode type)static BinaryExpressionltX(Expression lhv, Expression rhv)static java.lang.StringmakeDescriptorWithoutReturnType(MethodNode mn)Deprecated.use MethodNodeUtils#methodDescriptorWithoutReturnType(MethodNode) insteadstatic MapExpressionmapX(java.util.List<MapEntryExpression> expressions)static BinaryExpressionneX(Expression lhv, Expression rhv)static BinaryExpressionnotIdenticalX(Expression lhv, Expression rhv)static BooleanExpressionnotNullX(Expression argExpr)static NotExpressionnotX(Expression expr)static ConstantExpressionnullX()static BinaryExpressionorX(Expression lhv, Expression rhv)static Parameterparam(ClassNode type, java.lang.String name)static Parameterparam(ClassNode type, java.lang.String name, Expression initialExpression)static Parameter[]params(Parameter... params)static BinaryExpressionplusX(Expression lhv, Expression rhv)static PropertyExpressionpropX(Expression owner, java.lang.String property)static PropertyExpressionpropX(Expression owner, Expression property)static PropertyExpressionpropX(Expression owner, Expression property, boolean safe)static ExpressionpropX$$bridge(Expression owner, java.lang.String property)Deprecated.static ExpressionpropX$$bridge(Expression owner, Expression property)Deprecated.static StatementreturnS(Expression expr)static StatementsafeExpression(Expression fieldExpr, Expression expression)static BooleanExpressionsameX(Expression self, Expression other)static Statementstmt(Expression expr)static TernaryExpressionternaryX(Expression cond, Expression trueExpr, Expression elseExpr)static PropertyExpressionthisPropX(boolean implicit, java.lang.String property)static ThrowStatementthrowS(Expression expr)static TryCatchStatementtryCatchS(Statement tryStatement)static TryCatchStatementtryCatchS(Statement tryStatement, Statement finallyStatement)static TryCatchStatementtryCatchS(Statement tryStatement, Statement finallyStatement, CatchStatement... catchStatements)static VariableExpressionvarX(java.lang.String name)static VariableExpressionvarX(java.lang.String name, ClassNode type)static VariableExpressionvarX(Variable variable)Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
- 
Field Details- 
ASSIGN
- 
EQ
- 
NE
- 
NOT_IDENTICAL
- 
LT
- 
AND
- 
OR
- 
CMP
- 
INSTANCEOF
 
- 
- 
Constructor Details- 
GeneralUtilspublic GeneralUtils()
 
- 
- 
Method Details- 
andX
- 
args
- 
args
- 
args
- 
args
- 
asX
- 
assignS
- 
assignNullS
- 
assignX
- 
attrX
- 
binX
- 
block
- 
block
- 
block
- 
boolX
- 
bytecodeXpublic static BytecodeExpression bytecodeX(java.util.function.Consumer<org.objectweb.asm.MethodVisitor> writer)
- 
bytecodeXpublic static BytecodeExpression bytecodeX(ClassNode type, java.util.function.Consumer<org.objectweb.asm.MethodVisitor> writer)
- 
callSuperX
- 
callSuperX
- 
callThisX
- 
callThisX
- 
callX
- 
callXpublic static MethodCallExpression callX(Expression receiver, java.lang.String methodName, Expression args)
- 
callX
- 
callX
- 
callXpublic static StaticMethodCallExpression callX(ClassNode receiver, java.lang.String methodName, Expression args)
- 
castX
- 
castXpublic static CastExpression castX(ClassNode type, Expression expression, boolean ignoreAutoboxing)
- 
catchS
- 
classX
- 
classX
- 
closureX
- 
closureX
- 
cmpXBuilds a binary expression that compares two values.- Parameters:
- lhv- expression for the value to compare from
- rhv- expression for the value value to compare to
- Returns:
- the expression comparing two values
 
- 
constX
- 
constX
- 
ctorX
- 
ctorX
- 
ctorSuperS
- 
ctorSuperX
- 
ctorThisS
- 
ctorThisX
- 
ctorSuperS
- 
ctorSuperX
- 
ctorThisS
- 
ctorThisX
- 
declS
- 
declX
- 
elvisX- Since:
- 3.0.10
 
- 
entryX
- 
eqX
- 
equalsNullX
- 
fieldX
- 
fieldX
- 
findArg
- 
getAllMethods
- 
getAllProperties
- 
getInstanceNonPropertyFields
- 
getInstanceNonPropertyFieldNames
- 
getInstanceProperties
- 
getInstancePropertyNames
- 
getInstancePropertyFields
- 
getInterfacesAndSuperInterfaces
- 
getSuperNonPropertyFields
- 
getSuperPropertyFields
- 
getAllPropertiespublic static java.util.List<PropertyNode> getAllProperties(java.util.Set<java.lang.String> names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly)
- 
getAllPropertiespublic static java.util.List<PropertyNode> getAllProperties(java.util.Set<java.lang.String> names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly)
- 
getAllPropertiespublic static java.util.List<PropertyNode> getAllProperties(java.util.Set<java.lang.String> names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly, boolean reverse, boolean allNames, boolean includeStatic)
- 
getterThisXThis 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 from
- pNode- the property being accessed
- Returns:
- a method call expression or a property expression
 
- 
getterXThis 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 from
- receiver- the object having the property
- pNode- the property being accessed
- Returns:
- a method call expression or a property expression
 
- 
hasClassX
- 
hasEqualFieldX
- 
hasEqualPropertyXpublic static BinaryExpression hasEqualPropertyX(ClassNode annotatedNode, PropertyNode pNode, VariableExpression other)
- 
hasEqualPropertyXDeprecated.
- 
hasSameFieldX
- 
hasSamePropertyX
- 
ifElseS$$bridge@Deprecated public static Statement ifElseS$$bridge(Expression cond, Statement thenStmt, Statement elseStmt)Deprecated.
- 
ifElseS
- 
ifS$$bridgeDeprecated.
- 
ifS
- 
ifS$$bridgeDeprecated.
- 
ifS
- 
indexX
- 
isInstanceOfX
- 
isNullXAlias forequalsNullX(Expression)
- 
isOneX
- 
isTrueX
- 
isZeroX
- 
listX
- 
list2args
- 
classList2args
- 
localVarX
- 
localVarX
- 
ltX
- 
mapX
- 
neX
- 
notIdenticalX
- 
notNullX
- 
notX
- 
nullX
- 
orX
- 
param
- 
param
- 
params
- 
plusX
- 
propX
- 
propX$$bridgeDeprecated.
- 
propX
- 
propX$$bridgeDeprecated.
- 
propX
- 
returnS
- 
safeExpression
- 
sameX
- 
stmt
- 
ternaryXpublic static TernaryExpression ternaryX(Expression cond, Expression trueExpr, Expression elseExpr)
- 
thisPropX
- 
throwS
- 
tryCatchS
- 
tryCatchS
- 
tryCatchSpublic static TryCatchStatement tryCatchS(Statement tryStatement, Statement finallyStatement, CatchStatement... catchStatements)
- 
varX
- 
varX
- 
varX
- 
cloneParams
- 
copyAnnotatedNodeAnnotationspublic static void copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, java.util.List<AnnotationNode> copied, java.util.List<AnnotationNode> notCopied)Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIMEandRetentionPolicy.CLASS.Annotations with GeneratedClosuremembers are not supported at present.
- 
copyAnnotatedNodeAnnotationspublic static void copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, java.util.List<AnnotationNode> copied, java.util.List<AnnotationNode> notCopied, boolean includeGenerated)Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIMEandRetentionPolicy.CLASS.Generatedannotations will be copied ifincludeGeneratedis true.Annotations with GeneratedClosuremembers are not supported at present.
- 
createConstructorStatementDefault
- 
getGetterName
- 
getSetterNamepublic static java.lang.String getSetterName(java.lang.String name)
- 
convertASTToSourcepublic static java.lang.String convertASTToSource(ReaderSource readerSource, ASTNode expression) throws java.lang.ExceptionConverts an expression into the String source. Only some specific expressions like closure expression support this.- Parameters:
- readerSource- a source
- expression- an expression. Can't be null
- Returns:
- the source the closure was created from
- Throws:
- java.lang.IllegalArgumentException- when expression is null
- java.lang.Exception- when closure can't be read from source
 
- 
copyStatementsWithSuperAdjustmentpublic static boolean copyStatementsWithSuperAdjustment(ClosureExpression pre, BlockStatement body)
- 
hasDeclaredMethod
- 
inSamePackage
- 
inSamePackagepublic static boolean inSamePackage(java.lang.Class<?> first, java.lang.Class<?> second)
- 
isDefaultVisibilitypublic static boolean isDefaultVisibility(int modifiers)
- 
isOrImplements
- 
makeDescriptorWithoutReturnTypeDeprecated.use MethodNodeUtils#methodDescriptorWithoutReturnType(MethodNode) instead
 
-