Top Banner
Groovy AST Demystified Andres Almiray Canoo Engineering AG
41

Groovy AST Demystified

Apr 15, 2017

Download

Technology

Andres Almiray
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Groovy AST Demystified

Groovy AST Demystified

Andres Almiray Canoo Engineering AG

Page 2: Groovy AST Demystified

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

Page 3: Groovy AST Demystified

Agenda ¡ AST, How did we get here?

¡ AST Transformations

¡  Building your own AST

Page 4: Groovy AST Demystified

AST, how did we get here?

Page 5: Groovy AST Demystified
Page 6: Groovy AST Demystified
Page 7: Groovy AST Demystified
Page 8: Groovy AST Demystified
Page 9: Groovy AST Demystified
Page 10: Groovy AST Demystified
Page 11: Groovy AST Demystified

AST Transformations

Page 12: Groovy AST Demystified

E V I L

G E N I U S

Page 13: Groovy AST Demystified
Page 14: Groovy AST Demystified
Page 15: Groovy AST Demystified
Page 16: Groovy AST Demystified

Standard Groovy Distro includes: ¡  @EqualsAndHashCode

¡  @ToString

¡  @TupleConstructor

¡  @Canonical

¡  @InheritConstructors

¡  @IndexedProperty

¡  @Lazy

¡  @PackageScope

¡  @NotYetImplemented

¡  @AutoClone

¡  @AutoExternalize

¡  @Synchronized

¡  @Field

¡  @Grab

¡  @GrabResolver

¡  @CompileStatic

¡  @TypeChecked

Page 17: Groovy AST Demystified

Standard Groovy Distro includes: ¡  @Bindable

¡  @Vetoable

¡  @ListenerList

¡  @ConditionalInterrupt

¡  @ThreadInterrupt

¡  @TimedInterrupt

¡  @WithReadLock

¡  @WithWriteLock

¡  @Newify

¡  @Log

¡  @Slf4j

¡  @Log4j

¡  @Commons

¡  @Singleton

¡  @Immutable

¡  @Delegate

¡  @Category

¡  @Mixin

Page 18: Groovy AST Demystified

Groovy Ecosystem brings: ¡  @ByteCode

¡  @Scalify

¡  GContracts

¡  @Invariant

¡  @Requires

¡  @Ensures

¡  Grails

¡  @Entity

¡  @TestFor

¡  Griffon

¡  @EventPublisher

¡  @Threading

¡  @PropertyListener

¡  @MVCAware

¡  @MessageSourceAware

¡  @ResourceResolverAware

¡  @ResourcesAware

¡  @ThreadingAware

Page 19: Groovy AST Demystified

Global AST transformations ¡ Groovy – Grab

¡ Grails – GORM API

¡ Griffon – Threading injection

¡  Spock – the whole shebang

Page 20: Groovy AST Demystified

Building your own AST

Page 21: Groovy AST Demystified
Page 22: Groovy AST Demystified

Local AST Transformation 1.  Define an @interface ¡  Easy peasy … right?

2.  Define AST implementation ¡  huh ……

3.  Profit!

Page 23: Groovy AST Demystified

Global AST Transformation 1.  Define AST implementation ¡  ??? !!! ??? !!!

2.  Add AST implementation entry to ¡  META-INF/services/

org.codehaus.groovy.transform.ASTTransformation

3.  Profit!

Page 24: Groovy AST Demystified
Page 25: Groovy AST Demystified
Page 26: Groovy AST Demystified
Page 27: Groovy AST Demystified
Page 28: Groovy AST Demystified
Page 29: Groovy AST Demystified
Page 30: Groovy AST Demystified
Page 31: Groovy AST Demystified
Page 32: Groovy AST Demystified
Page 33: Groovy AST Demystified
Page 34: Groovy AST Demystified

Additional Tools ¡ AST browser

¡ AST Builder

Page 35: Groovy AST Demystified
Page 36: Groovy AST Demystified
Page 37: Groovy AST Demystified
Page 38: Groovy AST Demystified
Page 39: Groovy AST Demystified
Page 40: Groovy AST Demystified
Page 41: Groovy AST Demystified

Thank You! @aalmiray

[email protected]