❯ Guillaume Laforge

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.

Joachim Baumann, Groovy committer and German Groovy book author, wrote a very nice series of articles on the topic of authoring AST transformations, covering:

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.