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
-
Field Summary
-
Constructor Summary
Constructors Constructor Description GeneralUtils()
-
Method Summary
-
Field Details
-
Constructor Details
-
GeneralUtils
public GeneralUtils()
-
-
Method Details
-
andX
-
args
-
args
-
args
-
args
-
asX
-
assignS
-
assignNullS
-
assignX
-
attrX
-
binX
-
block
-
block
-
block
-
boolX
-
bytecodeX
-
bytecodeX
public static BytecodeExpression bytecodeX(ClassNode type, Consumer<org.objectweb.asm.MethodVisitor> writer) -
callSuperX
-
callSuperX
-
callThisX
-
callThisX
-
callX
-
callX
-
callX
-
callX
-
callX
public static StaticMethodCallExpression callX(ClassNode receiver, String methodName, Expression args) -
castX
-
castX
public static CastExpression castX(ClassNode type, Expression expression, boolean ignoreAutoboxing) -
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
-
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
-
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
-
notIdenticalX
-
notNullX
-
notX
-
nullX
-
orX
-
param
-
param
-
params
-
plusX
-
propX
-
propX$$bridge
Deprecated. -
propX
-
propX$$bridge
Deprecated. -
propX
-
returnS
-
safeExpression
-
sameX
-
stmt
-
ternaryX
public static TernaryExpression ternaryX(Expression cond, Expression trueExpr, Expression elseExpr) -
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.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
-
getGetterName
-
getSetterName
-
convertASTToSource
public static String convertASTToSource(ReaderSource readerSource, ASTNode expression) throws ExceptionConverts 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
-
inSamePackage
-
inSamePackage
-
isDefaultVisibility
public static boolean isDefaultVisibility(int modifiers) -
isOrImplements
-
makeDescriptorWithoutReturnType
Deprecated.use MethodNodeUtils#methodDescriptorWithoutReturnType(MethodNode) instead
-