ast transformations: groovy’s best kept secret by andres almiray
TRANSCRIPT
AST TRANSFORMATIONS: GROOVY’S BEST KEPT SECRET ANDRES ALMIRAY @AALMIRAY
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
AGENDA AST, How did we get here?
AST Transformations
Building your own AST
AST, HOW DID WE GET HERE?
AST TRANSFORMATIONS
E V I L
G E N I U S
STANDARD GROOVY DISTRO INCLUDES: * @EqualsAndHashCode * @ToString * @TupleConstructor * @Canonical * @InheritConstructors * @IndexedProperty * @Lazy * @PackageScope * @NotYetImplemented
* @AutoClone * @AutoExternalize * @Synchronized * @Field * @Grab * @GrabResolver * @CompileStatic * @TypeChecked * @ASTTest
STANDARD GROOVY DISTRO INCLUDES: * @Bindable * @Vetoable * @ListenerList * @ConditionalInterrupt * @ThreadInterrupt * @TimedInterrupt * @WithReadLock * @WithWriteLock * @Newify
* @Log * @Slf4j * @Log4j * @Commons * @Singleton * @Immutable * @Delegate * @Category * @Mixin
GROOVY ECOSYSTEM BRINGS: * @ByteCode * @Scalify * GContracts * @Invariant * @Requires * @Ensures * Grails * @Entity * @TestFor
* Griffon * @EventPublisher * @Threading * @PropertyListener * @MVCAware * @MessageSourceAware * @ResourceResolverAware * @ResourcesAware * @ThreadingAware
GLOBAL AST TRANSFORMATIONS Groovy – Grab
Grails – GORM API
Griffon – Threading injection
Spock – the whole shebang
BUILDING YOUR OWN AST
LOCAL AST TRANSFORMATION 1. Define an @interface
• Easy peasy … right? 2. Define AST implementation
• huh …… 3. Profit!
GLOBAL AST TRANSFORMATION 1. Add AST implementation entry to
• META-INF/services/org.codehaus.groovy.transform.ASTTransformation
2. Define AST implementation
• ??? !!! ??? !!! 3. Profit!
ADDITIONAL TOOLS AST browser
AST Builder
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
Thank You! @aalmiray