[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question on AST transformations

Answers below

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

       @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 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.