A Walkthrough
     of Groovy
AST Transformations
About the speaker
๏  Java developer since the beginning

๏  True believer in Open Source

๏  Groovy committer since 2007

๏  Project lead of the Griffon framework

๏  Currently working for




www.canoo.com                              2
What are AST Transformations?

๏  Essentially byte code generation

๏  They enable compile-time metaprogramming

๏  Groovy has two types of AST transformations: global and local




www.canoo.com                                                      3
Available in Groovy 1.7




www.canoo.com
@Delegate




www.canoo.com   5
@Singleton




www.canoo.com   6
@Immutable




www.canoo.com   7
@Category




www.canoo.com   8
@Mixin




www.canoo.com   9
@Grab




www.canoo.com   10
@Synchronized




www.canoo.com   11
@Lazy




www.canoo.com   12
@Newify




www.canoo.com   13
@Bindable (Vetoable)




www.canoo.com          14
Available in Groovy 1.8




www.canoo.com
@Log (@Commons @Log4j @Slf4j)




www.canoo.com                   16
@InheritConstructors




www.canoo.com          17
@ToString




www.canoo.com   18
@EqualsAndHashCode




www.canoo.com        19
@TupleConstructor




www.canoo.com       20
@Canonical

๏  Merges @ToString, @EqualsAndHashCode and @TupleConstructor

๏  Allows specific tweaks per annotation




www.canoo.com                                                   21
@IndexedProperty




www.canoo.com      22
And there are many more…

๏  @AutoClone

๏  @AutoExternalize

๏  @ConditionalInterrupt @TimedInterrupt @ThreadInterrupt

๏  @PackageScope

๏  @WithReadLock @WithWriteLock

๏  @Field




www.canoo.com                                               23
Found in other projects

๏  .
     ‣  @Entity

๏  .
     ‣  @EventPublisher
     ‣  @Listener
     ‣  @Entity
     ‣  @Scaffold

๏  Modules
     ‣  @Scalify
     ‣  @Bytecode

๏  Groovy++
     ‣  @Typed
www.canoo.com             24
http://people.canoo.com/share




www.canoo.com                                   25
Thank you!

twitter: @aalmiray

A Walkthrough of Groovy AST Transformations