SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
Groovy	
  AST	
  
Agenda	
  
•  Local	
  ASTTransforma5ons	
  
   –  Groovy	
  
   –  Grails	
  
   –  Griffon	
  
•  Como	
  funcionan?	
  
•  Otras	
  formas	
  de	
  modificar	
  AST	
  
LISTADO	
  DE	
  TRANSFORMACIONES	
  
DE	
  AST	
  (NO	
  EXHAUSTIVO)	
  
@Singleton	
  
@Singleton
class AccountManager {
  void process(Account account) { ... }
}


def account = new Account()
AccountManager.instance.process(account)
@Delegate	
  
class Event {
  @Delegate Date when
  String title, url
}

df = new SimpleDateFormat("MM/dd/yyyy")
so2gx = new Event(title: "SpringOne2GX",
   url: "http://springone2gx.com",
   when: df.parse("10/19/2010"))
oredev = new Event(title: "Oredev",
   url: "http://oredev.org",
   when: df.parse("11/02/2010"))
assert oredev.after(so2gx.when)
@Immutable	
  
@Immutable
class Person {
  String name
}


def person1 = new Person("ABC")
def person2 = new Person(name: "ABC")
assert person1 == person2
person1.name = "Boom!” // error!
@Category	
  
@Category(Integer)
class Pouncer {
  String pounce() {
     (1..this).collect([]) {
        'boing!' }.join(' ')
  }
}

use(Pouncer) {
  3.pounce() // boing! boing! boing!
}
@Mixin	
  
class Pouncer {
  String pounce() {
     (1..this.times).collect([]) {
        'boing!' }.join(' ')
  }
}

@Mixin(Pouncer)
class Person{
  int times
}

person1 = new Person(times: 2)
person1.pounce() // boing! boing!
@Grab	
  
@Grab('net.sf.json-lib:json-lib:2.3:jdk15')
def builder = new
net.sf.json.groovy.JsonGroovyBuilder()

def books = builder.books {
  book(title: "Groovy in Action",
       name: "Dierk Koenig")
}

assert books.name == ["Dierk Koenig"]
@Log	
  
@groovy.util.logging.Log
class Person {
  String name
  void talk() {
    log.info("$name is talking…")
  }
}

def person = new Person(name: "Duke")
person.talk()
// Oct 7, 2010 10:36:09 PM sun.reflect.NativeMethodAccessorImpl invoke0
// INFO: Duke is talking…	
  
@InheritConstructors	
  
@groovy.transform.InheritConstructors
class MyException extends RuntimeException {}


def x1 = new MyException("Error message")
def x2 = new MyException(x1)
assert x2.cause == x1
@Canonical	
  
@groovy.transform.Canonical
class Person {
    String name
}

def person1 = new Person("Duke")
def person2 = new Person(name: "Duke")
assert person1 == person2
person2.name = "Tux"
assert person1 != person2
@Scalify	
  
trait Output {
   @scala.reflect.BeanProperty
   var output:String = ""
}


@groovyx.transform.Scalify
class GroovyOutput implements Output {
    String output
}
@En5ty	
  
@grails.persistence.Entity
class Book {
  String title
}


def book = new Book().save()
assert book.id
assert book.version
@Bindable	
  
@groovy.beans.Bindable
class Book {
  String title
}

def book = new Book()
book.addPropertyChangeListener({e ->
  println "$e.propertyName $e.oldValue ->
$e.newValue"
} as java.beans.PropertyChangeListener)
book.title = "Foo” // prints "title Foo"
book.title = "Bar” // prints "title Foo Bar"
@Listener	
  
@groovy.beans.Bindable
class Book {
  @griffon.beans.Listener(snooper)
  String title
  private snooper = {e ->
    println "$e.propertyName $e.oldValue ->
$e.newValue"
  }
}

def book = new Book()
book.title = "Foo" // prints "title Foo"
book.title = "Bar" // prints "title Foo Bar"
@EventPublisher	
  
@Singleton
@griffon.util.EventPublisher
class AccountManager {
  void process(Account account) {
      publishEvent("AccountProcessed", [account)]
  }
}
def am = AccountManager.instance
am.addEventListener("AccountProcessed") { account ->
    println "Processed account $account"
}
def acc = new Account()
AccountManager.instance.process(acc)
// prints "Processed account Account:1"
@Scaffold	
  
class Book {
  String title
}

@griffon.presentation.Scaffold
class BookBeanModel {}

def model = new BookBeanModel()
def book = new Book(title: "Foo")
model.value = book
assert book.title == model.title.value
model.value = null
assert !model.title.value
assert model.title
@En5ty	
  
@griffon.persistence.Entity(‘gsql’)
class Book {
  String title
}


def book = new Book().save()
assert book.id
assert book.version
Y	
  otras	
  tantas	
  …	
  
•  @PackageScope	
  
•  @Lazy	
  
•  @Newify	
  
•  @Field	
  
•  @Synchronized	
  
•  @Vetoable	
  
•  @ToString,	
  @EqualsAndHashCode,	
  
   @TupleConstructor	
  
•  @AutoClone,	
  @AutoExternalize	
  
•  …	
  
LA	
  RECETA	
  SECRETA	
  PARA	
  HACER	
  
TRANSFORMACIONES	
  DE	
  AST	
  
1	
  Definir	
  interface	
  
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.FIELD, ElementType.TYPE})
@GroovyASTTransformationClass
("org.codehaus.griffon.ast.ListenerASTTransformation
")
public @interface Listener {
    String value();
}
2	
  Implementar	
  la	
  transformacion	
  
import org.codehaus.groovy.control.CompilePhase;
import org.codehaus.groovy.transform.ASTTransformation;
import org.codehaus.groovy.transform.GroovyASTTransformation;


@GroovyASTTransformation(phase=CompilationPhase.CANONICALIZATION)
public class ListenerASTTransformation
           implements ASTTransformation {
    public void visit(ASTNode[] nodes, SourceUnit source) {
        // MAGIC GOES HERE, REALLY! =)
    }
}
3	
  Anotar	
  el	
  codigo	
  
@groovy.beans.Bindable
class Book {
  @griffon.beans.Listener(snooper)
  String title
    private snooper = {e ->
      // awesome code …
    }
}
OTRO	
  TIPO	
  DE	
  
TRANSFORMACIONES	
  
GContracts	
  
Spock	
  
CodeNarc	
  
Griffon	
  
Gracias!	
  

        @aalmiray	
  
hXp://jroller.com/aalmiray	
  

Weitere ähnliche Inhalte

Was ist angesagt?

Book integrated assignment
Book integrated assignmentBook integrated assignment
Book integrated assignment
Akash gupta
 

Was ist angesagt? (20)

05. haskell streaming io
05. haskell streaming io05. haskell streaming io
05. haskell streaming io
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mule esb - How to convert from Json to Object in 5 minutes
Mule esb - How to convert from Json to Object in 5 minutesMule esb - How to convert from Json to Object in 5 minutes
Mule esb - How to convert from Json to Object in 5 minutes
 
Converting with custom transformer
Converting with custom transformerConverting with custom transformer
Converting with custom transformer
 
Converting with custom transformer part 2
Converting with custom transformer part 2Converting with custom transformer part 2
Converting with custom transformer part 2
 
JSON and The Argonauts
JSON and The ArgonautsJSON and The Argonauts
JSON and The Argonauts
 
Code Samples & Screenshots
Code Samples & ScreenshotsCode Samples & Screenshots
Code Samples & Screenshots
 
Book integrated assignment
Book integrated assignmentBook integrated assignment
Book integrated assignment
 
laravel-53
laravel-53laravel-53
laravel-53
 
Nginx cache api delete
Nginx cache api deleteNginx cache api delete
Nginx cache api delete
 
Mule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutesMule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutes
 
Gogo shell
Gogo shellGogo shell
Gogo shell
 
Javascript forloop-let
Javascript forloop-letJavascript forloop-let
Javascript forloop-let
 
The love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with XamarinThe love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with Xamarin
 
Mastering the MongoDB Shell
Mastering the MongoDB ShellMastering the MongoDB Shell
Mastering the MongoDB Shell
 
Clojure functions
Clojure functionsClojure functions
Clojure functions
 
Json perl example
Json perl exampleJson perl example
Json perl example
 
Modern Networking with Swish
Modern Networking with SwishModern Networking with Swish
Modern Networking with Swish
 
jrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeusjrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeus
 
Q
QQ
Q
 

Andere mochten auch

GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
Andres Almiray
 
Polyglot Programming @ CONFESS
Polyglot Programming @ CONFESSPolyglot Programming @ CONFESS
Polyglot Programming @ CONFESS
Andres Almiray
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVM
Andres Almiray
 
Professional Testimonials and Endorsements
Professional Testimonials and EndorsementsProfessional Testimonials and Endorsements
Professional Testimonials and Endorsements
Darren Huff
 
Cpm 003-2012-cgr
Cpm 003-2012-cgrCpm 003-2012-cgr
Cpm 003-2012-cgr
igor___
 
Un Paseo por las Transformaciones AST de Groovy
Un Paseo por las Transformaciones AST de GroovyUn Paseo por las Transformaciones AST de Groovy
Un Paseo por las Transformaciones AST de Groovy
Andres Almiray
 
Javaone - Getting Funky with Groovy
Javaone - Getting Funky with GroovyJavaone - Getting Funky with Groovy
Javaone - Getting Funky with Groovy
Andres Almiray
 

Andere mochten auch (20)

GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilder
 
Svcc Groovy Testing
Svcc Groovy TestingSvcc Groovy Testing
Svcc Groovy Testing
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Polyglot Programming @ CONFESS
Polyglot Programming @ CONFESSPolyglot Programming @ CONFESS
Polyglot Programming @ CONFESS
 
Polyglot Programming in the JVM
Polyglot Programming in the JVMPolyglot Programming in the JVM
Polyglot Programming in the JVM
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
Gradle: Harder, Stronger, Better, Faster
Gradle: Harder, Stronger, Better, FasterGradle: Harder, Stronger, Better, Faster
Gradle: Harder, Stronger, Better, Faster
 
Griffon: what's new and what's coming
Griffon: what's new and what's comingGriffon: what's new and what's coming
Griffon: what's new and what's coming
 
Professional Testimonials and Endorsements
Professional Testimonials and EndorsementsProfessional Testimonials and Endorsements
Professional Testimonials and Endorsements
 
Android slides
Android slidesAndroid slides
Android slides
 
Auto Instruccional Ofimática
Auto Instruccional Ofimática Auto Instruccional Ofimática
Auto Instruccional Ofimática
 
PerfilNautico42
PerfilNautico42PerfilNautico42
PerfilNautico42
 
Cpm 003-2012-cgr
Cpm 003-2012-cgrCpm 003-2012-cgr
Cpm 003-2012-cgr
 
Un Paseo por las Transformaciones AST de Groovy
Un Paseo por las Transformaciones AST de GroovyUn Paseo por las Transformaciones AST de Groovy
Un Paseo por las Transformaciones AST de Groovy
 
Javaone - Getting Funky with Groovy
Javaone - Getting Funky with GroovyJavaone - Getting Funky with Groovy
Javaone - Getting Funky with Groovy
 
Making the Most of Your Gradle Build
Making the Most of Your Gradle BuildMaking the Most of Your Gradle Build
Making the Most of Your Gradle Build
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
Learn Gnuplot
Learn Gnuplot Learn Gnuplot
Learn Gnuplot
 

Ähnlich wie Ast transformations

AST Transformations
AST TransformationsAST Transformations
AST Transformations
HamletDRC
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
HamletDRC
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
偉格 高
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
Eliot Horowitz
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
SHIVA101531
 

Ähnlich wie Ast transformations (20)

Introduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopIntroduction to MongoDB and Hadoop
Introduction to MongoDB and Hadoop
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: Prototypes
 
Java libraries you can't afford to miss
Java libraries you can't afford to missJava libraries you can't afford to miss
Java libraries you can't afford to miss
 
Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016
 
Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
jRuby: The best of both worlds
jRuby: The best of both worldsjRuby: The best of both worlds
jRuby: The best of both worlds
 
Groovy intro for OUDL
Groovy intro for OUDLGroovy intro for OUDL
Groovy intro for OUDL
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
OO in JavaScript
OO in JavaScriptOO in JavaScript
OO in JavaScript
 

Mehr von Andres Almiray

Mehr von Andres Almiray (20)

Creando, creciendo, y manteniendo una comunidad de codigo abierto
Creando, creciendo, y manteniendo una comunidad de codigo abiertoCreando, creciendo, y manteniendo una comunidad de codigo abierto
Creando, creciendo, y manteniendo una comunidad de codigo abierto
 
Liberando a produccion con confianza
Liberando a produccion con confianzaLiberando a produccion con confianza
Liberando a produccion con confianza
 
Liberando a produccion con confidencia
Liberando a produccion con confidenciaLiberando a produccion con confidencia
Liberando a produccion con confidencia
 
OracleDB Ecosystem for Java Developers
OracleDB Ecosystem for Java DevelopersOracleDB Ecosystem for Java Developers
OracleDB Ecosystem for Java Developers
 
Softcon.ph - Maven Puzzlers
Softcon.ph - Maven PuzzlersSoftcon.ph - Maven Puzzlers
Softcon.ph - Maven Puzzlers
 
Maven Puzzlers
Maven PuzzlersMaven Puzzlers
Maven Puzzlers
 
Oracle Database Ecosystem for Java Developers
Oracle Database Ecosystem for Java DevelopersOracle Database Ecosystem for Java Developers
Oracle Database Ecosystem for Java Developers
 
JReleaser - Releasing at the speed of light
JReleaser - Releasing at the speed of lightJReleaser - Releasing at the speed of light
JReleaser - Releasing at the speed of light
 
Building modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and LayrryBuilding modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and Layrry
 
Going Reactive with g rpc
Going Reactive with g rpcGoing Reactive with g rpc
Going Reactive with g rpc
 
Building modular applications with JPMS and Layrry
Building modular applications with JPMS and LayrryBuilding modular applications with JPMS and Layrry
Building modular applications with JPMS and Layrry
 
Taking Micronaut out for a spin
Taking Micronaut out for a spinTaking Micronaut out for a spin
Taking Micronaut out for a spin
 
Apache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and YouApache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and You
 
What I wish I knew about Maven years ago
What I wish I knew about Maven years agoWhat I wish I knew about Maven years ago
What I wish I knew about Maven years ago
 
What I wish I knew about maven years ago
What I wish I knew about maven years agoWhat I wish I knew about maven years ago
What I wish I knew about maven years ago
 
The impact of sci fi in tech
The impact of sci fi in techThe impact of sci fi in tech
The impact of sci fi in tech
 
Gradle Ex Machina - Devoxx 2019
Gradle Ex Machina - Devoxx 2019Gradle Ex Machina - Devoxx 2019
Gradle Ex Machina - Devoxx 2019
 
Creating Better Builds with Gradle
Creating Better Builds with GradleCreating Better Builds with Gradle
Creating Better Builds with Gradle
 
Interacting with the Oracle Cloud Java SDK with Gradle
Interacting with the Oracle Cloud Java SDK with GradleInteracting with the Oracle Cloud Java SDK with Gradle
Interacting with the Oracle Cloud Java SDK with Gradle
 
Gradle ex-machina
Gradle ex-machinaGradle ex-machina
Gradle ex-machina
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Ast transformations

  • 2.
  • 3. Agenda   •  Local  ASTTransforma5ons   –  Groovy   –  Grails   –  Griffon   •  Como  funcionan?   •  Otras  formas  de  modificar  AST  
  • 4. LISTADO  DE  TRANSFORMACIONES   DE  AST  (NO  EXHAUSTIVO)  
  • 5. @Singleton   @Singleton class AccountManager { void process(Account account) { ... } } def account = new Account() AccountManager.instance.process(account)
  • 6. @Delegate   class Event { @Delegate Date when String title, url } df = new SimpleDateFormat("MM/dd/yyyy") so2gx = new Event(title: "SpringOne2GX", url: "http://springone2gx.com", when: df.parse("10/19/2010")) oredev = new Event(title: "Oredev", url: "http://oredev.org", when: df.parse("11/02/2010")) assert oredev.after(so2gx.when)
  • 7. @Immutable   @Immutable class Person { String name } def person1 = new Person("ABC") def person2 = new Person(name: "ABC") assert person1 == person2 person1.name = "Boom!” // error!
  • 8. @Category   @Category(Integer) class Pouncer { String pounce() { (1..this).collect([]) { 'boing!' }.join(' ') } } use(Pouncer) { 3.pounce() // boing! boing! boing! }
  • 9. @Mixin   class Pouncer { String pounce() { (1..this.times).collect([]) { 'boing!' }.join(' ') } } @Mixin(Pouncer) class Person{ int times } person1 = new Person(times: 2) person1.pounce() // boing! boing!
  • 10. @Grab   @Grab('net.sf.json-lib:json-lib:2.3:jdk15') def builder = new net.sf.json.groovy.JsonGroovyBuilder() def books = builder.books { book(title: "Groovy in Action", name: "Dierk Koenig") } assert books.name == ["Dierk Koenig"]
  • 11. @Log   @groovy.util.logging.Log class Person { String name void talk() { log.info("$name is talking…") } } def person = new Person(name: "Duke") person.talk() // Oct 7, 2010 10:36:09 PM sun.reflect.NativeMethodAccessorImpl invoke0 // INFO: Duke is talking…  
  • 12. @InheritConstructors   @groovy.transform.InheritConstructors class MyException extends RuntimeException {} def x1 = new MyException("Error message") def x2 = new MyException(x1) assert x2.cause == x1
  • 13. @Canonical   @groovy.transform.Canonical class Person { String name } def person1 = new Person("Duke") def person2 = new Person(name: "Duke") assert person1 == person2 person2.name = "Tux" assert person1 != person2
  • 14. @Scalify   trait Output { @scala.reflect.BeanProperty var output:String = "" } @groovyx.transform.Scalify class GroovyOutput implements Output { String output }
  • 15. @En5ty   @grails.persistence.Entity class Book { String title } def book = new Book().save() assert book.id assert book.version
  • 16. @Bindable   @groovy.beans.Bindable class Book { String title } def book = new Book() book.addPropertyChangeListener({e -> println "$e.propertyName $e.oldValue -> $e.newValue" } as java.beans.PropertyChangeListener) book.title = "Foo” // prints "title Foo" book.title = "Bar” // prints "title Foo Bar"
  • 17. @Listener   @groovy.beans.Bindable class Book { @griffon.beans.Listener(snooper) String title private snooper = {e -> println "$e.propertyName $e.oldValue -> $e.newValue" } } def book = new Book() book.title = "Foo" // prints "title Foo" book.title = "Bar" // prints "title Foo Bar"
  • 18. @EventPublisher   @Singleton @griffon.util.EventPublisher class AccountManager { void process(Account account) { publishEvent("AccountProcessed", [account)] } } def am = AccountManager.instance am.addEventListener("AccountProcessed") { account -> println "Processed account $account" } def acc = new Account() AccountManager.instance.process(acc) // prints "Processed account Account:1"
  • 19. @Scaffold   class Book { String title } @griffon.presentation.Scaffold class BookBeanModel {} def model = new BookBeanModel() def book = new Book(title: "Foo") model.value = book assert book.title == model.title.value model.value = null assert !model.title.value assert model.title
  • 20. @En5ty   @griffon.persistence.Entity(‘gsql’) class Book { String title } def book = new Book().save() assert book.id assert book.version
  • 21. Y  otras  tantas  …   •  @PackageScope   •  @Lazy   •  @Newify   •  @Field   •  @Synchronized   •  @Vetoable   •  @ToString,  @EqualsAndHashCode,   @TupleConstructor   •  @AutoClone,  @AutoExternalize   •  …  
  • 22. LA  RECETA  SECRETA  PARA  HACER   TRANSFORMACIONES  DE  AST  
  • 23. 1  Definir  interface   @Retention(RetentionPolicy.SOURCE) @Target({ElementType.FIELD, ElementType.TYPE}) @GroovyASTTransformationClass ("org.codehaus.griffon.ast.ListenerASTTransformation ") public @interface Listener { String value(); }
  • 24. 2  Implementar  la  transformacion   import org.codehaus.groovy.control.CompilePhase; import org.codehaus.groovy.transform.ASTTransformation; import org.codehaus.groovy.transform.GroovyASTTransformation; @GroovyASTTransformation(phase=CompilationPhase.CANONICALIZATION) public class ListenerASTTransformation implements ASTTransformation { public void visit(ASTNode[] nodes, SourceUnit source) { // MAGIC GOES HERE, REALLY! =) } }
  • 25. 3  Anotar  el  codigo   @groovy.beans.Bindable class Book { @griffon.beans.Listener(snooper) String title private snooper = {e -> // awesome code … } }
  • 26. OTRO  TIPO  DE   TRANSFORMACIONES  
  • 31. Gracias!   @aalmiray   hXp://jroller.com/aalmiray