|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.codehaus.groovy.grails.compiler.injection.GrailsASTUtils
public class GrailsASTUtils extends java.lang.Object
Helper methods for working with Groovy AST trees.
Field Summary | |
---|---|
static org.codehaus.groovy.syntax.Token |
ASSIGNMENT_OPERATOR
|
static java.lang.String |
DOMAIN_DIR
|
static org.codehaus.groovy.syntax.Token |
EQUALS_OPERATOR
|
static java.lang.String |
GRAILS_APP_DIR
|
static java.lang.String |
METHOD_MISSING_METHOD_NAME
|
static org.codehaus.groovy.ast.ClassNode |
MISSING_METHOD_EXCEPTION
|
static org.codehaus.groovy.syntax.Token |
NOT_EQUALS_OPERATOR
|
static org.codehaus.groovy.ast.expr.ConstantExpression |
NULL_EXPRESSION
|
static java.lang.String |
STATIC_METHOD_MISSING_METHOD_NAME
|
Method Summary | |
---|---|
static void
|
addAnnotationIfNecessary(org.codehaus.groovy.ast.ClassNode classNode, java.lang.Class entityClass)
|
static void
|
addDelegateConstructor(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode constructorMethod)
Adds or modifies an existing constructor to delegate to the given static constructor method for initialization logic. |
static org.codehaus.groovy.ast.MethodNode
|
addDelegateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.Expression delegate, org.codehaus.groovy.ast.MethodNode declaredMethod)
Adds a delegate method to the target class node where the first argument is to the delegate method is 'this'. |
static org.codehaus.groovy.ast.MethodNode
|
addDelegateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.Expression delegate, org.codehaus.groovy.ast.MethodNode declaredMethod, org.codehaus.groovy.ast.AnnotationNode markerAnnotation)
|
static org.codehaus.groovy.ast.MethodNode
|
addDelegateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.Expression delegate, org.codehaus.groovy.ast.MethodNode declaredMethod, boolean thisAsFirstArgument)
|
static org.codehaus.groovy.ast.MethodNode
|
addDelegateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.Expression delegate, org.codehaus.groovy.ast.MethodNode declaredMethod, org.codehaus.groovy.ast.AnnotationNode markerAnnotation, 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(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ClassNode delegateNode, org.codehaus.groovy.ast.expr.Expression delegateInstance)
|
static void
|
addDelegateInstanceMethods(org.codehaus.groovy.ast.ClassNode supportedSuperType, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ClassNode delegateNode, org.codehaus.groovy.ast.expr.Expression delegateInstance)
|
static org.codehaus.groovy.ast.MethodNode
|
addDelegateStaticMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode delegateMethod)
Adds a static method call to given class node that delegates to the given method |
static org.codehaus.groovy.ast.MethodNode
|
addDelegateStaticMethod(org.codehaus.groovy.ast.expr.Expression expression, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.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 org.codehaus.groovy.ast.MethodNode
|
addDelegateStaticMethod(org.codehaus.groovy.ast.expr.Expression expression, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode delegateMethod, org.codehaus.groovy.ast.AnnotationNode markerAnnotation)
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 org.codehaus.groovy.ast.FieldNode
|
addFieldIfNonExistent(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ClassNode fieldType, java.lang.String fieldName)
|
static void
|
addMethodIfNotPresent(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.MethodNode methodNode)
|
static org.codehaus.groovy.ast.expr.ArgumentListExpression
|
createArgumentListFromParameters(org.codehaus.groovy.ast.Parameter[] parameterTypes, boolean thisAsFirstArgument)
Creates an argument list from the given parameter types. |
static org.codehaus.groovy.ast.stmt.ExpressionStatement
|
createPrintlnStatement(java.lang.String message)
|
static org.codehaus.groovy.ast.stmt.ExpressionStatement
|
createPrintlnStatement(java.lang.String message, java.lang.String variable)
|
static void
|
error(org.codehaus.groovy.control.SourceUnit sourceUnit, org.codehaus.groovy.ast.ASTNode astNode, java.lang.String message)
Generates a fatal compilation error. |
static void
|
error(org.codehaus.groovy.control.SourceUnit sourceUnit, org.codehaus.groovy.ast.ASTNode astNode, java.lang.String message, boolean fatal)
Generates a fatal compilation error. |
static org.codehaus.groovy.ast.AnnotationNode
|
findAnnotation(org.codehaus.groovy.ast.ClassNode annotationClassNode, java.util.List annotations)
|
static org.codehaus.groovy.ast.AnnotationNode
|
findAnnotation(org.codehaus.groovy.ast.ClassNode classNode, java.lang.Class type)
|
static org.codehaus.groovy.ast.ConstructorNode
|
findConstructor(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.Parameter[] constructorParams)
Finds a constructor for the given class node and parameter types |
static java.util.Map
|
getAllAssociationMap(org.codehaus.groovy.ast.ClassNode classNode)
|
static java.util.Map
|
getAssocationMap(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String associationType)
Returns a map containing the names and types of the given association type. eg. |
static java.util.Map
|
getConstraintMetadata(org.codehaus.groovy.ast.expr.ClosureExpression closureExpression)
Evaluates a constraints closure and returns metadata about the constraints configured in the closure. |
static org.codehaus.groovy.ast.ConstructorNode
|
getDefaultConstructor(org.codehaus.groovy.ast.ClassNode classNode)
Obtains the default constructor for the given class node. |
static java.lang.String
|
getFullName(org.codehaus.groovy.ast.ClassNode classNode)
Gets the full name of a ClassNode. |
static org.codehaus.groovy.ast.ClassNode
|
getFurthestParent(org.codehaus.groovy.ast.ClassNode classNode)
|
static org.codehaus.groovy.ast.ClassNode
|
getFurthestUnresolvedParent(org.codehaus.groovy.ast.ClassNode classNode)
|
static org.codehaus.groovy.ast.Parameter[]
|
getRemainingParameterTypes(org.codehaus.groovy.ast.Parameter[] parameters)
Gets the remaining parameters excluding the first parameter in the given list |
static boolean
|
hasAnnotation(org.codehaus.groovy.ast.ClassNode classNode, java.lang.Class annotationClass)
Returns true if classNode is marked with annotationClass |
static boolean
|
hasAnyAnnotations(org.codehaus.groovy.ast.ClassNode classNode, java.lang.Class... annotationsToLookFor)
@param classNode a ClassNode to search |
static boolean
|
hasOrInheritsProperty(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String propertyName)
|
static boolean
|
hasProperty(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String propertyName)
Returns whether a classNode has the specified property or not |
static boolean
|
implementsOrInheritsZeroArgMethod(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String methodName, java.util.List ignoreClasses)
|
static boolean
|
implementsZeroArgMethod(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String methodName)
Tests whether the ClasNode implements the specified method name. |
static boolean
|
isCandidateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode declaredMethod)
|
static boolean
|
isCandidateMethod(org.codehaus.groovy.ast.MethodNode declaredMethod)
|
static boolean
|
isConstructorMethod(org.codehaus.groovy.ast.MethodNode declaredMethod)
|
static boolean
|
isDomainClass(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.control.SourceUnit sourceNode)
|
static boolean
|
isInnerClassNode(org.codehaus.groovy.ast.ClassNode classNode)
Whether the given class node is an inner class |
static org.codehaus.groovy.ast.ClassNode
|
nonGeneric(org.codehaus.groovy.ast.ClassNode type)
|
static boolean
|
parametersEqual(org.codehaus.groovy.ast.Parameter[] a, org.codehaus.groovy.ast.Parameter[] b)
@return true if the two arrays are of the same size and have the same contents |
static void
|
warning(org.codehaus.groovy.control.SourceUnit sourceUnit, org.codehaus.groovy.ast.ASTNode node, java.lang.String warningMessage)
|
static void
|
wrapMethodBodyInTryCatchDebugStatements(org.codehaus.groovy.ast.MethodNode methodNode)
Wraps a method body in try / catch logic that catches any errors and logs an error, but does not rethrow! |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Field Detail |
---|
public static final org.codehaus.groovy.syntax.Token ASSIGNMENT_OPERATOR
public static final java.lang.String DOMAIN_DIR
public static final org.codehaus.groovy.syntax.Token EQUALS_OPERATOR
public static final java.lang.String GRAILS_APP_DIR
public static final java.lang.String METHOD_MISSING_METHOD_NAME
public static final org.codehaus.groovy.ast.ClassNode MISSING_METHOD_EXCEPTION
public static final org.codehaus.groovy.syntax.Token NOT_EQUALS_OPERATOR
public static final org.codehaus.groovy.ast.expr.ConstantExpression NULL_EXPRESSION
public static final java.lang.String STATIC_METHOD_MISSING_METHOD_NAME
Method Detail |
---|
public static void addAnnotationIfNecessary(org.codehaus.groovy.ast.ClassNode classNode, nClassNode); java.lang.Class entityClass)
public static void addDelegateConstructor(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode constructorMethod)
classNode
- The class nodeconstructorMethod
- The constructor static method
public static org.codehaus.groovy.ast.MethodNode addDelegateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.Expression delegate, org.codehaus.groovy.ast.MethodNode declaredMethod)
classNode
- The class nodedelegate
- The expression that looks up the delegatedeclaredMethod
- The declared method
public static org.codehaus.groovy.ast.MethodNode addDelegateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.Expression delegate, org.codehaus.groovy.ast.MethodNode declaredMethod, org.codehaus.groovy.ast.AnnotationNode markerAnnotation)
public static org.codehaus.groovy.ast.MethodNode addDelegateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.Expression delegate, org.codehaus.groovy.ast.MethodNode declaredMethod, boolean thisAsFirstArgument)
public static org.codehaus.groovy.ast.MethodNode addDelegateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.expr.Expression delegate, org.codehaus.groovy.ast.MethodNode declaredMethod, org.codehaus.groovy.ast.AnnotationNode markerAnnotation, 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 method
public static void addDelegateInstanceMethods(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ClassNode delegateNode, org.codehaus.groovy.ast.expr.Expression delegateInstance)
public static void addDelegateInstanceMethods(org.codehaus.groovy.ast.ClassNode supportedSuperType, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ClassNode delegateNode, org.codehaus.groovy.ast.expr.Expression delegateInstance)
public static org.codehaus.groovy.ast.MethodNode addDelegateStaticMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode delegateMethod)
classNode
- The class nodedelegateMethod
- The delegate method
public static org.codehaus.groovy.ast.MethodNode addDelegateStaticMethod(org.codehaus.groovy.ast.expr.Expression expression, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode delegateMethod)
expression
- The expressionclassNode
- The class nodedelegateMethod
- The delegate method
public static org.codehaus.groovy.ast.MethodNode addDelegateStaticMethod(org.codehaus.groovy.ast.expr.Expression expression, org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode delegateMethod, org.codehaus.groovy.ast.AnnotationNode markerAnnotation)
expression
- The expressionclassNode
- The class nodedelegateMethod
- The delegate methodmarkerAnnotation
- A marker annotation to be added to all methods
public static org.codehaus.groovy.ast.FieldNode addFieldIfNonExistent(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.ClassNode fieldType, java.lang.String fieldName)
public static void addMethodIfNotPresent(org.codehaus.groovy.ast.ClassNode controllerClassNode, org.codehaus.groovy.ast.MethodNode methodNode)
public static org.codehaus.groovy.ast.expr.ArgumentListExpression createArgumentListFromParameters(org.codehaus.groovy.ast.Parameter[] parameterTypes, boolean thisAsFirstArgument)
parameterTypes
- The parameter typesthisAsFirstArgument
- Whether to include a reference to 'this' as the first argument
public static org.codehaus.groovy.ast.stmt.ExpressionStatement createPrintlnStatement(java.lang.String message)
public static org.codehaus.groovy.ast.stmt.ExpressionStatement createPrintlnStatement(java.lang.String message, java.lang.String variable)
public static void error(org.codehaus.groovy.control.SourceUnit sourceUnit, org.codehaus.groovy.ast.ASTNode astNode, java.lang.String message)
sourceUnit
- the SourceUnitastNode
- the ASTNode which caused the errormessage
- The error message
public static void error(org.codehaus.groovy.control.SourceUnit sourceUnit, org.codehaus.groovy.ast.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 error
public static org.codehaus.groovy.ast.AnnotationNode findAnnotation(org.codehaus.groovy.ast.ClassNode annotationClassNode, java.util.List annotations)
public static org.codehaus.groovy.ast.AnnotationNode findAnnotation(org.codehaus.groovy.ast.ClassNode classNode, java.lang.Class type)
public static org.codehaus.groovy.ast.ConstructorNode findConstructor(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.Parameter[] constructorParams)
classNode
- The class nodeconstructorParams
- The parameter types
public static java.util.Map getAllAssociationMap(org.codehaus.groovy.ast.ClassNode classNode)
public static java.util.Map getAssocationMap(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String associationType)
classNode
- The target class ndoeassociationType
- The associationType
public static java.util.Map getConstraintMetadata(org.codehaus.groovy.ast.expr.ClosureExpression closureExpression)
closureExpression
- the closure expression to evaluate
public static org.codehaus.groovy.ast.ConstructorNode getDefaultConstructor(org.codehaus.groovy.ast.ClassNode classNode)
classNode
- The class node
public static java.lang.String getFullName(org.codehaus.groovy.ast.ClassNode classNode)
classNode
- The class node
public static org.codehaus.groovy.ast.ClassNode getFurthestParent(org.codehaus.groovy.ast.ClassNode classNode)
public static org.codehaus.groovy.ast.ClassNode getFurthestUnresolvedParent(org.codehaus.groovy.ast.ClassNode classNode)
public static org.codehaus.groovy.ast.Parameter[] getRemainingParameterTypes(org.codehaus.groovy.ast.Parameter[] parameters)
parameters
- The parameters
public static boolean hasAnnotation(org.codehaus.groovy.ast.ClassNode classNode, java.lang.Class annotationClass)
classNode
- A ClassNode to inspectannotationClass
- an annotation to look for
public static boolean hasAnyAnnotations(org.codehaus.groovy.ast.ClassNode classNode, java.lang.Class... annotationsToLookFor)
classNode
- a ClassNode to searchannotationsToLookFor
- Annotations to look for
public static boolean hasOrInheritsProperty(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String propertyName)
public static boolean hasProperty(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String propertyName)
classNode
- The ClassNodepropertyName
- The name of the property
@SuppressWarnings("rawtypes") public static boolean implementsOrInheritsZeroArgMethod(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String methodName, java.util.List ignoreClasses)
public static boolean implementsZeroArgMethod(org.codehaus.groovy.ast.ClassNode classNode, java.lang.String methodName)
classNode
- The ClassNodemethodName
- The method name
public static boolean isCandidateInstanceMethod(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.ast.MethodNode declaredMethod)
public static boolean isCandidateMethod(org.codehaus.groovy.ast.MethodNode declaredMethod)
public static boolean isConstructorMethod(org.codehaus.groovy.ast.MethodNode declaredMethod)
public static boolean isDomainClass(org.codehaus.groovy.ast.ClassNode classNode, org.codehaus.groovy.control.SourceUnit sourceNode)
public static boolean isInnerClassNode(org.codehaus.groovy.ast.ClassNode classNode)
classNode
- The class node
public static org.codehaus.groovy.ast.ClassNode nonGeneric(org.codehaus.groovy.ast.ClassNode type)
public static boolean parametersEqual(org.codehaus.groovy.ast.Parameter[] a, org.codehaus.groovy.ast.Parameter[] b)
public static void warning(org.codehaus.groovy.control.SourceUnit sourceUnit, org.codehaus.groovy.ast.ASTNode node, java.lang.String warningMessage)
public static void wrapMethodBodyInTryCatchDebugStatements(org.codehaus.groovy.ast.MethodNode methodNode)
methodNode
- The method node
Groovy Documentation