I would like to add a companion with a FIR plugin ...
# compiler
t
I would like to add a companion with a FIR plugin when a class has a specific super type. If I'm correct, I have to use
FirDeclarationGenerationExtension.getNestedClassifiersNames
to return with the name of the companion to make the compiler call the generator functions. How can I check for the super type in
getNestedClassifiersNames
? I tried
classSymbol.resolvedSuperTypes
but it throws a class casting exception, I guess the phase is wrong for that method.
d
You can't check resolved supertypes, because companion object (as any other class) may be generated before supertypes resolution phase So you should write plugin in assumption that none of supertypes of any class are not resolved yet
thank you color 1
t
That's fine, I mean it's logical that we can't have resolved super types at that point. Would it be possible to check the qualified name of the super type and work with that? I'm fine with the name, no need to be resolved.
d
You can extract parts of name from
FirUserTypeRef
, but it won't be an FQN Just the name which user wrote in the source code