groovy dynamic methods contributor

Hi - I have a class along these lines:

abstract class MyBaseScript extends Script {

void methodMissing(String name, Object args) {
...
}
}

And then some construct like this:

import groovy.transform.BaseScript

@BaseScript MyBaseScript delegate

foobar()

What I am trying to do is use a psi contributor to add any method at the level of foobar()... but not just any method, the actual method that the author chooses.

So very similar to org.jetbrains.plugins.groovy.builder.XmlMarkupBuilderNonCodeMemberContributor.

However I was trying to do it using a gdsl file, as it seems a bit easier. My problem is knowing what method to add. 

So I can add foobar() using:

def ctx3 = context(scope: scriptScope(name: "SomeScript.groovy"))
contributor(ctx3) {
method name: "foobar", type: 'java.util.Collection', params: [closure: "groovy.lang.Closure"]
}

but obviously that doesn't work for anything other than foobar.

Can this be done using a gdsl or should I be looking at a org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor extension?

TIA, jamie

 

 

0

Please sign in to leave a comment.