• Save
GR8Conf 2011: STS DSL Support
Upcoming SlideShare
Loading in...5
×
 

GR8Conf 2011: STS DSL Support

on

  • 909 views

 

Statistics

Views

Total Views
909
Views on SlideShare
909
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

GR8Conf 2011: STS DSL Support GR8Conf 2011: STS DSL Support Presentation Transcript

  • 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
  • What’s new in Groovy & Grails Support?Part 1 © 2011 SpringSource, A division of VMware. All rights reserved
  • 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
  • New Grails tooling support in STS 2.7.0.M1  Service field content assist  Groovy search results in GSPs 4
  • 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! 6
  • DSL Support in Groovy-EclipsePart 2 © 2011 SpringSource, A division of VMware. All rights reserved
  • The Problem 8
  • A DSL for distance calculations 3.m + 2.yd + 2.mi - 1.km In the Groovy editor: Uh oh! Can we do better??? 9
  • 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: •  “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
  • 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 •  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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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 Console here: 24
  • 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 31
  • 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.  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
  • 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