Reflection: add KClass.typeParameters, KCallable.typeParameters
Inheritance from KCallable is removed in kt9078.kt because it was irrelevant to the test and because it gets in the way of modification of KCallable
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class F {
|
||||
fun <A> foo() {}
|
||||
val <B> B.bar: B get() = this
|
||||
}
|
||||
|
||||
class C<D> {
|
||||
fun baz() {}
|
||||
fun <E, G> quux() {}
|
||||
}
|
||||
|
||||
fun get(klass: KClass<*>, memberName: String? = null): List<String> =
|
||||
(if (memberName != null)
|
||||
klass.members.single { it.name == memberName }.typeParameters
|
||||
else
|
||||
klass.typeParameters)
|
||||
.map { it.name }
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf(), get(F::class))
|
||||
assertEquals(listOf("A"), get(F::class, "foo"))
|
||||
assertEquals(listOf("B"), get(F::class, "bar"))
|
||||
|
||||
assertEquals(listOf("D"), get(C::class))
|
||||
assertEquals(listOf(), get(C::class, "baz"))
|
||||
assertEquals(listOf("E", "G"), get(C::class, "quux"))
|
||||
|
||||
assertEquals(listOf("T"), get(Comparable::class))
|
||||
assertEquals(listOf(), get(String::class))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user