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"
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
// KT-9078 (NPE in control flow analysis); EA-71535
|
||||
abstract class KFunctionKt9005WorkAround<out R: Any?>(private val _functionInstance: Function<R>): kotlin.reflect.KCallable<R> {
|
||||
abstract class KFunctionKt9005WorkAround<out R: Any?>(private val _functionInstance: Function<R>) {
|
||||
private val _reflectedFunction: kotlin.reflect.KFunction<R> = _functionInstance.<!UNRESOLVED_REFERENCE!>reflect<!>() ?: throw IllegalStateException("")
|
||||
|
||||
private val _parameters: List<kotlin.reflect.KParameter> = run {
|
||||
@@ -9,4 +9,4 @@ abstract class KFunctionKt9005WorkAround<out R: Any?>(private val _functionInsta
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
package
|
||||
|
||||
public abstract class KFunctionKt9005WorkAround</*0*/ out R> : kotlin.reflect.KCallable<R> {
|
||||
public abstract class KFunctionKt9005WorkAround</*0*/ out R> {
|
||||
public constructor KFunctionKt9005WorkAround</*0*/ out R>(/*0*/ _functionInstance: kotlin.Function<R>)
|
||||
private final val _functionInstance: kotlin.Function<R>
|
||||
private final val _parameters: kotlin.collections.List<kotlin.reflect.KParameter>
|
||||
private final val _reflectedFunction: kotlin.reflect.KFunction<R>
|
||||
public abstract override /*1*/ /*fake_override*/ val annotations: kotlin.collections.List<kotlin.Annotation>
|
||||
public abstract override /*1*/ /*fake_override*/ val name: kotlin.String
|
||||
public abstract override /*1*/ /*fake_override*/ val parameters: kotlin.collections.List<kotlin.reflect.KParameter>
|
||||
public abstract override /*1*/ /*fake_override*/ val returnType: kotlin.reflect.KType
|
||||
public abstract override /*1*/ /*fake_override*/ fun call(/*0*/ vararg args: kotlin.Any? /*kotlin.Array<out kotlin.Any?>*/): R
|
||||
public abstract override /*1*/ /*fake_override*/ fun callBy(/*0*/ args: kotlin.collections.Map<kotlin.reflect.KParameter, kotlin.Any?>): R
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
@@ -12943,6 +12943,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/typeParameters")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class TypeParameters extends AbstractBlackBoxCodegenTest {
|
||||
public void testAllFilesPresentInTypeParameters() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/reflection/typeParameters"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("typeParametersAndNames.kt")
|
||||
public void testTypeParametersAndNames() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/typeParameters/typeParametersAndNames.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/types")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user