Groovy AstTransformationSupport Test



I'm writing a plugin to support a custom Groovy AST transformation.

The plugin itself is working as expected but I have problem writing up tests.

I set up a base class for my tests which adds the Groovy library:


Just to test whether my setup works I copied a spec from the official Groovy plugin (from GrStubAstSwitchTest) where @Delegate is tested, which has similarities with custom annotation:


GroovyFileImpl file = myFixture.addFileToProject('a.groovy', '''\
class A {
def foo(){}
class B {
A a = new A()
''') as GroovyFileImpl

assert !file.contentsLoaded
PsiClass clazzB = file.classes[1]
assert !file.contentsLoaded

assert clazzB.methods.find { == 'foo' }
assert !file.contentsLoaded


But not even that one passes. It seems like TransformationUtil#transformDefinition isn't called in time. Is there some way to trigger AstTransformationSupport and wait for it to finish?

Is someting with my setup wrong?


Thanks for your help!



Hi, is your AstTransformationSupport registered in plugin.xml ?


Hi, yeah I think it is.

The plugin itself is working as expected when executing using runIde gradle task.

I just can't figure out how to test a AstTransformationSupport. What I find weird is that not even the built-in AstTransformationSupport like for @Delegat works in the test.


Do you mind sharing your project?


Please sign in to leave a comment.