SlideShare a Scribd company logo
[object Object]
http://hamletdarcy.blogspot.com ,[object Object]
[object Object],[object Object],[object Object]
[object Object],[object Object]
I shot an elephant in my pajamas.
Subject: I Verb: shot Direct Object: an elephant Indirect Object: in my pajamas
I shot an elephant in my pajamas. How he got in my pajamas,  I'll never know.
Subject: I Verb: shot an elephant in my pajamas Participle Phrase
I want to thank my parents,  Jesus and Oprah Winfrey
I want to thank my parents,  Jesus and Oprah Winfrey
Subject: I Verb: want Participle: God my parents Oprah Winfrey Infinitive: to thank
I want to thank my parents,  Jesus and Oprah Winfrey
I want to thank my parents,  Jesus and Oprah Winfrey You b. 1976 You b. 1954 God b. ?
Subject: I Verb: want Participle Phrase: my parents God Oprah Winfrey Infinitive: to thank
[object Object]
[object Object]
2 + 3 * 4
2 + 3 * 4 2 + * 3 4
2 + 3 * 4 2 + * 3 4 4 * + 2 3
(+ 2 (* 3 4)) 2 + * 3 4 4 * + 2 3
[object Object]
public class   Person { private  String name;  public void  setName(String name) {  this .name = name;} public  String getNameName() {  return   name ;  } public   static   void  main(String[] args) { Person p =  new  Person();   p.setName( “Hamlet” );  System. out .println(p);  } }
[object Object]
[object Object],[object Object]
 
 
 
 
 
 
 
 
 
 
 
 
@Data public   class  Person { private  String  firstName ; private  String  lastName ; } public   class  Person { private  String  firstName ; private  String  lastName ; public  String getFirstName() { return   this . firstName ; } public  void setFirstName(String paramString) { this . firstName  = paramString; } public  String getLastName() { return   this . lastName ; } public  void setLastName(String paramString) { this . lastName  = paramString; } public  boolean equals(Object paramObject) { if (paramObject ==  this ) return   true ; if (paramObject ==  null ) return   false ; if (paramObject.getClass() != getClass()) return   false ; Person localPerson = (Person) paramObject; if ( this . firstName  ==  null  ? localPerson. firstName  !=  null     : ! this . firstName .equals(localPerson. firstName )) return   false ; return   this . lastName  ==  null  ? localPerson. lastName  ==  null   :  this . lastName .equals(localPerson. lastName ); } public  int hashCode() { int i =  1 ; i = i *  31  + ( this . firstName  ==  null  ?  0  :  this . firstName .hashCode()); i = i *  31  + ( this . lastName  ==  null  ?  0  :  this . lastName .hashCode()); return  i; } public  String toString() { return   "Person(firstName=" + this . firstName + ", lastName=" + this . lastName  +  ")" ; } } ,[object Object]
@Getter / @Setter @ToString @EqualsAndHashCode @NoArgsConstructor @RequiredArgsConstructor  @AllArgsConstructor @Data @Cleanup @Synchronized @SneakyThrows @Log @Delegate val ,[object Object]
Generates Java Boilerplate Compile Time Only –  For Eclipse and javac –  IDEA & NetBeans too Removable with delombok –  Javadoc –  GWT? Read the fine print –  Know what is generated –  Slows compilation times? ,[object Object]
[object Object],Annotation Processor Javac Handler Eclipse Handler ,[object Object]
 
 
 
 
// javac private   void  generatePropertyChangeSupportField(JavacNode node) { if  (fieldAlreadyExists( PROPERTY_SUPPORT_FIELD_NAME , node))  return ; JCExpression exp = chainDots(node.getTreeMaker(), node,  "this" ); JCVariableDecl fieldDecl = newField() .ofType(PropertyChangeSupport. class ) .withName( PROPERTY_SUPPORT_FIELD_NAME ) .withModifiers( PRIVATE  |  FINAL ) .withArgs(exp) .buildWith(node); injectField(node, fieldDecl); } // ECJ private   void  generatePropertyChangeSupportField(EclipseNode node) { if  (fieldAlreadyExists( PROPERTY_SUPPORT_FIELD_NAME , node))  return ; Expression exp = referenceForThis(node.get()); FieldDeclaration fieldDecl = newField() .ofType(PropertyChangeSupport. class ) .withName( PROPERTY_SUPPORT_FIELD_NAME ) .withModifiers( PRIVATE  |  FINAL ) .withArgs(exp) .buildWith(node); injectField(node, fieldDecl); } Alex Ruiz – Custom AST  Transformations with Project Lombok http://www.ibm.com/developerworks/java/library/j-lombok/
[object Object]
class  Event { String  title } public class  Event { String  title public  void getTitle() { title } public  String setTitle(String t) { this. title  = t  } } ,[object Object]
class  Event { @Delegate  Date  when } class  Event implements Comparable, Clonable { Date  when boolean  after(Date when) {  this . when .after(when) } boolean  before(Date when)  {  this . when .before(when) } Object clone() {  this . when .clone() }  int  getDate()  {  this . when .date } int  getDay()  {  this . when .day } int  getHours()  {  this . when .hours } int  getMinutes()  {  this . when .minutes } int  getMonth()  {  this . when .month } int  getSeconds()  {  this . when .seconds } long  getTime()  {  this . when .time } int  getTimezoneOffset() {  this . when .timezoneOffset }  int  getYear() {  this . when .year } void  setDate( int  date) {  this . when .date = date }  void  setHours( int  hours)  {  this . when .hours = hours } void  setMonth( int  month)  {  this . when .month = month } void  setTime( long  time) {  this . when .time = time }  void  setYear( int  year)  {  this . when .year = year } String toGMTString()  {  this . when .toGMTString() } String toLocaleString() {  this . when .toLocaleString() }  void  setSeconds( int  seconds) {  this . when .seconds = seconds  }  void  setMinutes( int  minutes)  {  this . when .minutes = minutes  } int  compareTo(Date anotherDate)  {  this . when .compareTo(otherDate)  } } ,[object Object]
class Event { @Lazy ArrayList speakers } class Event { ArrayList speakers  def getSpeakers() { if (speakers != null) { return speakers } else { synchronized(this) { if (speakers == null) { speakers = [] }  return speakers } } } } ,[object Object]
@Immutable  class Event { String title } ,[object Object],–  Properties must be @Immutable or effectively immutable –  Properties are private –  Mutatators throw ReadOnlyPropertyException –  Map constructor created –  Tuple constructor created –  Equals(), hashCode() & toString() created –  Dates, Clonables, & arrays are defensively copied on way in & out (but not deeply cloned) –  Collections & Maps are wrapped in Immutable variants –  Non-immutable fields force an error –  Special handling for Date, Color, etc –  Many generated methods configurable ,[object Object]
[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Declarative Concurrency ,[object Object],Easier Cloning and Externalizing ,[object Object],Safer Scripting ,[object Object],[object Object],[object Object],[object Object]
[object Object],Local AST Transformations ,[object Object]
 
 
 
 
class  Event {   @Delegate  Date  when } @GroovyASTTransformationClass ( "org.pkg.DelegateTransform" ) public   @ interface  Delegate {   ... } @GroovyASTTransformation (phase =  CANONICALIZATION ) public   class   DelegateTransform   implements  ASTTransformation {   public   void  visit(ASTNode[] nodes, SourceUnit source) {   ...   } } ,[object Object]
[object Object],class  MainExample { @Main public   void  greet() { println  "Hello from greet()!" } } $ groovy MainExample.groovy  Hello from greet()! ,[object Object]
MethodNode makeMainMethod(MethodNode source) { def  className = source.declaringClass.name def  methodName = source.name def  ast =  new  AstBuilder().buildFromString( INSTRUCTION_SELECTION ,  false ,  """ package $source.declaringClass.packageName class $source.declaringClass.nameWithoutPackage { public static void main(String[] args) { new $className().$methodName() } } """ ) ast[ 1 ].methods.find { it.name ==  'main'  } } ,[object Object]
[object Object],[object Object]
–  Dead Code –  Defects like Gstring as Map Key, Duplicate Map Key –  Return path analysis (null returns) –  Type inference (and improving) –  Concurrency Problems (busy wait, etc) –  Poor Testing Practices –  Un-Groovy code …  and 260+ more rules
How it works CodeNarc Rule:  Ban new java.util.Random() calls @Override void   visitConstructorCallExpression(   ConstructorCallExpression call) { if   (AstUtil.classNodeImplementsType(call. type , Random)) {   addViolation(call,  'Using Random is insecure...' )   }   super .visitConstructorCallExpression(call) }
How it works
Embedded Languages def  s =  new  ArithmeticShell() assert 2 == s.evaluate( ' 1+1 ' ) assert 1.0 == s.evaluate( 'cos(2*PI)' ) public interface   GroovyCodeVisitor {   void  visitBlockStatement(BlockStatement statement);   void  visitForLoop(ForStatement forLoop);   void  visitWhileLoop(WhileStatement loop);   void  visitDoWhileLoop(DoWhileStatement loop);   ... }
[object Object],//FinallyStatement//ReturnStatement //SynchronizedStatement/Block[1][count(*) = 0] //AllocationExpression/ClassOrInterfaceType   [contains(@Image,'ThreadGroup')] | //PrimarySuffix   [contains(@Image, 'getThreadGroup')] ,[object Object],[object Object]
How it Works Compiles Groovy to AST Analyzes AST Nodes –  Not well typed –  Not many tokens –  unreliable with other AST Transforms
[object Object],def   "Does simple math work?" () {   expect:   def  s =  new  ArithmeticShell()   s.evaluate(input) == output   where:   input  | output   '1 + 1'   | 2   'cos(2*PI)'   | 1.0 } ,[object Object],[object Object]
2.0
void  method(String message) { if  (message !=  null ) { log .info( "Received input: ${ message.toUppercase() }" ) } }
@groovy.transform.TypeChecked void  method(String message) { if  (message !=  null ) { log .info( "Received input: ${ message.toUppercase() }" ) } }
@groovy.transform.TypeChecked void  method(String message) { if  (message !=  null ) { log .info( "Received input: ${ message.toUppercase() }" ) } } 1 compilation error: [Static type checking] - Cannot find matching  method java.lang.String#toUppercase() at line: 4, column: 43
void  method(Object message) { if  (message  instanceof  String) { log .info( "Received input: "  + message.toUpperCase() ); } }
@groovy.transform.TypeChecked void  method(Object message) { if  (message  instanceof  String) { log .info( "Received input: ${ message.toUpperCase() }" ) } }
@Log class  MyClass { def   message @groovy.transform.TypeChecked void   method() { if   ( message   instanceof   String) { doSomething()  log .info( "Received input: ${ message .toUpperCase() }" ) } } def  doSomething() { // ... } }
@Log class  MyClass { def   message @groovy.transform.TypeChecked void   method() { if   ( message   instanceof   String) { doSomething()  log .info( "Received input: ${ message .toUpperCase() }" ) } } def  doSomething() { message  =  5 } }
def  map = [x: 1 ,y: 2 ,z: 3 ]  def   keys = map*.key def   values = map*.value keys*.toUpperCase()
def  map = [x: 1 ,y: 2 ,z: 3 ]  def   keys = map*.key def   values = map*.value keys*.toUpperCase() values*.toUpperCase()
Dimension d1 = [ 100 ]  Dimension d2 = [ '100' , '200' ]  Dimension d3 =  new   Dimension(   width:  100 ,    height:  100 ,    depth:  100 )
- Local AST ransformation –  Not a static compiler –  No new syntax  –  No new semantics –  Bytecode not changed –  Targeted at Java developers @groovy.transform.TypeChecked
def   v =   1 v = v.toString() println v.toUpperCase()
def   v =   1 v = v.toString() println v.toUpperCase() Flow Sensitive Typing –  Under Discussion
int   fib(int i) { i <  2   ?  1   : fib(i -  2 ) + fib(i -  1 ) }
@groovy.transform.CompileStatic int  fib(int i) { i <  2  ?  1  : fib(i -  2 ) + fib(i -  1 ) }
@groovy.transform.CompileStatic – Is a static compiler – No new syntax  – Requires new semantics – Bytecode is changed
[object Object],[object Object]
Ruby FizzBuzz 1.upto(100) do |n| print &quot;Fizz&quot; if a = ((n % 3) == 0) print &quot;Buzz&quot; if b = ((n % 5) == 0)  print n unless (a || b) print &quot;&quot; end
Mirah FizzBuzz 1.upto(100) do |n| print &quot;Fizz&quot; if a = ((n % 3) == 0) print &quot;Buzz&quot; if b = ((n % 5) == 0)  print n unless (a || b) print &quot;&quot; end
Mirah: Pure JVM Class Output public class Fizz-buzz { public static void main(String[] argv) { ... do { n = __xform_tmp_4; ... if (n % 15 == 0) System.out.println(&quot;FizzBuzz&quot;); else if (n % 5 == 0) System.out.println(&quot;Buzz&quot;); else if (n % 3 == 0) System.out.println(&quot;Fizz&quot;); else System.out.println(n); ... } while (__xform_tmp_4 <= __xform_tmp_5); } }
Mirah: .java File Output if (((n % 15) == 0)) { PrintStream temp$10 = System.out; temp$10.println(&quot;FizzBuzz&quot;); } else { if (((n % 5) == 0)) { PrintStream temp$11 = System.out; temp$11.println(&quot;Buzz&quot;); } else { if (((n % 3) == 0)) { PrintStream temp$12 = System.out; temp$12.println(&quot;Fizz&quot;); } else { PrintStream temp$13 = System.out; temp$13.println(n); } } }
What it Means –  Fast –  Lightweight –  Uses JDK –  Android? –  GWT?
How it Works
How it Works
 
Mirah Macros macro def eachChar(value, &block) quote {  `value`.toCharArray.each do | my_char | `block.body` end  } end eachChar('laat de leeeuw niet ...') do | my_char | puts my_char end
Mirah Macros class Person  make_attr :firstName, :string  end  p = Person.new p.firstName = 'hamlet' puts p.firstName
Mirah Macros macro def make_attr(name, type)  attribute_name = name.string_value() quote { def `name`  @`name`  end  def `&quot;#{attribute_name}_set&quot;`(value:`type`)  @`name` = value end  } end
[object Object],[object Object]
Difficult to find call-sites
Still Difficult to generate AST Macros are more general ,[object Object]

More Related Content

What's hot

Groovy Grails DevJam Jam Session
Groovy Grails DevJam Jam SessionGroovy Grails DevJam Jam Session
Groovy Grails DevJam Jam Session
Mike Hugo
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)
Phil Calçado
 
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...Phil Calçado
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
Ian Robertson
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
Ken Kousen
 
Groovy!
Groovy!Groovy!
Groovy!
Petr Giecek
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
José Paumard
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
pramode_ce
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
José Paumard
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
Ganesh Samarthyam
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요
Chang W. Doh
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
Garth Gilmour
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - StockholmJan Kronquist
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
NAVER Engineering
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java Developers
Andres Almiray
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 

What's hot (20)

Groovy Grails DevJam Jam Session
Groovy Grails DevJam Jam SessionGroovy Grails DevJam Jam Session
Groovy Grails DevJam Jam Session
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)
 
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
 
Groovy!
Groovy!Groovy!
Groovy!
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 
Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요Kotlin, 어떻게 동작하나요
Kotlin, 어떻게 동작하나요
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java Developers
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 

Viewers also liked

Mirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby GroupMirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby Group
baroquebobcat
 
JRuby: Polyglot Heaven
JRuby: Polyglot HeavenJRuby: Polyglot Heaven
JRuby: Polyglot Heaven
Charles Nutter
 
Cloud Gate
Cloud GateCloud Gate
Cloud Gate
guest4b6201
 
Elements
ElementsElements
Elements
Carlos Pari
 
SCGH ED CME Intro 2014
SCGH ED CME Intro 2014SCGH ED CME Intro 2014
SCGH ED CME Intro 2014
SCGH ED CME
 
La robotica de la ultima generacion
La robotica de la ultima generacionLa robotica de la ultima generacion
La robotica de la ultima generacion
ericka_20
 
Es Ts Progress Report
Es Ts Progress ReportEs Ts Progress Report
Es Ts Progress ReportCC BASE
 
Sales Excellence SAM Completion Certificate
Sales Excellence SAM Completion CertificateSales Excellence SAM Completion Certificate
Sales Excellence SAM Completion CertificateTroy Carlisle
 
SCA Presentation Q2 2016
SCA Presentation Q2 2016SCA Presentation Q2 2016
SCA Presentation Q2 2016
SCA Svenska Cellulosa Aktiebolaget
 
Hancock Center
Hancock CenterHancock Center
Hancock Center
Rob Hannah
 
Tratamento de Imagens com Photoshop - Visao Geral
Tratamento de Imagens com Photoshop - Visao GeralTratamento de Imagens com Photoshop - Visao Geral
Tratamento de Imagens com Photoshop - Visao Geral
dualpixel
 
CV - 2nd Mate YACHTS:DPO - FREDERIK LIEBENBERG
CV - 2nd Mate YACHTS:DPO - FREDERIK LIEBENBERGCV - 2nd Mate YACHTS:DPO - FREDERIK LIEBENBERG
CV - 2nd Mate YACHTS:DPO - FREDERIK LIEBENBERGDerik Liebenberg
 
Economía Liberada. 1. Richard Cantillon
Economía Liberada. 1. Richard CantillonEconomía Liberada. 1. Richard Cantillon
Economía Liberada. 1. Richard Cantillon
elementos economia
 

Viewers also liked (14)

Mirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby GroupMirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby Group
 
JRuby: Polyglot Heaven
JRuby: Polyglot HeavenJRuby: Polyglot Heaven
JRuby: Polyglot Heaven
 
Cloud Gate
Cloud GateCloud Gate
Cloud Gate
 
Elements
ElementsElements
Elements
 
SCGH ED CME Intro 2014
SCGH ED CME Intro 2014SCGH ED CME Intro 2014
SCGH ED CME Intro 2014
 
La robotica de la ultima generacion
La robotica de la ultima generacionLa robotica de la ultima generacion
La robotica de la ultima generacion
 
Tlalne 1
Tlalne 1Tlalne 1
Tlalne 1
 
Es Ts Progress Report
Es Ts Progress ReportEs Ts Progress Report
Es Ts Progress Report
 
Sales Excellence SAM Completion Certificate
Sales Excellence SAM Completion CertificateSales Excellence SAM Completion Certificate
Sales Excellence SAM Completion Certificate
 
SCA Presentation Q2 2016
SCA Presentation Q2 2016SCA Presentation Q2 2016
SCA Presentation Q2 2016
 
Hancock Center
Hancock CenterHancock Center
Hancock Center
 
Tratamento de Imagens com Photoshop - Visao Geral
Tratamento de Imagens com Photoshop - Visao GeralTratamento de Imagens com Photoshop - Visao Geral
Tratamento de Imagens com Photoshop - Visao Geral
 
CV - 2nd Mate YACHTS:DPO - FREDERIK LIEBENBERG
CV - 2nd Mate YACHTS:DPO - FREDERIK LIEBENBERGCV - 2nd Mate YACHTS:DPO - FREDERIK LIEBENBERG
CV - 2nd Mate YACHTS:DPO - FREDERIK LIEBENBERG
 
Economía Liberada. 1. Richard Cantillon
Economía Liberada. 1. Richard CantillonEconomía Liberada. 1. Richard Cantillon
Economía Liberada. 1. Richard Cantillon
 

Similar to AST Transformations at JFokus

#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기
Arawn Park
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
Giordano Scalzo
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Codemotion
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Groovy
GroovyGroovy
Groovy
Zen Urban
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVMVaclav Pech
 
Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. Experience
Mike Fogus
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
Vaclav Pech
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
James Titcumb
 
Introduction kot iin
Introduction kot iinIntroduction kot iin
Introduction kot iin
Jedsada Tiwongvokul
 
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Codemotion
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
johndaviddalton
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
Paulo Morgado
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
James Titcumb
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
Cody Engel
 

Similar to AST Transformations at JFokus (20)

#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
JavaScript Survival Guide
JavaScript Survival GuideJavaScript Survival Guide
JavaScript Survival Guide
 
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Groovy
GroovyGroovy
Groovy
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. Experience
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
 
Introduction kot iin
Introduction kot iinIntroduction kot iin
Introduction kot iin
 
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 

More from HamletDRC

Static Analysis and AST Transformations
Static Analysis and AST TransformationsStatic Analysis and AST Transformations
Static Analysis and AST Transformations
HamletDRC
 
Static Analysis in IDEA
Static Analysis in IDEAStatic Analysis in IDEA
Static Analysis in IDEA
HamletDRC
 
10 Years of Groovy
10 Years of Groovy10 Years of Groovy
10 Years of Groovy
HamletDRC
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
HamletDRC
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
HamletDRC
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
HamletDRC
 

More from HamletDRC (6)

Static Analysis and AST Transformations
Static Analysis and AST TransformationsStatic Analysis and AST Transformations
Static Analysis and AST Transformations
 
Static Analysis in IDEA
Static Analysis in IDEAStatic Analysis in IDEA
Static Analysis in IDEA
 
10 Years of Groovy
10 Years of Groovy10 Years of Groovy
10 Years of Groovy
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
 

Recently uploaded

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 

AST Transformations at JFokus

  • 1.
  • 2.
  • 3.
  • 4.
  • 5. I shot an elephant in my pajamas.
  • 6. Subject: I Verb: shot Direct Object: an elephant Indirect Object: in my pajamas
  • 7. I shot an elephant in my pajamas. How he got in my pajamas, I'll never know.
  • 8. Subject: I Verb: shot an elephant in my pajamas Participle Phrase
  • 9. I want to thank my parents, Jesus and Oprah Winfrey
  • 10. I want to thank my parents, Jesus and Oprah Winfrey
  • 11. Subject: I Verb: want Participle: God my parents Oprah Winfrey Infinitive: to thank
  • 12. I want to thank my parents, Jesus and Oprah Winfrey
  • 13. I want to thank my parents, Jesus and Oprah Winfrey You b. 1976 You b. 1954 God b. ?
  • 14. Subject: I Verb: want Participle Phrase: my parents God Oprah Winfrey Infinitive: to thank
  • 15.
  • 16.
  • 17. 2 + 3 * 4
  • 18. 2 + 3 * 4 2 + * 3 4
  • 19. 2 + 3 * 4 2 + * 3 4 4 * + 2 3
  • 20. (+ 2 (* 3 4)) 2 + * 3 4 4 * + 2 3
  • 21.
  • 22. public class Person { private String name; public void setName(String name) { this .name = name;} public String getNameName() { return name ; } public static void main(String[] args) { Person p = new Person(); p.setName( “Hamlet” ); System. out .println(p); } }
  • 23.
  • 24.
  • 25.  
  • 26.  
  • 27.  
  • 28.  
  • 29.  
  • 30.  
  • 31.  
  • 32.  
  • 33.  
  • 34.  
  • 35.  
  • 36.  
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.  
  • 42.  
  • 43.  
  • 44.  
  • 45. // javac private void generatePropertyChangeSupportField(JavacNode node) { if (fieldAlreadyExists( PROPERTY_SUPPORT_FIELD_NAME , node)) return ; JCExpression exp = chainDots(node.getTreeMaker(), node, &quot;this&quot; ); JCVariableDecl fieldDecl = newField() .ofType(PropertyChangeSupport. class ) .withName( PROPERTY_SUPPORT_FIELD_NAME ) .withModifiers( PRIVATE | FINAL ) .withArgs(exp) .buildWith(node); injectField(node, fieldDecl); } // ECJ private void generatePropertyChangeSupportField(EclipseNode node) { if (fieldAlreadyExists( PROPERTY_SUPPORT_FIELD_NAME , node)) return ; Expression exp = referenceForThis(node.get()); FieldDeclaration fieldDecl = newField() .ofType(PropertyChangeSupport. class ) .withName( PROPERTY_SUPPORT_FIELD_NAME ) .withModifiers( PRIVATE | FINAL ) .withArgs(exp) .buildWith(node); injectField(node, fieldDecl); } Alex Ruiz – Custom AST Transformations with Project Lombok http://www.ibm.com/developerworks/java/library/j-lombok/
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.  
  • 56.  
  • 57.  
  • 58.  
  • 59.
  • 60.
  • 61.
  • 62.
  • 63. – Dead Code – Defects like Gstring as Map Key, Duplicate Map Key – Return path analysis (null returns) – Type inference (and improving) – Concurrency Problems (busy wait, etc) – Poor Testing Practices – Un-Groovy code … and 260+ more rules
  • 64. How it works CodeNarc Rule: Ban new java.util.Random() calls @Override void visitConstructorCallExpression( ConstructorCallExpression call) { if (AstUtil.classNodeImplementsType(call. type , Random)) { addViolation(call, 'Using Random is insecure...' ) } super .visitConstructorCallExpression(call) }
  • 66. Embedded Languages def s = new ArithmeticShell() assert 2 == s.evaluate( ' 1+1 ' ) assert 1.0 == s.evaluate( 'cos(2*PI)' ) public interface GroovyCodeVisitor { void visitBlockStatement(BlockStatement statement); void visitForLoop(ForStatement forLoop); void visitWhileLoop(WhileStatement loop); void visitDoWhileLoop(DoWhileStatement loop); ... }
  • 67.
  • 68. How it Works Compiles Groovy to AST Analyzes AST Nodes – Not well typed – Not many tokens – unreliable with other AST Transforms
  • 69.
  • 70. 2.0
  • 71. void method(String message) { if (message != null ) { log .info( &quot;Received input: ${ message.toUppercase() }&quot; ) } }
  • 72. @groovy.transform.TypeChecked void method(String message) { if (message != null ) { log .info( &quot;Received input: ${ message.toUppercase() }&quot; ) } }
  • 73. @groovy.transform.TypeChecked void method(String message) { if (message != null ) { log .info( &quot;Received input: ${ message.toUppercase() }&quot; ) } } 1 compilation error: [Static type checking] - Cannot find matching method java.lang.String#toUppercase() at line: 4, column: 43
  • 74. void method(Object message) { if (message instanceof String) { log .info( &quot;Received input: &quot; + message.toUpperCase() ); } }
  • 75. @groovy.transform.TypeChecked void method(Object message) { if (message instanceof String) { log .info( &quot;Received input: ${ message.toUpperCase() }&quot; ) } }
  • 76. @Log class MyClass { def message @groovy.transform.TypeChecked void method() { if ( message instanceof String) { doSomething() log .info( &quot;Received input: ${ message .toUpperCase() }&quot; ) } } def doSomething() { // ... } }
  • 77. @Log class MyClass { def message @groovy.transform.TypeChecked void method() { if ( message instanceof String) { doSomething() log .info( &quot;Received input: ${ message .toUpperCase() }&quot; ) } } def doSomething() { message = 5 } }
  • 78. def map = [x: 1 ,y: 2 ,z: 3 ] def keys = map*.key def values = map*.value keys*.toUpperCase()
  • 79. def map = [x: 1 ,y: 2 ,z: 3 ] def keys = map*.key def values = map*.value keys*.toUpperCase() values*.toUpperCase()
  • 80. Dimension d1 = [ 100 ] Dimension d2 = [ '100' , '200' ] Dimension d3 = new Dimension( width: 100 , height: 100 , depth: 100 )
  • 81. - Local AST ransformation – Not a static compiler – No new syntax – No new semantics – Bytecode not changed – Targeted at Java developers @groovy.transform.TypeChecked
  • 82. def v = 1 v = v.toString() println v.toUpperCase()
  • 83. def v = 1 v = v.toString() println v.toUpperCase() Flow Sensitive Typing – Under Discussion
  • 84. int fib(int i) { i < 2 ? 1 : fib(i - 2 ) + fib(i - 1 ) }
  • 85. @groovy.transform.CompileStatic int fib(int i) { i < 2 ? 1 : fib(i - 2 ) + fib(i - 1 ) }
  • 86. @groovy.transform.CompileStatic – Is a static compiler – No new syntax – Requires new semantics – Bytecode is changed
  • 87.
  • 88. Ruby FizzBuzz 1.upto(100) do |n| print &quot;Fizz&quot; if a = ((n % 3) == 0) print &quot;Buzz&quot; if b = ((n % 5) == 0) print n unless (a || b) print &quot;&quot; end
  • 89. Mirah FizzBuzz 1.upto(100) do |n| print &quot;Fizz&quot; if a = ((n % 3) == 0) print &quot;Buzz&quot; if b = ((n % 5) == 0) print n unless (a || b) print &quot;&quot; end
  • 90. Mirah: Pure JVM Class Output public class Fizz-buzz { public static void main(String[] argv) { ... do { n = __xform_tmp_4; ... if (n % 15 == 0) System.out.println(&quot;FizzBuzz&quot;); else if (n % 5 == 0) System.out.println(&quot;Buzz&quot;); else if (n % 3 == 0) System.out.println(&quot;Fizz&quot;); else System.out.println(n); ... } while (__xform_tmp_4 <= __xform_tmp_5); } }
  • 91. Mirah: .java File Output if (((n % 15) == 0)) { PrintStream temp$10 = System.out; temp$10.println(&quot;FizzBuzz&quot;); } else { if (((n % 5) == 0)) { PrintStream temp$11 = System.out; temp$11.println(&quot;Buzz&quot;); } else { if (((n % 3) == 0)) { PrintStream temp$12 = System.out; temp$12.println(&quot;Fizz&quot;); } else { PrintStream temp$13 = System.out; temp$13.println(n); } } }
  • 92. What it Means – Fast – Lightweight – Uses JDK – Android? – GWT?
  • 95.  
  • 96. Mirah Macros macro def eachChar(value, &block) quote { `value`.toCharArray.each do | my_char | `block.body` end } end eachChar('laat de leeeuw niet ...') do | my_char | puts my_char end
  • 97. Mirah Macros class Person make_attr :firstName, :string end p = Person.new p.firstName = 'hamlet' puts p.firstName
  • 98. Mirah Macros macro def make_attr(name, type) attribute_name = name.string_value() quote { def `name` @`name` end def `&quot;#{attribute_name}_set&quot;`(value:`type`) @`name` = value end } end
  • 99.
  • 100. Difficult to find call-sites
  • 101.
  • 102. Easily quote ASTs into source
  • 103.
  • 104.
  • 105.
  • 106.
  • 107. – Groovy Wiki and Mailing List is amazingly helpful
  • 108. – Use your creativity and patience
  • 109. – http://hamletdarcy.blogspot.com & @HamletDRC Groovy, Grails, Griffon, and Agile Consulting [email_address] or [email_address]