Vladimir Tagakov
06/09/2022, 8:03 PMabstract 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?BaseClass
I wan’t to know what is the exact value of the type parameter in BaseClass
despite of the class hierarchyabstract class BaseClass<TypeParam> {
fun dummy(param: TypeParam)
}
then I can get the KSFunction and using asMemberOf
with my MyClass
or AnotherMyClass
I can compute the parameter’s value (String and Int respectively). The question is: is it possible to achieve the same behavior without adding additional function to the BaseClass
? Looks like there is no way to do it in KSPJiaxiang
06/10/2022, 12:01 AMKSTypeArgument
?Vladimir Tagakov
06/10/2022, 12:13 AM(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:
resolver.getClassDeclarationByName("com.BaseClass").asMemberOfClassHierarchy(myClassKSType).arguments //should have KSTypeArgument with [INVARIANT String]