ast transformations: groovy’s best kept secret by andres almiray

46
AST TRANSFORMATIONS: GROOVY’S BEST KEPT SECRET ANDRES ALMIRAY @AALMIRAY

Upload: zeroturnaround

Post on 10-May-2015

587 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: AST Transformations: Groovy’s best kept secret by Andres Almiray

AST TRANSFORMATIONS: GROOVY’S BEST KEPT SECRET ANDRES ALMIRAY @AALMIRAY

Page 2: AST Transformations: Groovy’s best kept secret by Andres Almiray

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: AST Transformations: Groovy’s best kept secret by Andres Almiray

AGENDA AST, How did we get here?

AST Transformations

Building your own AST

Page 4: AST Transformations: Groovy’s best kept secret by Andres Almiray

AST, HOW DID WE GET HERE?

Page 5: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 6: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 7: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 8: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 9: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 10: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 11: AST Transformations: Groovy’s best kept secret by Andres Almiray

AST TRANSFORMATIONS

Page 12: AST Transformations: Groovy’s best kept secret by Andres Almiray

E V I L

G E N I U S

Page 13: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 14: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 15: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 16: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 17: AST Transformations: Groovy’s best kept secret by Andres Almiray

STANDARD GROOVY DISTRO INCLUDES: *  @EqualsAndHashCode *  @ToString *  @TupleConstructor *  @Canonical *  @InheritConstructors *  @IndexedProperty *  @Lazy *  @PackageScope *  @NotYetImplemented

*  @AutoClone *  @AutoExternalize *  @Synchronized *  @Field *  @Grab *  @GrabResolver *  @CompileStatic *  @TypeChecked *  @ASTTest

Page 18: AST Transformations: Groovy’s best kept secret by Andres Almiray

STANDARD GROOVY DISTRO INCLUDES: *  @Bindable *  @Vetoable *  @ListenerList *  @ConditionalInterrupt *  @ThreadInterrupt *  @TimedInterrupt *  @WithReadLock *  @WithWriteLock *  @Newify

*  @Log *  @Slf4j *  @Log4j *  @Commons *  @Singleton *  @Immutable *  @Delegate *  @Category *  @Mixin

Page 19: AST Transformations: Groovy’s best kept secret by Andres Almiray

GROOVY ECOSYSTEM BRINGS: *  @ByteCode *  @Scalify *  GContracts *  @Invariant *  @Requires *  @Ensures *  Grails *  @Entity *  @TestFor

*  Griffon *  @EventPublisher *  @Threading *  @PropertyListener *  @MVCAware *  @MessageSourceAware *  @ResourceResolverAware *  @ResourcesAware *  @ThreadingAware

Page 20: AST Transformations: Groovy’s best kept secret by Andres Almiray

GLOBAL AST TRANSFORMATIONS Groovy – Grab

Grails – GORM API

Griffon – Threading injection

Spock – the whole shebang

Page 21: AST Transformations: Groovy’s best kept secret by Andres Almiray

BUILDING YOUR OWN AST

Page 22: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 23: AST Transformations: Groovy’s best kept secret by Andres Almiray

LOCAL AST TRANSFORMATION 1.  Define an @interface

•  Easy peasy … right? 2.  Define AST implementation

•  huh …… 3.  Profit!

Page 24: AST Transformations: Groovy’s best kept secret by Andres Almiray

GLOBAL AST TRANSFORMATION 1.  Add AST implementation entry to

• META-INF/services/org.codehaus.groovy.transform.ASTTransformation

2.  Define AST implementation

•  ??? !!! ??? !!! 3.  Profit!

Page 25: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 26: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 27: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 28: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 29: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 30: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 31: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 32: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 33: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 34: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 35: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 36: AST Transformations: Groovy’s best kept secret by Andres Almiray

ADDITIONAL TOOLS AST browser

AST Builder

Page 37: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 38: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 39: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 40: AST Transformations: Groovy’s best kept secret by Andres Almiray

DOCS? DON’T MIND IF I DO https://github.com/melix/ast-workshop

Setup gradle 1.6 (or use gradlew)

Browse docs/gen/workshop.html

Page 41: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 42: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 43: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 44: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 45: AST Transformations: Groovy’s best kept secret by Andres Almiray
Page 46: AST Transformations: Groovy’s best kept secret by Andres Almiray

Thank You! @aalmiray

[email protected]