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:
Alexander Udalov
2016-07-12 16:50:12 +03:00
parent f69cc01f8e
commit 127e7ab5b7
11 changed files with 89 additions and 21 deletions
@@ -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"
}