Re: [groovy-dev] AST Transformations status
AST Transformation are in Groovy 1.6-beta-1, and the first examples of them are the <at> groovy.beans.Bindable, <at> groovy.beans.Vetoable, and <at> groovy.lang.Mixin annotations. and in the current dev releases there is also <at> groovy.lang.Category. The best way to get a feel for them is to look at those examples.
As compared to Jocen's posts the transformations are not quite the same. The transformation class follows the spirit of what Jocen wanted, but that is about the extent. The first change is that you do not use a different import statement to declare a transformation. You use an annotation that is a transformation annotation (an annotation on the annotation declares this). Not useing an import statement restricts us to using grammer symbols with a strictly static meaning at compile time to insure we are transforming what we should be. So transforming method calls basically won't work then in this case, since the MOP can redirect any method call done from groovy code. The import mechanic used to designate a symbol name was a solution that would
allow us to transform on such ordinarily dynamic symbols, but the response on the dev list.
As far as using a transform to remove import statements, the current implementation basically preculdes it since the transform is not run until after hte imports are resolved, and the DSL class would start failing because the classes wouldn't be guaranteed to be resolved early enough. There is some affordance for that by adding transforms via the Java services API (basically adding a file in a particular palce in META-INF in the jar), but that doesn't have any concerte example in groovy core. A half-baked example exists in the grape-ivy modeule in the SVN tree of having <at> Grab add jars to the classpath so the imports work. But you may be able to add the imports by directly manipulating some of the AST structures and insureing that the annotation you are marking
the DSL with is evaluated first.
--Danno
--
------------------------------------------------------
I'm Danno Ferrin, and I approved this message.