public class GrailsASTUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Token |
ASSIGNMENT_OPERATOR |
static Token |
EQUALS_OPERATOR |
static java.lang.String |
METHOD_MISSING_METHOD_NAME |
static ClassNode |
MISSING_METHOD_EXCEPTION |
static Token |
NOT_EQUALS_OPERATOR |
static ConstantExpression |
NULL_EXPRESSION |
static java.lang.String |
STATIC_METHOD_MISSING_METHOD_NAME |
Constructor and Description |
---|
GrailsASTUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addAnnotationIfNecessary(ClassNode classNode,
java.lang.Class<Entity> entityClass) |
static void |
addDelegateConstructor(ClassNode classNode,
MethodNode constructorMethod)
Adds or modifies an existing constructor to delegate to the
given static constructor method for initialization logic.
|
static MethodNode |
addDelegateInstanceMethod(ClassNode classNode,
Expression delegate,
MethodNode declaredMethod)
Adds a delegate method to the target class node where the first argument
is to the delegate method is 'this'.
|
static MethodNode |
addDelegateInstanceMethod(ClassNode classNode,
Expression delegate,
MethodNode declaredMethod,
boolean thisAsFirstArgument)
Adds a delegate method to the target class node where the first argument
is to the delegate method is 'this'.
|
static void |
addDelegateInstanceMethods(ClassNode supportedSuperType,
ClassNode classNode,
ClassNode delegateNode,
Expression delegateInstance) |
static void |
addDelegateInstanceMethods(ClassNode classNode,
ClassNode delegateNode,
Expression delegateInstance) |
static MethodNode |
addDelegateStaticMethod(ClassNode classNode,
MethodNode delegateMethod)
Adds a static method call to given class node that delegates to the given method
|
static MethodNode |
addDelegateStaticMethod(Expression expression,
ClassNode classNode,
MethodNode delegateMethod)
Adds a static method to the given class node that delegates to the given method
and resolves the object to invoke the method on from the given expression.
|
static void |
addFieldIfNonExistent(ClassNode classNode,
ClassNode fieldType,
java.lang.String fieldName) |
static void |
addMethodIfNotPresent(ClassNode controllerClassNode,
MethodNode methodNode) |
static ArgumentListExpression |
createArgumentListFromParameters(Parameter[] parameterTypes,
boolean thisAsFirstArgument)
Creates an argument list from the given parameter types.
|
static ExpressionStatement |
createPrintlnStatement(java.lang.String message) |
static ExpressionStatement |
createPrintlnStatement(java.lang.String message,
java.lang.String variable) |
static void |
error(SourceUnit sourceUnit,
ASTNode astNode,
java.lang.String message)
Generates a fatal compilation error
|
static void |
error(SourceUnit sourceUnit,
ASTNode astNode,
java.lang.String message,
boolean fatal)
Generates a fatal compilation error
|
static AnnotationNode |
findAnnotation(ClassNode classNode,
java.lang.Class type) |
static AnnotationNode |
findAnnotation(ClassNode annotationClassNode,
java.util.List<AnnotationNode> annotations) |
static ConstructorNode |
findConstructor(ClassNode classNode,
Parameter[] constructorParams)
Finds a constructor for the given class node and parameter types
|
static java.util.Map<java.lang.String,ClassNode> |
getAllAssociationMap(ClassNode classNode) |
static java.util.Map<java.lang.String,ClassNode> |
getAssocationMap(ClassNode classNode,
java.lang.String associationType)
Returns a map containing the names and types of the given association type.
|
static java.util.Map<java.lang.String,java.util.Map<java.lang.String,Expression>> |
getConstraintMetadata(ClosureExpression closureExpression)
Evaluates a constraints closure and returns metadata about the constraints configured in the closure.
|
static ConstructorNode |
getDefaultConstructor(ClassNode classNode)
Obtains the default constructor for the given class node.
|
static java.lang.String |
getFullName(ClassNode classNode)
Gets the full name of a ClassNode.
|
static ClassNode |
getFurthestParent(ClassNode classNode) |
static ClassNode |
getFurthestUnresolvedParent(ClassNode classNode) |
static Parameter[] |
getRemainingParameterTypes(Parameter[] parameters)
Gets the remaining parameters excluding the first parameter in the given list
|
static boolean |
hasAnnotation(ClassNode classNode,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Returns true if classNode is marked with annotationClass
|
static boolean |
hasAnyAnnotations(ClassNode classNode,
java.lang.Class<? extends java.lang.annotation.Annotation>... annotationsToLookFor) |
static boolean |
hasOrInheritsProperty(ClassNode classNode,
java.lang.String propertyName) |
static boolean |
hasProperty(ClassNode classNode,
java.lang.String propertyName)
Returns whether a classNode has the specified property or not
|
static boolean |
implementsOrInheritsZeroArgMethod(ClassNode classNode,
java.lang.String methodName,
java.util.List ignoreClasses) |
static boolean |
implementsZeroArgMethod(ClassNode classNode,
java.lang.String methodName)
Tests whether the ClasNode implements the specified method name.
|
static boolean |
isCandidateInstanceMethod(ClassNode classNode,
MethodNode declaredMethod) |
static boolean |
isCandidateMethod(MethodNode declaredMethod) |
static boolean |
isConstructorMethod(MethodNode declaredMethod) |
static ClassNode |
nonGeneric(ClassNode type) |
static boolean |
parametersEqual(Parameter[] a,
Parameter[] b) |
static void |
warning(SourceUnit sourceUnit,
ASTNode node,
java.lang.String warningMessage) |
static void |
wrapMethodBodyInTryCatchDebugStatements(MethodNode methodNode)
Wraps a method body in try / catch logic that catches any errors and logs an error, but does not rethrow!
|
public static final java.lang.String METHOD_MISSING_METHOD_NAME
public static final java.lang.String STATIC_METHOD_MISSING_METHOD_NAME
public static final Token EQUALS_OPERATOR
public static final Token NOT_EQUALS_OPERATOR
public static final ClassNode MISSING_METHOD_EXCEPTION
public static final ConstantExpression NULL_EXPRESSION
public static final Token ASSIGNMENT_OPERATOR
public static void warning(SourceUnit sourceUnit, ASTNode node, java.lang.String warningMessage)
public static void error(SourceUnit sourceUnit, ASTNode astNode, java.lang.String message)
sourceUnit
- the SourceUnitastNode
- the ASTNode which caused the errormessage
- The error messagepublic static void error(SourceUnit sourceUnit, ASTNode astNode, java.lang.String message, boolean fatal)
sourceUnit
- the SourceUnitastNode
- the ASTNode which caused the errormessage
- The error messagefatal
- indicates if this is a fatal errorpublic static boolean hasProperty(ClassNode classNode, java.lang.String propertyName)
classNode
- The ClassNodepropertyName
- The name of the propertypublic static boolean hasOrInheritsProperty(ClassNode classNode, java.lang.String propertyName)
public static boolean implementsZeroArgMethod(ClassNode classNode, java.lang.String methodName)
classNode
- The ClassNodemethodName
- The method namepublic static boolean implementsOrInheritsZeroArgMethod(ClassNode classNode, java.lang.String methodName, java.util.List ignoreClasses)
public static java.lang.String getFullName(ClassNode classNode)
classNode
- The class nodepublic static ClassNode getFurthestParent(ClassNode classNode)
public static ClassNode getFurthestUnresolvedParent(ClassNode classNode)
public static MethodNode addDelegateInstanceMethod(ClassNode classNode, Expression delegate, MethodNode declaredMethod)
classNode
- The class nodedelegate
- The expression that looks up the delegatedeclaredMethod
- The declared methodpublic static MethodNode addDelegateInstanceMethod(ClassNode classNode, Expression delegate, MethodNode declaredMethod, boolean thisAsFirstArgument)
classNode
- The class nodedelegate
- The expression that looks up the delegatedeclaredMethod
- The declared methodthisAsFirstArgument
- Whether 'this' should be passed as the first argument to the methodpublic static ArgumentListExpression createArgumentListFromParameters(Parameter[] parameterTypes, boolean thisAsFirstArgument)
parameterTypes
- The parameter typesthisAsFirstArgument
- Whether to include a reference to 'this' as the first argumentpublic static Parameter[] getRemainingParameterTypes(Parameter[] parameters)
parameters
- The parameterspublic static MethodNode addDelegateStaticMethod(ClassNode classNode, MethodNode delegateMethod)
classNode
- The class nodedelegateMethod
- The delegate methodpublic static MethodNode addDelegateStaticMethod(Expression expression, ClassNode classNode, MethodNode delegateMethod)
expression
- The expressionclassNode
- The class nodedelegateMethod
- The delegate methodpublic static void addDelegateConstructor(ClassNode classNode, MethodNode constructorMethod)
classNode
- The class nodeconstructorMethod
- The constructor static methodpublic static ConstructorNode findConstructor(ClassNode classNode, Parameter[] constructorParams)
classNode
- The class nodeconstructorParams
- The parameter typespublic static boolean parametersEqual(Parameter[] a, Parameter[] b)
public static ConstructorNode getDefaultConstructor(ClassNode classNode)
classNode
- The class nodepublic static ClassNode nonGeneric(ClassNode type)
public static boolean isCandidateInstanceMethod(ClassNode classNode, MethodNode declaredMethod)
public static boolean isCandidateMethod(MethodNode declaredMethod)
public static boolean isConstructorMethod(MethodNode declaredMethod)
public static void addDelegateInstanceMethods(ClassNode classNode, ClassNode delegateNode, Expression delegateInstance)
public static void addDelegateInstanceMethods(ClassNode supportedSuperType, ClassNode classNode, ClassNode delegateNode, Expression delegateInstance)
public static void addFieldIfNonExistent(ClassNode classNode, ClassNode fieldType, java.lang.String fieldName)
public static void addAnnotationIfNecessary(ClassNode classNode, java.lang.Class<Entity> entityClass)
public static AnnotationNode findAnnotation(ClassNode annotationClassNode, java.util.List<AnnotationNode> annotations)
public static AnnotationNode findAnnotation(ClassNode classNode, java.lang.Class type)
public static boolean hasAnnotation(ClassNode classNode, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
classNode
- A ClassNode to inspectannotationClass
- an annotation to look forpublic static boolean hasAnyAnnotations(ClassNode classNode, java.lang.Class<? extends java.lang.annotation.Annotation>... annotationsToLookFor)
classNode
- a ClassNode to searchannotationsToLookFor
- Annotations to look forpublic static void addMethodIfNotPresent(ClassNode controllerClassNode, MethodNode methodNode)
public static ExpressionStatement createPrintlnStatement(java.lang.String message)
public static ExpressionStatement createPrintlnStatement(java.lang.String message, java.lang.String variable)
public static void wrapMethodBodyInTryCatchDebugStatements(MethodNode methodNode)
methodNode
- The method nodepublic static java.util.Map<java.lang.String,java.util.Map<java.lang.String,Expression>> getConstraintMetadata(ClosureExpression closureExpression)
closureExpression
- the closure expression to evaluatepublic static java.util.Map<java.lang.String,ClassNode> getAssocationMap(ClassNode classNode, java.lang.String associationType)
classNode
- The target class ndoeassociationType
- The associationTypepublic static java.util.Map<java.lang.String,ClassNode> getAllAssociationMap(ClassNode classNode)