@CompileStatic class AstUtils extends Object
Utility methods for dealing with Groovy ASTs
| Modifiers | Name | Description |
|---|---|---|
class |
AstUtils.1 |
| Modifiers | Name | Description |
|---|---|---|
static Token |
ASSIGNMENT_OPERATOR |
|
static ClassNode |
COMPILE_STATIC_TYPE |
|
static Pattern |
DOMAIN_PATH_PATTERN |
|
static String |
DOMAIN_TYPE |
|
static ClassNode[] |
EMPTY_CLASS_ARRAY |
|
static String |
GRAILS_APP_DIR |
The name of the Grails application directory |
static String |
META_DATA_KEY_GRAILS_APP_DIR |
|
static String |
META_DATA_KEY_PROJECT_DIR |
|
static ClassNode |
OBJECT_CLASS_NODE |
|
static String |
REGEX_FILE_SEPARATOR |
|
static Object |
TRANSFORM_APPLIED_MARKER |
|
static ClassNode |
TYPE_CHECKED_TYPE |
|
static ArgumentListExpression |
ZERO_ARGUMENTS |
|
static Parameter[] |
ZERO_PARAMETERS |
| Constructor and description |
|---|
AstUtils() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
static void |
addAnnotationIfNecessary(AnnotatedNode classNode, Class<? extends Annotation> annotationClass)Adds an annotation to the give class node if it doesn't already exist |
|
static AnnotationNode |
addAnnotationOrGetExisting(AnnotatedNode classNode, Class<? extends Annotation> annotationClass)Adds an annotation to the given class node or returns the existing annotation |
|
static AnnotationNode |
addAnnotationOrGetExisting(AnnotatedNode annotatedNode, Class<? extends Annotation> annotationClass, Map<String, Object> members)Adds an annotation to the given class node or returns the existing annotation |
|
static AnnotationNode |
addAnnotationOrGetExisting(AnnotatedNode annotatedNode, ClassNode annotationClassNode) |
|
static AnnotationNode |
addAnnotationOrGetExisting(AnnotatedNode annotatedNode, ClassNode annotationClassNode, Map<String, Object> members) |
|
static void |
addTransformedEntityName(String name)
|
|
static MethodCallExpression |
buildGetPropertyExpression(Expression objectExpression, String propertyName, ClassNode targetClassNode)Build static direct call to getter of a property |
|
static MethodCallExpression |
buildGetPropertyExpression(Expression objectExpression, String propertyName, ClassNode targetClassNode, boolean useBooleanGetter)Build static direct call to getter of a property |
|
static MethodCallExpression |
buildSetPropertyExpression(Expression objectExpression, String propertyName, ClassNode targetClassNode, Expression valueExpression)Build static direct call to setter of a property |
|
static AnnotationNode |
cloneAnnotation(AnnotationNode node) |
|
static void |
copyAnnotations(AnnotatedNode from, AnnotatedNode to) |
|
static void |
copyAnnotations(AnnotatedNode from, AnnotatedNode to, Set<String> included, Set<String> excluded) |
|
static Parameter[] |
copyParameters(Parameter[] parameterTypes) |
|
static Parameter[] |
copyParameters(Parameter[] parameterTypes, Map<String, ClassNode> genericsPlaceholders) |
|
static Parameter[] |
copyParameters(Map<String, ClassNode> genericsSpec, Parameter[] parameterTypes, List<String> currentMethodGenPlaceholders) |
|
static void |
error(SourceUnit sourceUnit, ASTNode expr, String errorMessage) |
|
protected static void |
findAbstractMethodsInternal(ClassNode classNode, List<MethodNode> methods, boolean includeProtected) |
|
static List<MethodNode> |
findAllAbstractMethods(ClassNode classNode)Finds all the abstract methods for the give class node |
|
static List<MethodNode> |
findAllUnimplementedAbstractMethods(ClassNode classNode)Finds all the abstract methods for the give class node |
|
static AnnotationNode |
findAnnotation(AnnotatedNode classNode, Class<?> type) |
|
static AnnotationNode |
findAnnotation(AnnotatedNode annotationClassNode, List<AnnotationNode> annotations) |
|
static ClassNode |
findInterface(ClassNode classNode, String interfaceName) |
|
static List<MethodNode> |
findPublicAbstractMethods(ClassNode classNode)Finds all the abstract methods for the give class node |
|
static ClassNode |
getFurthestUnresolvedParent(ClassNode classNode) |
|
static Collection<String> |
getKnownEntityNames()
|
|
static PropertyNode |
getPropertyFromHierarchy(ClassNode cn, String name)Obtains a property from the class hierarchy |
|
static ClassNode |
getPropertyType(ClassNode classNode, String propertyName)Returns the property type if it exists |
|
static boolean |
hasAnnotation(MethodNode methodNode, Class<? extends Annotation> annotationClass)Returns true if MethodNode is marked with annotationClass |
|
static boolean |
hasAnnotation(MethodNode methodNode, ClassNode annotationClassNode) |
|
static boolean |
hasAnnotation(MethodNode methodNode, String annotationClassName)Returns true if MethodNode is marked with annotationClass |
|
static boolean |
hasAnnotation(List<AnnotationNode> annotationNodes, AnnotationNode annotationNode) |
|
static boolean |
hasAnnotation(ClassNode classNode, Class<? extends Annotation> annotationClass)Returns true if classNode is marked with annotationClass |
|
static boolean |
hasAnyAnnotations(ClassNode classNode, Class<? extends Annotation>[] annotationsToLookFor)
|
|
static boolean |
hasJunitAnnotation(MethodNode md)Whether the method node has any JUnit annotations |
|
static boolean |
hasOrInheritsProperty(ClassNode classNode, String propertyName) |
|
static boolean |
hasProperty(ClassNode classNode, String propertyName)Returns whether a classNode has the specified property or not |
|
static boolean |
implementsInterface(ClassNode classNode, String interfaceName)Whether the given class node implements the given interface name |
|
static boolean |
implementsInterface(ClassNode classNode, Class itfc)Whether the given class node implements the given interface node |
|
static boolean |
implementsInterface(ClassNode classNode, ClassNode interfaceNode)Whether the given class node implements the given interface node |
|
static boolean |
implementsOrInheritsZeroArgMethod(ClassNode classNode, String methodName) |
|
static boolean |
implementsZeroArgMethod(ClassNode classNode, String methodName)Tests whether the ClasNode implements the specified method name. |
|
static void |
injectTrait(ClassNode classNode, Class traitClass) |
|
static boolean |
isDomainClass(URL url)Checks whether the file referenced by the given url is a domain class |
|
static boolean |
isDomainClass(ClassNode classNode) |
|
static boolean |
isEnum(ClassNode classNode)Is the class an enum |
|
static boolean |
isGetter(MethodNode declaredMethod) |
|
static boolean |
isGroovyType(ClassNode type)Whether the given type is a Groovy object |
|
static boolean |
isIterableOrArrayOfDomainClasses(ClassNode type) |
|
static boolean |
isNumberType(ClassNode classNode)Is the class a number |
|
static boolean |
isSetter(MethodNode declaredMethod) |
|
static boolean |
isSpockTest(ClassNode classNode)Whether the class is a Spock test |
|
static boolean |
isSubclassOf(ClassNode classNode, String parentClassName)Returns true if the given class name is a parent class of the given class |
|
static boolean |
isSubclassOfOrImplementsInterface(ClassNode childClass, ClassNode superClass) |
|
static boolean |
isSubclassOfOrImplementsInterface(ClassNode childClass, String superClassName) |
|
static ClosureExpression |
makeClosureAwareOfArguments(MethodNode methodNode, ClosureExpression closure)Makes a closure aware of the given methods arguments |
|
static MapExpression |
mapX(Map<String, ? extends Expression> map)Builds a map |
|
static ClassNode |
nonGeneric(ClassNode type) |
|
static ClassNode |
nonGeneric(ClassNode type, ClassNode wildcardReplacement) |
|
static void |
processVariableScopes(SourceUnit source, ClassNode classNode, MethodNode methodNode) |
|
static ClassNode |
replaceGenericsPlaceholders(ClassNode type, Map<String, ClassNode> genericsPlaceholders) |
|
static ClassNode |
replaceGenericsPlaceholders(ClassNode type, Map<String, ClassNode> genericsPlaceholders, ClassNode defaultPlaceholder) |
|
static VariableExpression |
varThis()
|
|
static void |
warning(SourceUnit sourceUnit, ASTNode node, String warningMessage) |
The name of the Grails application directory
Adds an annotation to the give class node if it doesn't already exist
classNode - The class nodeannotationClass - The annotation classAdds an annotation to the given class node or returns the existing annotation
classNode - The class nodeannotationClass - The annotation classAdds an annotation to the given class node or returns the existing annotation
annotatedNode - The class nodeannotationClass - The annotation class
name - Adds the name of a transformed entityBuild static direct call to getter of a property
Build static direct call to getter of a property
Build static direct call to setter of a property
Finds all the abstract methods for the give class node
classNode - The class nodeFinds all the abstract methods for the give class node
classNode - The class nodeFinds all the abstract methods for the give class node
classNode - The class node
Obtains a property from the class hierarchy
cn - The class nodename - The property nameReturns the property type if it exists
classNode - The ClassNodepropertyName - The name of the propertyReturns true if MethodNode is marked with annotationClass
methodNode - A MethodNode to inspectannotationClass - an annotation to look forReturns true if MethodNode is marked with annotationClass
methodNode - A MethodNode to inspectannotationClass - an annotation to look forReturns true if classNode is marked with annotationClass
classNode - A ClassNode to inspectannotationClass - an annotation to look for
classNode - a ClassNode to searchannotationsToLookFor - Annotations to look forWhether the method node has any JUnit annotations
md - The method nodeReturns whether a classNode has the specified property or not
classNode - The ClassNodepropertyName - The name of the propertyWhether the given class node implements the given interface name
classNode - The class nodeinterfaceName - The interface nameWhether the given class node implements the given interface node
classNode - The class nodeitfc - The interfaceWhether the given class node implements the given interface node
classNode - The class nodeinterfaceName - The interface nodeTests whether the ClasNode implements the specified method name.
classNode - The ClassNodemethodName - The method nameChecks whether the file referenced by the given url is a domain class
url - The URL instanceIs the class an enum
classNode - The class nodeWhether the given type is a Groovy object
type - The typeIs the class a number
classNode - The class nodeWhether the class is a Spock test
classNode - The class nodeReturns true if the given class name is a parent class of the given class
classNode - The class nodeparentClassName - the parent class nameMakes a closure aware of the given methods arguments
methodNode - The methodclosure - The existing closureBuilds a map
map - The map