class ASTTransformationCustomizer extends CompilationCustomizer
This customizer allows applying an AST transformation to a source unit with several strategies. Creating a customizer with the class constructor will trigger an AST transformation for each class node of a source unit. However, you cannot pass parameters to the annotation so the default values will be used. Writing :
def configuration = new CompilerConfiguration() configuration.addCompilationCustomizers(new ASTTransformationCustomizer(Log)) def shell = new GroovyShell(configuration) shell.evaluate(""" class MyClass { }""")is equivalent to :
def shell = new GroovyShell() shell.evaluate(""" @Log class MyClass { }""")The class passed as a constructor parameter must be an AST transformation annotation. Alternatively, you can apply a global AST transformation by calling the AST transformation. In that case, the transformation is applied once for the whole source unit. Unlike a global AST transformation declared in the META-INF/services/org.codehaus.groovy.transform.ASTTransformation file, which are applied if the file is in the classpath, using this customizer you'll have the choice to apply your transformation selectively. It can also be useful to debug global AST transformations without having to package your annotation in a jar file.
Modifiers | Name | Description |
---|---|---|
protected org.codehaus.groovy.control.CompilationUnit |
compilationUnit |
Type | Name and description |
---|---|
ASTTransformation |
transformation |
Constructor and description |
---|
ASTTransformationCustomizer
(Class<? extends Annotation> transformationAnnotation, String astTransformationClassName, ClassLoader transformationClassLoader) Creates an AST transformation customizer using the specified annotation. |
ASTTransformationCustomizer
(Class<? extends Annotation> transformationAnnotation, String astTransformationClassName) Creates an AST transformation customizer using the specified annotation. |
ASTTransformationCustomizer
(Map annotationParams, Class<? extends Annotation> transformationAnnotation, String astTransformationClassName, ClassLoader transformationClassLoader) Creates an AST transformation customizer using the specified annotation. |
ASTTransformationCustomizer
(Map annotationParams, Class<? extends Annotation> transformationAnnotation, String astTransformationClassName) |
ASTTransformationCustomizer
(Class<? extends Annotation> transformationAnnotation, ClassLoader transformationClassLoader) Creates an AST transformation customizer using the specified annotation. |
ASTTransformationCustomizer
(Class<? extends Annotation> transformationAnnotation) Creates an AST transformation customizer using the specified annotation. |
ASTTransformationCustomizer
(ASTTransformation transformation) Creates an AST transformation customizer using the specified transformation. |
ASTTransformationCustomizer
(Map annotationParams, Class<? extends Annotation> transformationAnnotation, ClassLoader transformationClassLoader) Creates an AST transformation customizer using the specified annotation. |
ASTTransformationCustomizer
(Map annotationParams, Class<? extends Annotation> transformationAnnotation) |
ASTTransformationCustomizer
(Map annotationParams, ASTTransformation transformation) |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
call(org.codehaus.groovy.control.SourceUnit source, GeneratorContext context, ClassNode classNode) |
|
void |
setAnnotationParameters(Map<String, Object> params) Specify annotation parameters. |
|
void |
setCompilationUnit(org.codehaus.groovy.control.CompilationUnit unit) |
Methods inherited from class | Name |
---|---|
class CompilationCustomizer |
getPhase |
class org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation |
org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#needSortedInput(), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#call(org.codehaus.groovy.control.SourceUnit, org.codehaus.groovy.classgen.GeneratorContext, org.codehaus.groovy.ast.ClassNode), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#wait(long), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#wait(long, int), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#wait(), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#equals(java.lang.Object), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#toString(), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#hashCode(), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#getClass(), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#notify(), org.codehaus.groovy.control.CompilationUnit$PrimaryClassNodeOperation#notifyAll() |
Creates an AST transformation customizer using the specified annotation. The transformation classloader can
be used if the transformation class cannot be loaded from the same class loader as the annotation class.
It's assumed that the annotation is not annotated with GroovyASTTransformationClass
and so the
second argument supplies the link to the ASTTransformation class that should be used.
Creates an AST transformation customizer using the specified annotation. It's assumed that the annotation
is not annotated with GroovyASTTransformationClass
and so the second argument supplies the link to
the ASTTransformation class that should be used.
Creates an AST transformation customizer using the specified annotation. The transformation classloader can
be used if the transformation class cannot be loaded from the same class loader as the annotation class.
Additionally, you can pass a map of parameters that will be used to parameterize the annotation.
It's assumed that the annotation is not annotated with GroovyASTTransformationClass
and so the
second argument supplies the link to the ASTTransformation class that should be used.
Creates an AST transformation customizer using the specified annotation. The transformation classloader can be used if the transformation class cannot be loaded from the same class loader as the annotation class.
Creates an AST transformation customizer using the specified annotation.
Creates an AST transformation customizer using the specified transformation.
Creates an AST transformation customizer using the specified annotation. The transformation classloader can be used if the transformation class cannot be loaded from the same class loader as the annotation class. Additionally, you can pass a map of parameters that will be used to parameterize the annotation.
Specify annotation parameters. For example, if the annotation is :
@Log(value='logger')You could create an AST transformation customizer and specify the "value" parameter thanks to this method:
annotationParameters = [value: 'logger'] Note that you cannot specify annotation closure values directly. If the annotation you want to add takes a closure as an argument, you will have to set a ClosureExpression instead. This can be done by either creating a custom ClosureExpression from code, or using the AstBuilder. Here is an example :// add @Contract({distance >= 0 }) customizer = new ASTTransformationCustomizer(Contract) final expression = new AstBuilder().buildFromCode(CompilePhase.CONVERSION) {-> distance >= 0 }.expression[0] customizer.annotationParameters = [value: expression]
params
- the annotation parametersCopyright © 2003-2018 The Apache Software Foundation. All rights reserved.