https://kotlinlang.org logo
#compiler
Title
# compiler
t

Tóth István Zoltán

12/06/2023, 1:33 PM
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

dmitriy.novozhilov

12/06/2023, 1:39 PM
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

Tóth István Zoltán

12/06/2023, 1:41 PM
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

dmitriy.novozhilov

12/06/2023, 1:50 PM
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
4 Views