Answers below
On Fri, Jun 1, 2018 at 7:57 AM, [email protected] <
[email protected]> wrote:
>
> I am writing an article on metaprogramming and have several questions
> on Groovy. I would thank any help with them.
>
> 1. Is there any example in which @GroovyASTTransformationClass takes an
> array with more
> than one element? Something like this:
>
> @Retention(RetentionPolicy.SOURCE)
> @Target([ElementType.TYPE])
> @GroovyASTTransformationClass( [FirstTransformation,
> SecondTransformation] )
> @interface MyAnnot { }
>
> I could not find one. If this is possible, I suppose that a single
> annotation
> can apply transformations in several compiler phase
>
Yes, this is possible. Examples in the Groovy codebase:
src/test/org/codehaus/groovy/transform/LocalASTTransformTest.groovy
src/test/groovy/bugs/G3839A2.java
>
> 2. Suppose I want to use the annotation WithLogging of
> http://groovy-lang.org/metaprogramming.html#developing-ast-xforms
> All I have is the Groovy compiler, a .exe file. What do I do? The
> general question is: how the Groovy compiler finds a **local** AST
> transformation class? For global transformation the page above says
>
> Compiled classes that implement global transformations are in a JAR
> added to the classpath of the compiler and contain service locator file
> META-INF...
>
> But for local transformations, there is no such observation.
>
You need the annotation definition and transformation class in your
classpath. The annotation annotating your code is what triggers the
compiler to invoke the transformation.
Cheers, Paul.