LightPsiClassBuilder with inheritance and generics
Hello,
Given a simple class like ```abstract class Base<A,B,C>{}``` I'd like to make a LightPsiClassBuilder (and SyntheticElement) class like ```class Impl<A,B,C> extends Base<A,B,C>{ Impl(String s, A a, B b,C c) {} }```, in a similar way to how Lombok's IntelliJ plugin does it for the Builder class. So, the users of the plugin can write code like ```Base<String,Integer,Long> b = new Impl<>("blah", "a", 42, 777);``` and the Impl class and it's constructor will be understood by the IntelliJ.
It mostly works (and fully works without generics), but I can't seem to get the combination of getTypeParameterList(), LightTypeParameterListBuilder, getExtendsList(), LightReferenceListBuilder, LightMethodBuilder, the constructor parameters' types, and all the substitutors involved right. So, I just generate a String source-code -- "class Impl<A,B,C> extends Base<A,B,C>{ Impl(String s, A a, B b,C c i) {} }" parse it to PsiClass and then grab the getTypeParameterList, getExtendsList, and getMethods and use in my LightPsiClassBuilder. It seem to work in general (except ctrl+p -- show arguments of the constructor). But, how could one do that without generating the source code and Intermediate PsiClass, but directly in PSI using the "Light" Psi classes for this case with generics?
请先登录再写评论。
Creating light Java PSI isn't easy. Debugging and comparing from-text-PSI with yours might help. Usually, one needs to carefully implement getParent/getContext/getContainingFile and ensuring parent-child relations are consistent (e.g. cls.getTypeParameters[0].getOwner() == cls). You might get some inspiration from Kotlin's light and ultra-light classes, generics mostly seem to work there: https://github.com/JetBrains/kotlin/tree/bc66834c3c3d94d34631aa359d0a2fb213d56c09/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes
If creation from text works fine for you and isn't very slow, you could as well consider sticking to it. We plan to add an easier way to create light JVM entitites, but we can provide no ETA yet.