Use experimental javaType in full reflect where it's not supported yet

#KT-22936 Fixed
 #KT-34344 Fixed
This commit is contained in:
Alexander Udalov
2020-05-28 20:48:35 +02:00
parent 9e37b62f62
commit 117aae8a6b
14 changed files with 126 additions and 42 deletions
@@ -26072,6 +26072,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/mapping/types"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("allSupertypes.kt")
public void testAllSupertypes() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/allSupertypes.kt");
}
@TestMetadata("annotationConstructorParameters.kt")
public void testAnnotationConstructorParameters() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/annotationConstructorParameters.kt");
@@ -26087,6 +26092,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/reflection/mapping/types/constructors.kt");
}
@TestMetadata("createType.kt")
public void testCreateType() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/createType.kt");
}
@TestMetadata("genericArrayElementType.kt")
public void testGenericArrayElementType() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/genericArrayElementType.kt");
@@ -0,0 +1,21 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
package test
import kotlin.reflect.full.allSupertypes
import kotlin.reflect.jvm.javaType
import kotlin.test.assertEquals
interface I<T>
abstract class A<X> : Map<I<out CharSequence>, Array<List<Int>>>
fun box(): String {
assertEquals(
"java.util.Map<test.I<? extends java.lang.CharSequence>, java.util.List<? extends java.lang.Integer>[]>",
A::class.allSupertypes.single { it.classifier == Map::class }.javaType.toString()
)
return "OK"
}
@@ -0,0 +1,27 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
package test
import kotlin.reflect.KTypeProjection
import kotlin.reflect.full.createType
import kotlin.reflect.jvm.javaType
import kotlin.test.assertEquals
class A<X>
fun box(): String {
val nullableAOfInString = A::class.createType(listOf(
KTypeProjection.contravariant(String::class.createType())
), true)
assertEquals("test.A<? super java.lang.String>", nullableAOfInString.javaType.toString())
val arrayOfListOfInteger = Array::class.createType(listOf(
KTypeProjection.invariant(List::class.createType(listOf(
KTypeProjection.invariant(Int::class.createType())
)))
))
assertEquals("java.util.List<java.lang.Integer>[]", arrayOfListOfInteger.javaType.toString())
return "OK"
}
@@ -7,7 +7,7 @@ import java.lang.reflect.TypeVariable
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
class A<T> {
class A<T : CharSequence> {
fun foo(t: T) {}
}
@@ -19,5 +19,8 @@ fun box(): String {
assertEquals("T", t.name)
assertEquals(A::class.java, (t.genericDeclaration as Class<*>))
val tp = A::class.typeParameters
assertEquals(CharSequence::class.java, tp.single().upperBounds.single().javaType)
return "OK"
}
@@ -27663,6 +27663,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/mapping/types"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("allSupertypes.kt")
public void testAllSupertypes() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/allSupertypes.kt");
}
@TestMetadata("annotationConstructorParameters.kt")
public void testAnnotationConstructorParameters() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/annotationConstructorParameters.kt");
@@ -27678,6 +27683,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/reflection/mapping/types/constructors.kt");
}
@TestMetadata("createType.kt")
public void testCreateType() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/createType.kt");
}
@TestMetadata("genericArrayElementType.kt")
public void testGenericArrayElementType() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/genericArrayElementType.kt");
@@ -25297,6 +25297,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/mapping/types"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("allSupertypes.kt")
public void testAllSupertypes() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/allSupertypes.kt");
}
@TestMetadata("annotationConstructorParameters.kt")
public void testAnnotationConstructorParameters() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/annotationConstructorParameters.kt");
@@ -25312,6 +25317,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/reflection/mapping/types/constructors.kt");
}
@TestMetadata("createType.kt")
public void testCreateType() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/createType.kt");
}
@TestMetadata("genericArrayElementType.kt")
public void testGenericArrayElementType() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/genericArrayElementType.kt");
@@ -26072,6 +26072,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/mapping/types"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("allSupertypes.kt")
public void testAllSupertypes() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/allSupertypes.kt");
}
@TestMetadata("annotationConstructorParameters.kt")
public void testAnnotationConstructorParameters() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/annotationConstructorParameters.kt");
@@ -26087,6 +26092,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/reflection/mapping/types/constructors.kt");
}
@TestMetadata("createType.kt")
public void testCreateType() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/createType.kt");
}
@TestMetadata("genericArrayElementType.kt")
public void testGenericArrayElementType() throws Exception {
runTest("compiler/testData/codegen/box/reflection/mapping/types/genericArrayElementType.kt");