https://kotlinlang.org logo
Title
y

yamasa

02/19/2021, 4:49 PM
Suppose a code like this:
class Outer<T> {
    inner class Inner
}

val foo: Outer<String>.Inner
    get() = TODO()
Is there a way to get the type argument
String
from
KSPropertyDeclaration.type
of the property
foo
? I tried
fooPropertyDeclaration.type.resolve().declaration.parentDeclaration?.typeParameters?.get(0)
, but it was
T
, not
String
.
y

yigit

02/19/2021, 4:50 PM
you want the type arguments of the KS Type. 1sec
ksType.arguments
in room we needed the declaration as well (KSTypeParameter) to resolve variance when generating java code
so you probably don't need it
y

yamasa

02/19/2021, 4:56 PM
Hmm... Since
Inner
itself has no type parameter,
fooPropertyDeclaration.type.resolve().arguments
is empty. I'd like to access the
ksType
of
Outer
, but I don't know how to do it.
y

yigit

02/19/2021, 4:57 PM
oh, hmm
didn't notice that part sorry
t

Ting-Yuan Huang

02/19/2021, 6:39 PM
You don't need to resolve a type reference to get its type arguments.
// returns String
(fooPropertyDeclaration.type.element as KSClassifierReference).qualifier.typeArguments
On the other hand, it looks like a bug to me that the
KSType
for
Inner
has no type argument. Unlike nested types, inner types should carry type arguments from their outer types.
y

yamasa

02/20/2021, 3:33 AM
Thank you. I'm looking forward to it being fixed!