I would like to create a new top level class in FI...
# compiler
t
I would like to create a new top level class in FIR whenever I see an interface that extends another interface. Like this:
Copy code
interface Test : Service
And the class I would like to generate:
Copy code
class Test$Impl : Test { }
I tried to figure out how to use
FirDeclarationGenerationExtension
for this but I couldn't.
getTopLevelClassIds
is called very early, and I don't know how to figure out which interfaces should I process. Any pointers? Thanks in advance.
j
I think you need to use annotations for this.
If nothing has changed, everything around the generation extension needs annotations
thank you color 1
t
Thanks, I was afraid that's the case. I'll change to annotations. I really don't like them, they make the code hard to read and move information to the wrong place, but this is how it is.
On the other hand I really don't see what's the difference between an annotation and an interface at this point. I guess I could just figure out how the compiler checks the annotations and do the same for the interfaces. Maybe it's too much work...
d
I recently described the reasoning behind this design
t
Thanks, the description of phases in that description is very useful. The problem is that
getTopLevelClassIds
is called very early and I can't figure out how to collect the classes I want to process. In ExternalClassGenerator of the fir plugin prototype a predicate is used but when I tried it I got an empty result. I also checked the cache it uses with debugger and it was empty. From FirDeclarationGenerationExtension: • the
getTopLevelClassIds
method is called AFTER the SUPERTYPES phase • the
generateTopLevelClassLikeDeclaration
method is called ON the SUPERTYPES phase I don't understand how would this work.
d
From `FirDeclarationGenerationExtension`:
• the
getTopLevelClassIds
method is called AFTER the SUPERTYPES phase
• the
generateTopLevelClassLikeDeclaration
method is called ON the SUPERTYPES phase
It's a problem in the documentation. This comment about "after supertypes" is about methods about callables
getTopLevelClassIds
will be called on the supertypes stage
The problem is that
getTopLevelClassIds
is called very early and I can't figure out how to collect the classes I want to process.
Only using predicates
In ExternalClassGenerator of the fir plugin prototype a predicate is used but when I tried it I got an empty result. I also checked the cache it uses with debugger and it was empty.
That's strange Did you register your predicates in the extension itself?
t
Yes, I think:
Copy code
override fun FirDeclarationPredicateRegistrar.registerPredicates() {
        register(PREDICATE)
    }
d
Are your annotations listed here during debugging?
t
Yes:
As I see it calls FirPredicateBasedProviderImpl.kt but the cache is empty. I'm using the standard plugin test framework btw.