Reflection: add KType.withNullability
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.withNullability
|
||||
import kotlin.reflect.jvm.javaType
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun nonNull(): String = ""
|
||||
fun nullable(): String? = ""
|
||||
|
||||
fun box(): String {
|
||||
val nonNull = ::nonNull.returnType
|
||||
val nullable = ::nullable.returnType
|
||||
|
||||
assertEquals(nullable.javaType, nullable.withNullability(false).javaType)
|
||||
assertEquals(nullable.javaType, nullable.withNullability(true).javaType)
|
||||
assertEquals(nonNull.javaType, nonNull.withNullability(false).javaType)
|
||||
assertEquals(nullable.javaType, nonNull.withNullability(true).javaType)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public interface J {
|
||||
String platform();
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.withNullability
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun nonNull(): String = ""
|
||||
fun nullable(): String? = ""
|
||||
|
||||
fun box(): String {
|
||||
val nonNull = ::nonNull.returnType
|
||||
val nullable = ::nullable.returnType
|
||||
val platform = J::platform.returnType
|
||||
|
||||
assertEquals(nonNull, nullable.withNullability(false))
|
||||
assertEquals(nullable, nullable.withNullability(true))
|
||||
assertEquals(nonNull, nonNull.withNullability(false))
|
||||
assertEquals(nullable, nonNull.withNullability(true))
|
||||
|
||||
assertEquals(nonNull, platform.withNullability(false))
|
||||
assertEquals(nullable, platform.withNullability(true))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -12490,6 +12490,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/mapping/types/unit.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withNullability.kt")
|
||||
public void testWithNullability() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/mapping/types/withNullability.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13056,6 +13062,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("withNullability.kt")
|
||||
public void testWithNullability() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reflection/types/withNullability.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/types/createType")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user