26
A Walkthrough of Groovy AST Transformations

A Walkthrough of Groovy AST Transformations

Embed Size (px)

Citation preview

A Walkthrough of Groovy

AST Transformations

www.canoo.com 2

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 3

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

Available in Groovy 1.7

www.canoo.com 5

@Delegate

www.canoo.com 6

@Singleton

www.canoo.com 7

@Immutable

www.canoo.com 8

@Category

www.canoo.com 9

@Mixin

www.canoo.com 10

@Grab

www.canoo.com 11

@Synchronized

www.canoo.com 12

@Lazy

www.canoo.com 13

@Newify

www.canoo.com 14

@Bindable (Vetoable)

www.canoo.com

Available in Groovy 1.8

www.canoo.com 16

@Log (@Commons @Log4j @Slf4j)

www.canoo.com 17

@InheritConstructors

www.canoo.com 18

@ToString

www.canoo.com 19

@EqualsAndHashCode

www.canoo.com 20

@TupleConstructor

www.canoo.com 21

@Canonical

๏  Merges @ToString, @EqualsAndHashCode and @TupleConstructor

๏  Allows specific tweaks per annotation

www.canoo.com 22

@IndexedProperty

www.canoo.com 23

And there are many more…

๏  @AutoClone

๏  @AutoExternalize

๏  @ConditionalInterrupt @TimedInterrupt @ThreadInterrupt

๏  @PackageScope

๏  @WithReadLock @WithWriteLock

๏  @Field

www.canoo.com 24

Found in other projects

๏  . ‣ @Entity

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

๏  Modules ‣ @Scalify ‣ @Bytecode

๏  Groovy++ ‣ @Typed

www.canoo.com

http://people.canoo.com/share

25

Thank you!

twitter: @aalmiray