Hi guys! I know this may seem a bit crazy, but is ...
# ksp
r
Hi guys! I know this may seem a bit crazy, but is it possible to get the KSType here corresponding to
FirstType
and
SecondType
? I am able to get the KSType corresponding to
AbcType
, but not the other two.
ExternalModuleDestinations
is an
annotation class ExternalModuleDestinations<T: SomeType>
and
ExternalDestination
is also
annotation class ExternalDestination<T: OtherType>
.
Copy code
@ExternalModuleDestinations<AbcType>(
        overriding = [
            ExternalDestination<FirstType>(),
            ExternalDestination<SecondType>(),
        ]
    )
    class SomeClass
When I try, I just get
T
, not the actual types used here (
FirstType
and
SecondType
)
j
Can you try to read the annotation value of
ExternalModuleDestinations
?
r
Hmm how exactly do I do that? šŸ˜… Sorry Iā€™m not familiar with the term
j
say you got the
KSClassDeclaration
of
SomeClass
, you can get the list of its annotations via
KSClassDeclaration.annotations
, iterate through the annotation list, find the annotation with type
ExternalModuleDestinations
, read the annotation values by
KSAnnotation.arguments
r
Im afk now, but I think thatā€™s what Iā€™m doing, yes. Then I get the argument ā€œoverridingā€ and I get an ArrayLisf<KSAnnotation>. Then I try to get the type argument with something like (will confirm shortly)
annotationType.arguments.first().resolve()
I think Iā€™m missing something there, Iā€™ll check it in 5 min
j
donā€™t resolve, by resolving you get the declaration of the types, which surely only contains type parameter.
šŸ¤” 1
r
so this is what I actually do (sorry)
Copy code
it.annotationType.resolve().arguments.first().type!!.resolve()
Ƭt
is a
KSAnnotation
from the
ArrayList<KSAnnotation>
I got from "overriding" argument.
if I don't
resolve
then I get a
KSTypeReference
.. how can I convert that into
KSType
?
I guess I would expect to get
T
if I was using
declaration
, like:
Copy code
it.annotationType.resolve().declaration.typeParameters.first()
Since then I was actually going to the declaration of the annotation type (
ExternalDestination
)
also, I use the exact same code to get the type argument of
@ExternalModuleDestinations<AbcType>
. In that case I do get
AbcType
with
Copy code
ksAnnotation.annotationType.resolve().arguments.first().type!!.resolve()
I get that in this case it is actually annotating, while on the other case I'm passing an "instance" of the annotation class to the "overriding" argument.
@Jiaxiang sorry to tag you, but if you could follow up on this šŸ™ I already have a workaround, but I'm still interested in improving things if this is possible.
j
sorry, your case might be a little bit convoluted to be communicated via chat, can you put your case in a mini repository so I can take a look?