Support flexible types internally in typeOf

#KT-45066 Fixed
This commit is contained in:
Alexander Udalov
2021-05-21 19:27:59 +02:00
parent 26cdb2f928
commit 6e975b3498
21 changed files with 358 additions and 42 deletions
@@ -183,4 +183,11 @@ public class Reflection {
public static void setUpperBounds(KTypeParameter typeParameter, KType... bounds) {
factory.setUpperBounds(typeParameter, ArraysKt.toList(bounds));
}
// Features of stable typeOf
@SinceKotlin(version = "1.6")
public static KType platformType(KType lowerBound, KType upperBound) {
return factory.platformType(lowerBound, upperBound);
}
}
@@ -93,4 +93,9 @@ public class ReflectionFactory {
public void setUpperBounds(KTypeParameter typeParameter, List<KType> bounds) {
((TypeParameterReference) typeParameter).setUpperBounds(bounds);
}
@SinceKotlin(version = "1.6")
public KType platformType(KType lowerBound, KType upperBound) {
return new TypeReference(lowerBound.getClassifier(), lowerBound.getArguments(), lowerBound.isMarkedNullable(), upperBound);
}
}
@@ -3,22 +3,32 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("NEWER_VERSION_IN_SINCE_KOTLIN")
package kotlin.jvm.internal
import kotlin.reflect.*
@SinceKotlin("1.4")
public class TypeReference(
public class TypeReference /* @SinceKotlin("1.6") constructor */(
override val classifier: KClassifier,
override val arguments: List<KTypeProjection>,
override val isMarkedNullable: Boolean
override val isMarkedNullable: Boolean,
private val platformTypeUpperBound: KType?,
) : KType {
constructor(
classifier: KClassifier,
arguments: List<KTypeProjection>,
isMarkedNullable: Boolean,
) : this(classifier, arguments, isMarkedNullable, null)
override val annotations: List<Annotation>
get() = emptyList()
override fun equals(other: Any?): Boolean =
other is TypeReference &&
classifier == other.classifier && arguments == other.arguments && isMarkedNullable == other.isMarkedNullable
classifier == other.classifier && arguments == other.arguments && isMarkedNullable == other.isMarkedNullable &&
platformTypeUpperBound == other.platformTypeUpperBound
override fun hashCode(): Int =
(classifier.hashCode() * 31 + arguments.hashCode()) * 31 + isMarkedNullable.hashCode()
@@ -3995,6 +3995,7 @@ public class kotlin/jvm/internal/Reflection {
public static fun nullableTypeOf (Ljava/lang/Class;Lkotlin/reflect/KTypeProjection;Lkotlin/reflect/KTypeProjection;)Lkotlin/reflect/KType;
public static fun nullableTypeOf (Ljava/lang/Class;[Lkotlin/reflect/KTypeProjection;)Lkotlin/reflect/KType;
public static fun nullableTypeOf (Lkotlin/reflect/KClassifier;)Lkotlin/reflect/KType;
public static fun platformType (Lkotlin/reflect/KType;Lkotlin/reflect/KType;)Lkotlin/reflect/KType;
public static fun property0 (Lkotlin/jvm/internal/PropertyReference0;)Lkotlin/reflect/KProperty0;
public static fun property1 (Lkotlin/jvm/internal/PropertyReference1;)Lkotlin/reflect/KProperty1;
public static fun property2 (Lkotlin/jvm/internal/PropertyReference2;)Lkotlin/reflect/KProperty2;
@@ -4021,6 +4022,7 @@ public class kotlin/jvm/internal/ReflectionFactory {
public fun mutableProperty0 (Lkotlin/jvm/internal/MutablePropertyReference0;)Lkotlin/reflect/KMutableProperty0;
public fun mutableProperty1 (Lkotlin/jvm/internal/MutablePropertyReference1;)Lkotlin/reflect/KMutableProperty1;
public fun mutableProperty2 (Lkotlin/jvm/internal/MutablePropertyReference2;)Lkotlin/reflect/KMutableProperty2;
public fun platformType (Lkotlin/reflect/KType;Lkotlin/reflect/KType;)Lkotlin/reflect/KType;
public fun property0 (Lkotlin/jvm/internal/PropertyReference0;)Lkotlin/reflect/KProperty0;
public fun property1 (Lkotlin/jvm/internal/PropertyReference1;)Lkotlin/reflect/KProperty1;
public fun property2 (Lkotlin/jvm/internal/PropertyReference2;)Lkotlin/reflect/KProperty2;
@@ -4120,6 +4122,7 @@ public final class kotlin/jvm/internal/TypeParameterReference$Companion {
public final class kotlin/jvm/internal/TypeReference : kotlin/reflect/KType {
public fun <init> (Lkotlin/reflect/KClassifier;Ljava/util/List;Z)V
public fun <init> (Lkotlin/reflect/KClassifier;Ljava/util/List;ZLkotlin/reflect/KType;)V
public fun equals (Ljava/lang/Object;)Z
public fun getAnnotations ()Ljava/util/List;
public fun getArguments ()Ljava/util/List;