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
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. 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. 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. 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. 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. 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
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. 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