What’s new in Groovy & Grails Support?DSL Support in Groovy-EclipseAndrew Eisenberg, SpringSource Tools Team              ...
What’s new in Groovy & Grails Support?Part 1                                 © 2011 SpringSource, A division of VMware. Al...
New Groovy-Eclipse Support in 2.5.0  DSL Descriptors (discussed later)  Groovy 1.8  Parameter guessing content assist ...
New Grails tooling support in STS 2.7.0.M1  Service field content assist  Groovy search results in GSPs                 ...
Gradle support in STSPart 1.5                        © 2011 SpringSource, A division of VMware. All rights reserved
First cut at Gradle support now available in STS  Demoed this morning in the Gradle talk  Yay!                          ...
DSL Support in Groovy-EclipsePart 2                                © 2011 SpringSource, A division of VMware. All rights r...
The Problem              8
A DSL for distance calculations                  3.m + 2.yd + 2.mi - 1.km       In the Groovy editor:                     ...
The Solution:DSL Descriptors (DSLDs)                          10
DSL Descriptors  Teach the IDE about DSLs through scripting                               CONFIDENTIAL     11
DSL Descriptors  In English:  •  “Any subtype of Number should have the following properties: m, yd, mi, km”  In DSLD:  ...
Let’s see that  Ex 1: Distances                     13
Anatomy of a DSLD file                         14
DSLD and the Inferencing Engine  Hooks into Groovy-Eclipse’s type inferencing engine •  Visit each expression AST node • ...
Pointcuts and Contribution blocks  Pointcuts:  •  Where to do it.  •  What is the current expression?  •  Declaring type?...
What goes in a Contribution Block?  property : “adds” a property                  (…).accept {! •  arguments             ...
Pointcuts  currentType() : Matches on the current declaring type  enclosingClass() : Matches on the enclosing class  cu...
Where does this pointcut match? What does it add?(enclosingClass(annotatedBy(“org.junit.runner.RunWith”)) & 
currentType(m...
Wait…isn’t this Aspect-Oriented Programming?  Pointcut  •  Intentionally borrowed from AOP  AspectJ: pointcuts and advic...
Other things to help with DSLDs                                  21
New DSLD Wizard  File  New  Groovy DSL Descriptor                                        22
DSLD Preferences Page                        23
Groovy Event Console  Keep this open while implementing DSLDs: •  Shows exceptions •  Pointcuts •  Matches  Find the Con...
Groovy AST Viewer  Exploration of AST of current Groovy file                                               25
Examples           26
Basic ScriptEx 2: Using the DSLD wizard                              27
Meta DSLEx 3: DSLD script for editing DSLDs                                      28
AST TransformsEx 3: Standard AST Transforms                                29
SwingBuilderEx 4: Long script, but simple to understand                                              30
Grails Constraints DSLEx 5: encapsulate Grails domain knowledge in a script                                               ...
Criteria QueriesEx 6: simple script, large effect                                    32
GriffonEx 7: from last night                        33
What’s next?               34
DSLD is not complete  Guided by user feedback  Collaboration with library developers •  Grails, Gaelyk, Griffon, etc.  ...
Thanks!  More information:  •  Google: groovy eclipse dsld  Full documentation on Codehaus.org:  •  http://docs.codehaus...
Upcoming SlideShare
Loading in...5
×

GR8Conf 2011: STS DSL Support

688

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
688
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "GR8Conf 2011: STS DSL Support"

  1. 1. What’s new in Groovy & Grails Support?DSL Support in Groovy-EclipseAndrew Eisenberg, SpringSource Tools Team © 2011 SpringSource, A division of VMware. All rights reserved
  2. 2. What’s new in Groovy & Grails Support?Part 1 © 2011 SpringSource, A division of VMware. All rights reserved
  3. 3. New Groovy-Eclipse Support in 2.5.0  DSL Descriptors (discussed later)  Groovy 1.8  Parameter guessing content assist  Script outline view  Distinguish read vs. write access in search  Conditional breakpoints in Groovy files (STS only) 3
  4. 4. New Grails tooling support in STS 2.7.0.M1  Service field content assist  Groovy search results in GSPs 4
  5. 5. Gradle support in STSPart 1.5 © 2011 SpringSource, A division of VMware. All rights reserved
  6. 6. First cut at Gradle support now available in STS  Demoed this morning in the Gradle talk  Yay! 6
  7. 7. DSL Support in Groovy-EclipsePart 2 © 2011 SpringSource, A division of VMware. All rights reserved
  8. 8. The Problem 8
  9. 9. A DSL for distance calculations 3.m + 2.yd + 2.mi - 1.km In the Groovy editor: Uh oh! Can we do better??? 9
  10. 10. The Solution:DSL Descriptors (DSLDs) 10
  11. 11. DSL Descriptors  Teach the IDE about DSLs through scripting CONFIDENTIAL 11
  12. 12. DSL Descriptors  In English: •  “Any subtype of Number should have the following properties: m, yd, mi, km”  In DSLD: •  “Any subtype of Number”: currentType( subType( Number ) )! •  “…the following properties…”: [ “m”, “yd”, “cm”, “mi”, “km” ].each {! property name:it, type:"Distance”! }! 3.m + 2.yd + 2.mi - 1.km 12
  13. 13. Let’s see that  Ex 1: Distances 13
  14. 14. Anatomy of a DSLD file 14
  15. 15. DSLD and the Inferencing Engine  Hooks into Groovy-Eclipse’s type inferencing engine •  Visit each expression AST node •  Determine type using previous expression •  Move to next expression  DSLD operates on Groovy AST Expression nodes •  Exposes Groovy AST nodes and uses Groovy API  In the background, while typing (reconciling) org.codehaus.groovy.ast.expr.Expression! 15
  16. 16. Pointcuts and Contribution blocks  Pointcuts: •  Where to do it. •  What is the current expression? •  Declaring type? class Other {! •  Enclosing class? def x! }!  Contribution blocks: class Foo {! •  What to do def method() {! •  “Add” method new Other().x! •  “Add” property }! }! •  (not at runtime, in the editor only) 16
  17. 17. What goes in a Contribution Block?  property : “adds” a property (…).accept {! •  arguments property name: “myName”! •  name: “blarb” method name: “getMyName”! }! •  type: “java.lang.String” •  declaringType :”com.foo.Frumble” •  isStatic: false •  doc: “Some html” •  provider: “My DSL”  method : “adds” a method •  all arguments above, and •  params: [firstName:“java.lang.String”, lastName:“java.lang.String”] •  useNamedArgs: true  name is required, others optional 17
  18. 18. Pointcuts  currentType() : Matches on the current declaring type  enclosingClass() : Matches on the enclosing class  currentType(“com.bar.Foo”)  methods(“run”)  annotatedBy(“org.junit.runner.RunWith”)  enclosingClass( annotatedBy(“org.junit.runner.RunWith”) ) & currentType(methods(“run”) ) 18
  19. 19. Where does this pointcut match? What does it add?(enclosingClass(annotatedBy(“org.junit.runner.RunWith”)) & 
currentType(methods(“run”))).accept { property name:”blarb” }! Looking for an expression that:@RunWith(Sumthin) !class Foo {! def someTest() {! enclosed by @RunWith print “Hello”! def x = new MyRunner()! x.blarb! has run method }! blarb}! class MyRunner { def run() {…} }! 19
  20. 20. Wait…isn’t this Aspect-Oriented Programming?  Pointcut •  Intentionally borrowed from AOP  AspectJ: pointcuts and advice •  operates on Java instructions at runtime class Foo {!  DSLD: pointcuts and contribution blocks def x = {! •  operates on AST def i = 0! org.codehaus.groovy.ast.expr.*!  Join Point Model i++! }! •  Join points (e.g., instructions, expressions) }! •  Mechanism for quantifying join points (e.g., pointcuts) •  Means of affect at a join point (e.g., advice, contribution blocks) 20
  21. 21. Other things to help with DSLDs 21
  22. 22. New DSLD Wizard  File  New  Groovy DSL Descriptor 22
  23. 23. DSLD Preferences Page 23
  24. 24. Groovy Event Console  Keep this open while implementing DSLDs: •  Shows exceptions •  Pointcuts •  Matches  Find the Console here: 24
  25. 25. Groovy AST Viewer  Exploration of AST of current Groovy file 25
  26. 26. Examples 26
  27. 27. Basic ScriptEx 2: Using the DSLD wizard 27
  28. 28. Meta DSLEx 3: DSLD script for editing DSLDs 28
  29. 29. AST TransformsEx 3: Standard AST Transforms 29
  30. 30. SwingBuilderEx 4: Long script, but simple to understand 30
  31. 31. Grails Constraints DSLEx 5: encapsulate Grails domain knowledge in a script 31
  32. 32. Criteria QueriesEx 6: simple script, large effect 32
  33. 33. GriffonEx 7: from last night 33
  34. 34. What’s next? 34
  35. 35. DSLD is not complete  Guided by user feedback  Collaboration with library developers •  Grails, Gaelyk, Griffon, etc.  Release standard DSLDs (AST Transforms, Builders, etc.) •  With Groovy-Eclipse? •  With Groovy core?  More pointcuts •  What do users need that isn’t implemented? •  regex(), instanceof(), superType(), enclosingEnum(), etc.  What about IntelliJ’s GDSL? 35
  36. 36. Thanks!  More information: •  Google: groovy eclipse dsld  Full documentation on Codehaus.org: •  http://docs.codehaus.org/display/GROOVY/DSL+Descriptors+for+Groovy-Eclipse  Install from update site: •  http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/  Mailing list: •  eclipse-plugin-users@codehaus.org  Or chat with me whenever 36

×