groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <>
Subject Re: question on AST transformations
Date Fri, 01 Jun 2018 03:26:49 GMT
Answers below

On Fri, Jun 1, 2018 at 7:57 AM, <> 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:

>    2. Suppose I want to use the annotation WithLogging of
>    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
>    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.

View raw message