Have you ever come across a situation where you want to auto inject a common method or field at compile time to set of classes? AST Transformations is the solution.
AST Transformations provide a wonderful way of manipulating code at compile time via modifications in Abstract Syntax Tree. AST Transformations provides Groovy with improved compile-time meta programming capabilities allowing powerful flexibility at the language level, without a runtime performance penalty.
In this session I would be discussing what AST Transformations are and what can be achieved using it. I will be discussing two kinds of transformations :
- Global Transformations
- Local Transformations
I will discuss predefined annotations in Groovy which uses AST Transformations for necessary code generations e.g. @Delegate, @Immutable, @Singleton, @Newify etc.
Apart from this I will showcase a Case Study for writing custom AST Transformations and it’s benefits.