Multi-modules: superTypes doesn't return the super types
See original GitHub issueI’m processing an interface (with generics) from another module, this interface extends another interface (also with generics), I can get the properties & functions from the super but superTypes and getAllSuperTypes() returns nothing.
SSCCE: https://github.com/glureau/ksp-kmp-issues/tree/ksp_multimodule_supers Slack: https://kotlinlang.slack.com/archives/C013BA8EQSE/p1641980604009600
(KSP 1.6.0-1.0.2)
Processing from same module: OK
Given an interface extending another interface in mymodule
(Base.kt)
package ksp.example
@MyAnnotation
interface Base<T> {
fun provide(): T
}
@MyAnnotation
interface Advanced<T> : Base<T>
Using KSP on the mymodule
will properly resolve Advanced
super.
> Task :mymodule:kspKotlinMetadata
> w: [ksp] Supers of Advanced: 1
Processing from another module: KO
If I wrote another module and define an annotation that points to Advanced
class (here)
@file:MyFileAnnotation(
klass = Advanced::class
)
package ksp.example
And if I define my processor this way:
resolver.getSymbolsWithAnnotation(MyFileAnnotation::class.java.name).forEach {
it.accept(object : KSVisitorVoid() {
override fun visitFile(file: KSFile, data: Unit) {
file.annotations.forEach { ksAnnotation ->
val klass = ksAnnotation.getArg<KSType>(MyFileAnnotation::klass)
val classDeclaration = klass.declaration as KSClassDeclaration
environment.logger.warn("From another module - Supers of ${classDeclaration.simpleName.asString()}: ${classDeclaration.superTypes.count()}")
}
}
}, Unit)
}
then it’s logging that Advanced have no supers.
[ksp] From another module - Supers of Advanced: 0
I was expecting to found the Base class here, like for the 1st example.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8
Glad it worked out for you!
As for your question, the annotations on a type a part of the type system, usually you don’t need them, they can be found if the annotation is applied on the type rather than the property, you only need to check type annotations if you know you are looking for type annotations.
This release fixes this issue I reported on Slack (kinda related)