Search code examples
javaeclipsegroovydslsubtype

Eclipse Groovy DSLDs and static compilation


Is it possible to define Eclipse Groovy DSLD (DSL Definition) which can be statically compilable?

I tried to use DSLD example provided by Eclipse, so I created TestDsl.dsld:

contribute(currentType(subType('groovy.lang.GroovyObject'))) {
    property (
        name : 'newProp',
        type : String,
        provider : 'Sample DSL',
        doc : 'This is a sample.  You should see this in content assist for GroovyObjects: <pre>newProp</pre>')
}

Then I wrote a test class using previous property. This class should be compiled statically. Eclipse is showing new property as a valid one, but then it fails to compile.

Same result occurs using both @CompileStatic and @TypeChecked.


Solution

  • DSLDs introduce new methods and properties into content assist and type inferencing. This does not guarantee the methods or properties will be available at compile- or run-time. They operate more like hints than anything.

    Quite often, DSLDs are used to fill a gap that exists between the static type checker and the dynamic execution state of your program. If you want something that is compatible with @TypeChecked or @CompileStatic, you may need to write a TypeChekingExtension instead of a DSLD contribution.