groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Basil Peace <>
Subject Adding new class with annotations in AST transformation
Date Wed, 05 Dec 2018 23:33:23 GMT
Hello to everybody!

I'm writing AST transformation that creates new classes, and I have a problem with annotations.
I'm using Groovy 2.5.4 (with Gradle).

Code of AST transformation class is here (WIP):

Basically, user puts an annotation on interface.
Then AST transformation:
1) adds inner class to this interface
2) adds to this inner class method implementations, fields, constructor and so on
Some of these should be annotated.

I've already seen post in desmontandojava blog on adding inner classes:
And figured out that if I don't use CompilationUnit for inner class, it doesn't get methodMissing,
propertyMissing etc. methods.
So, I guess, I need it.

I'm using CompilationUnit this way:

    new CompilationUnit(sourceUnit.AST.unit.config).with {

Whenever members of implClass have annotations I got NPE at org.codehaus.groovy.classgen.ExtendedVerifier.isAnnotationCompatible(
I debugged and figured out that:
1) CompilationUnit#addClassNode adds new ModuleNode constructed with CompileUnit, and SourceUnit
is null in this case.
2) Then null source gets passed to other objects.
3) ExtendedVerifier#isAnnotationCompatible needs source to get configuration.
Without source I got NPE.

Note that code in desmontandojava blog doesn't create annotations.

I also tried to add my new class into existing module but then I got another error, saying
that line numbers are null.

I've looked at Groovy 3.0 sources too, but couldn't see any changes that would fix or change

Could somebody help me?
Am I doing something wrong, or it is a bug?

Best regards,
Basil Peace

View raw message