Can I use GDSL with Groovy AST transforms, that have closures as parameters?

Answered

So I have a question about gdsl files, and if I can use them to add IDE support for a Groovy AST Transform, made for a Grails plugin, that takes up to three closures as parameters? The closures are eventually delegated to a Grails service, which is generate by the plugins install. What I'm looking to get out of this is that the IDE won't mark calls to the Grails service, in the closures as unresolved. If it could allow for code completion of the various methods from the Grails service that would be a bonus.

The plugin:
https://github.com/virtualdogbert/Enforcer/

The AST Transform:

https://github.com/virtualdogbert/Enforcer/blob/master/src/main/groovy/com/virtualdogbert/ast/Enforce.groovy
https://github.com/virtualdogbert/Enforcer/blob/master/src/main/groovy/com/virtualdogbert/ast/EnforceASTTransformation.groovy

If this can be done, my next question is how? I've looked through documentation and examples, but haven't found any that targets a Groovy AST Transform, with closure parameters. I've also tried something based off:
http://www.tothenew.com/blog/gdsl-awesomeness-delegating-closure-calls/

but it didn't work.

2 comments
Comment actions Permalink
Official comment

Hi 

You need closure scope restricted to closures within annotation. 

contributor(context(scope: closureScope(annotationName: "com.virtualdogbert.ast.Enforce"))) {
delegatesTo(findClass(DELEGATE_FQN))
}

I've not found `enforserService` in your repo, you just substitute DELEGATE_FQN with its fully qualified name.

Comment actions Permalink

That worked thanks. Now I just have to make a few changes, so that the service is always installed to the same location(rather than user chosen), and I can do a new release. Thanks again.

0

Please sign in to leave a comment.