@Documented @Retention(RetentionPolicy.SOURCE) @Target({ElementType.PACKAGE, ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}) @GroovyASTTransformationClass("org.codehaus.groovy.transform.ASTTestTransformation") public @interface ASTTest
This AST transformation aims at helping in debugging other AST transformations. It provides a basic infrastructure for performing tests on AST nodes. You can place this annotation on any node which accepts an annotation (types, methods, annotations, constructors, fields, local variables, packages or parameters), then use a script which is run against this AST node at a specific phase. For example, you could test the Field AST transformation this way:
import groovy.transform.*The closure code is executed after the specified phase has completed. If no phase is provided, then the code is executed after the semantic analysis phase and each subsequent phase.@ASTTest(value = { def owner = node.declaringClass assert owner.fields.any { it.name == 'x' } })@Field int x
The node variable refers to the AST node where the AST test annotation is put. In the previous example,
it means that node refers to the declaration "int x".
Because the closure is evaluated during compilation, merely compiling source which carries this
annotation executes that code, whether or not the compiled result is subsequently run. Setting the
groovy.asttest.enable system property to false makes the annotation a no-op, in the same
way that groovy.grape.enable turns off @Grab dependency resolution. Consider doing so when
compiling source you do not control; see the Apache Groovy
threat model for what compiling
such source does and does not imply.
| Type | Name and Description |
|---|---|
Class<? extends Closure<?>> |
valueA closure which is executed against the annotated node after the specified phase has completed. |
| Type | Name and Description |
|---|---|
CompilePhase |
phaseThe compile phase after which the test code should run. |
The compile phase after which the test code should run.