How do I subclass a generic base class in a Groovy AST transformation?

Viewed 10

I have an abstract base class Resource<A> (written in Java) that contains some A attributes. I am writing an AST transformation to be applied to FooAttributes that will generate the wrapper class FooResource extends Resource<FooAttributes>, but I'm encountering an error about handling the ClassNode.

When I try to write this:

make(rc.fqcn).tap {
  superClass = makeWithoutCaching(Resource).tap { genericsTypes = [attr] as GenericsType[] }
}

I receive the compiler error

transform used a generics containing ClassNode com.example.Resource<com.example.FooAttributes> for the super class com.example.FooResource directly. You are not supposed to do this. Please create a new ClassNode referring to the old ClassNode and use the new ClassNode instead of the old one. Otherwise the compiler will create wrong descriptors and a potential NullPointerException in TypeResolver in the OpenJDK. If this is not your own doing, please report this bug to the writer of the transform.

(Presumably the "super class" is an error and meant to say "super class for".)

I have reviewed the APIs for ClassNode and ClassHelper and cannot find a way to "create a new node referring to the old node". I tried invoking new ClassNode(String, int, ClassNode), but I received the same error.

What API calls should I use to create the "new ClassNode" for my generic Resource<A> class?

0 Answers
Related