Hi I have class hierarchy like: ```abstract class ...
# ksp
v
Hi I have class hierarchy like:
Copy code
abstract class BaseClass<TypeParam>

abstract class IntermediateClass<TypeParam> : BaseClass<TypeParam>
@MyAnnotation class MyClass: IntermediateClass<String>


abstract class AnotherIntermediateClass: BaseClass<Int>
@MyAnnotation class AnotherMyClass: AnotherIntermediateClass
All classes having
@MyAnnotation
are extending
BaseClass
in one way or another. Can’t figure out how to get the types parametrizing
BaseClass
for
MyClass
and
AnotherMyClass
can someone help me here please?
In other words: given that some type extends
BaseClass
I wan’t to know what is the exact value of the type parameter in
BaseClass
despite of the class hierarchy
j
you should be able to get the value of type parameter from
KSTypeArgument
?
v
No, with a code like this:
Copy code
(myClass.superTypes.first()//returns IntermediateClass<String> (1)
    .resolve() // (2)
    .declaration as KSClassDeclaration)
    .superTypes.first() //returns BaseClass<TypeParam> (3)
    .resolve() 
    .arguments.first()//returns [INVARIANT TypeParam] not a [INVARIANT String]
I can get what you are saying at the
(2)
but at
(3)
the information is already gone. Basically I am looking for the API similar to:
fun KSClassDeclaration.asMemberOfClassHierarchy(containing: KSType): KSType
So I will be able to do something like:
Copy code
resolver.getClassDeclarationByName("com.BaseClass").asMemberOfClassHierarchy(myClassKSType).arguments //should have KSTypeArgument with [INVARIANT String]