Groovy AST transformations tutorials
Groovy is a powerful language that gives the opportunity to its users to plugin into the compilation process to create what we call AST transformations, ie. the ability to customize the Abstract Syntax Tree representing your programs before the compiler walks this tree to generate Java bytecode.
Since Groovy 1.6, many useful such transformations have been added to Groovy, like @Delegate to implement delegation, @Immutable to make your types immutable, or @Grab to add dependencies to your scripts, and many more. However, mastering the Groovy AST and compiler APIs is not such a simple task, and requires some advanced knowledge of the inner workings of Groovy.
- compiler phases and syntax trees
- prerequisites and annotations
- the implementation of the example transformation itself
- testing and error messages
- creating a complex AST transformation
If you’re interested in writing your own transformations, those very well written articles are really a great start that should get you up to speed very rapidly.