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()