Class GeneralUtils
java.lang.Object
org.codehaus.groovy.ast.tools.GeneralUtils
Handy methods when working with the Groovy AST
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BinaryExpressionandX(Expression lhv, Expression rhv) static ArgumentListExpressionstatic ArgumentListExpressionargs(List<Expression> expressions) static ArgumentListExpressionargs(Expression... expressions) static ArgumentListExpressionstatic StatementassignNullS(Expression target) static StatementassignS(Expression target, Expression value) static ExpressionassignX(Expression target, Expression value) static ExpressionattrX(Expression oe, Expression prop) static BinaryExpressionbinX(Expression left, Token token, Expression right) static BlockStatementstatic BlockStatementblock(VariableScope scope, List<Statement> stmts) static BlockStatementblock(VariableScope scope, Statement... stmts) static BooleanExpressionboolX(Expression expr) static MethodCallExpressioncallSuperX(String methodName) static MethodCallExpressioncallSuperX(String methodName, Expression args) static MethodCallExpressionstatic MethodCallExpressioncallThisX(String methodName, Expression args) static StaticMethodCallExpressionstatic StaticMethodCallExpressioncallX(ClassNode receiver, String methodName, Expression args) static MethodCallExpressioncallX(Expression receiver, String methodName) static MethodCallExpressioncallX(Expression receiver, 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 CatchStatementstatic ListExpressionclassList2args(List<String> args) static ClassExpressionstatic ClassExpressionstatic Parameter[]cloneParams(Parameter[] source) static ClosureExpressionstatic ClosureExpressionstatic BinaryExpressioncmpX(Expression lhv, Expression rhv) Builds a binary expression that compares two values.static ConstantExpressionstatic ConstantExpressionstatic StringconvertASTToSource(ReaderSource readerSource, ASTNode expression) Converts an expression into the String source.static voidcopyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied) Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIMEandRetentionPolicy.CLASS.static voidcopyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied, boolean includeGenerated) Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIMEandRetentionPolicy.CLASS.static booleanstatic Statementstatic Statementstatic StatementctorSuperS(Expression args) static ConstructorCallExpressionstatic ConstructorCallExpressionctorSuperX(Expression args) static Statementstatic StatementctorThisS(Expression args) static ConstructorCallExpressionstatic ConstructorCallExpressionctorThisX(Expression args) static ConstructorCallExpressionstatic ConstructorCallExpressionctorX(ClassNode type, Expression args) static StatementdeclS(Expression target, Expression init) static DeclarationExpressiondeclX(Expression target, Expression init) static MapEntryExpressionentryX(Expression key, Expression value) static BooleanExpressionequalsNullX(Expression argExpr) static BinaryExpressioneqX(Expression lhv, Expression rhv) static FieldExpressionstatic FieldExpressionstatic Expressionstatic List<MethodNode> getAllMethods(ClassNode type) static List<PropertyNode> getAllProperties(Set<String> names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly) static List<PropertyNode> getAllProperties(Set<String> names, ClassNode origType, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly) 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) static List<PropertyNode> getAllProperties(ClassNode type) static StringgetGetterName(PropertyNode pNode) static List<PropertyNode> getInstanceProperties(ClassNode cNode) static StringgetSetterName(String name) 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, 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(Class first, 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 ListExpressionstatic ListExpressionlistX(List<Expression> args) static VariableExpressionstatic VariableExpressionstatic BinaryExpressionltX(Expression lhv, Expression rhv) static StringDeprecated.use MethodNodeUtils#methodDescriptorWithoutReturnType(MethodNode) insteadstatic MapExpressionmapX(List<MapEntryExpression> expressions) static BinaryExpressionneX(Expression lhv, Expression rhv) static BooleanExpressionnotNullX(Expression argExpr) static NotExpressionnotX(Expression expr) static ConstantExpressionnullX()static BinaryExpressionorX(Expression lhv, Expression rhv) static Parameterstatic Parameterparam(ClassNode type, String name, Expression initialExpression) static Parameter[]static BinaryExpressionplusX(Expression lhv, Expression rhv) static ExpressionpropX(Expression owner, String property) static ExpressionpropX(Expression owner, Expression property) static PropertyExpressionpropX(Expression owner, Expression property, boolean safe) 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 PropertyExpressionstatic ThrowStatementthrowS(Expression expr) static TryCatchStatementstatic TryCatchStatementstatic TryCatchStatementtryCatchS(Statement tryStatement, Statement finallyStatement, CatchStatement... catchStatements) static VariableExpressionstatic VariableExpressionstatic VariableExpression
-
Field Details
-
ASSIGN
-
EQ
-
NE
-
LT
-
AND
-
OR
-
CMP
-
INSTANCEOF
-
-
Constructor Details
-
GeneralUtils
public GeneralUtils()
-
-
Method Details
-
andX
-
args
-
args
-
args
-
args
-
assignNullS
-
assignS
-
assignX
-
attrX
-
binX
-
block
-
block
-
block
-
boolX
-
callSuperX
-
callSuperX
-
callThisX
-
callThisX
-
callX
-
callX
-
callX
-
callX
-
callX
public static StaticMethodCallExpression callX(ClassNode receiver, String methodName, Expression args) -
castX
-
castX
-
catchS
-
classX
-
classX
-
closureX
-
closureX
-
cmpX
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
-
constX
-
ctorX
-
ctorX
-
ctorSuperS
-
ctorSuperS
-
ctorSuperX
-
ctorSuperX
-
ctorThisS
-
ctorThisS
-
ctorThisX
-
ctorThisX
-
declS
-
declX
-
entryX
-
eqX
-
equalsNullX
-
fieldX
-
fieldX
-
findArg
-
getAllMethods
-
getAllProperties
-
getInstanceNonPropertyFields
-
getInstanceNonPropertyFieldNames
-
getInstanceProperties
-
getInstancePropertyNames
-
getInstancePropertyFields
-
getInterfacesAndSuperInterfaces
-
getSuperNonPropertyFields
-
getSuperPropertyFields
-
getAllProperties
public static List<PropertyNode> getAllProperties(Set<String> names, ClassNode cNode, boolean includeProperties, boolean includeFields, boolean includePseudoGetters, boolean includePseudoSetters, boolean traverseSuperClasses, boolean skipReadonly) -
getAllProperties
-
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
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
-
hasClassX
-
hasEqualFieldX
-
hasEqualPropertyX
public static BinaryExpression hasEqualPropertyX(ClassNode annotatedNode, PropertyNode pNode, VariableExpression other) -
hasEqualPropertyX
Deprecated. -
hasSameFieldX
-
hasSamePropertyX
-
ifElseS$$bridge
@Deprecated public static Statement ifElseS$$bridge(Expression cond, Statement thenStmt, Statement elseStmt) Deprecated. -
ifElseS
-
ifS$$bridge
Deprecated. -
ifS
-
ifS$$bridge
Deprecated. -
ifS
-
indexX
-
isInstanceOfX
-
isNullX
Alias forequalsNullX(Expression) -
isOneX
-
isTrueX
-
isZeroX
-
listX
-
list2args
-
classList2args
-
localVarX
-
localVarX
-
ltX
-
mapX
-
neX
-
notNullX
-
notX
-
nullX
-
orX
-
param
-
param
-
params
-
plusX
-
propX
-
propX
-
propX
-
returnS
-
safeExpression
-
sameX
-
stmt
-
ternaryX
-
thisPropX
-
throwS
-
tryCatchS
-
tryCatchS
-
tryCatchS
public static TryCatchStatement tryCatchS(Statement tryStatement, Statement finallyStatement, CatchStatement... catchStatements) -
varX
-
varX
-
varX
-
cloneParams
-
copyAnnotatedNodeAnnotations
public static void copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, List<AnnotationNode> copied, List<AnnotationNode> notCopied) Copies all candidateAnnotations with retention policyRetentionPolicy.RUNTIMEandRetentionPolicy.CLASS.Annotations with
GeneratedClosuremembers 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.RUNTIMEandRetentionPolicy.CLASS.Generatedannotations will be copied ifincludeGeneratedis true.Annotations with
GeneratedClosuremembers are not supported at present. -
createConstructorStatementDefault
-
getGetterName
-
getSetterName
-
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
-
hasDeclaredMethod
-
inSamePackage
-
inSamePackage
-
isDefaultVisibility
public static boolean isDefaultVisibility(int modifiers) -
isOrImplements
-
makeDescriptorWithoutReturnType
Deprecated.use MethodNodeUtils#methodDescriptorWithoutReturnType(MethodNode) instead
-