From 881906d1db7d955d632bb4e2655407673649a382 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 25 Dec 2019 23:05:12 +0300 Subject: [PATCH] Commonize kotlin.reflect API KClassifier, KTypeProjection, and KVariance were moved to common (cherry picked from commit 0ce1a3592279eb515d0746ba639d0cfe2e958b23) --- .../src/main/kotlin/kotlin/reflect/KClass.kt | 4 +- .../main/kotlin/kotlin/reflect/KClassifier.kt | 15 ----- .../main/kotlin/kotlin/reflect/KFunction.kt | 2 +- .../src/main/kotlin/kotlin/reflect/KType.kt | 61 ++----------------- .../main/kotlin/kotlin/reflect/KVariance.kt | 34 ----------- 5 files changed, 7 insertions(+), 109 deletions(-) delete mode 100644 runtime/src/main/kotlin/kotlin/reflect/KClassifier.kt delete mode 100644 runtime/src/main/kotlin/kotlin/reflect/KVariance.kt diff --git a/runtime/src/main/kotlin/kotlin/reflect/KClass.kt b/runtime/src/main/kotlin/kotlin/reflect/KClass.kt index fa6f01312ed..585050e0725 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KClass.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KClass.kt @@ -24,13 +24,13 @@ public actual interface KClass : KDeclarationContainer, KAnnotatedEleme * The fully qualified dot-separated name of the class, * or `null` if the class is local or it is an anonymous object literal. */ - public val qualifiedName: String? + public actual val qualifiedName: String? /** * Returns `true` if [value] is an instance of this class on a given platform. */ @SinceKotlin("1.1") - public fun isInstance(value: Any?): Boolean + public actual fun isInstance(value: Any?): Boolean /** * Returns `true` if this [KClass] instance represents the same Kotlin class as the class represented by [other]. diff --git a/runtime/src/main/kotlin/kotlin/reflect/KClassifier.kt b/runtime/src/main/kotlin/kotlin/reflect/KClassifier.kt deleted file mode 100644 index b1c26599a98..00000000000 --- a/runtime/src/main/kotlin/kotlin/reflect/KClassifier.kt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. - */ - -package kotlin.reflect - -/** - * A classifier is either a class or a type parameter. - * - * @see [KClass] - * @see [KTypeParameter] - */ -@SinceKotlin("1.1") -public interface KClassifier diff --git a/runtime/src/main/kotlin/kotlin/reflect/KFunction.kt b/runtime/src/main/kotlin/kotlin/reflect/KFunction.kt index 56c2afcf0d1..3197c00cf7d 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KFunction.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KFunction.kt @@ -5,4 +5,4 @@ package kotlin.reflect -interface KFunction : KCallable +public actual interface KFunction : KCallable, Function diff --git a/runtime/src/main/kotlin/kotlin/reflect/KType.kt b/runtime/src/main/kotlin/kotlin/reflect/KType.kt index c34d47d3e86..8bdc56c3288 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KType.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KType.kt @@ -9,7 +9,7 @@ package kotlin.reflect * Represents a type. Type is usually either a class with optional type arguments, * or a type parameter of some declaration, plus nullability. */ -public interface KType { +public actual interface KType { /** * The declaration of the classifier used in this type. * For example, in the type `List` the classifier would be the [KClass] instance for [List]. @@ -17,7 +17,7 @@ public interface KType { * Returns `null` if this type is not denotable in Kotlin, for example if it is an intersection type. */ @SinceKotlin("1.1") - public val classifier: KClassifier? + public actual val classifier: KClassifier? /** * Type arguments passed for the parameters of the classifier in this type. @@ -28,7 +28,7 @@ public interface KType { * For example, in the type `Outer.Inner` the returned list is `[C, D, A, B]`. */ @SinceKotlin("1.1") - public val arguments: List + public actual val arguments: List /** * `true` if this type was marked nullable in the source code. @@ -47,58 +47,5 @@ public interface KType { * } * ``` */ - public val isMarkedNullable: Boolean -} - -/** - * Represents a type projection. Type projection is usually the argument to another type in a type usage. - * For example, in the type `Array`, `out Number` is the covariant projection of the type represented by the class `Number`. - * - * Type projection is either the star projection, or an entity consisting of a specific type plus optional variance. - * - * See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/generics.html#type-projections) - * for more information. - */ -@SinceKotlin("1.1") -public data class KTypeProjection constructor( - /** - * The use-site variance specified in the projection, or `null` if this is a star projection. - */ - public val variance: KVariance?, - /** - * The type specified in the projection, or `null` if this is a star projection. - */ - public val type: KType? -) { - public companion object { - /** - * Star projection, denoted by the `*` character. - * For example, in the type `KClass<*>`, `*` is the star projection. - * See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/generics.html#star-projections) - * for more information. - */ - public val STAR: KTypeProjection = KTypeProjection(null, null) - - /** - * Creates an invariant projection of a given type. Invariant projection is just the type itself, - * without any use-site variance modifiers applied to it. - * For example, in the type `Set`, `String` is an invariant projection of the type represented by the class `String`. - */ - public fun invariant(type: KType): KTypeProjection = - KTypeProjection(KVariance.INVARIANT, type) - - /** - * Creates a contravariant projection of a given type, denoted by the `in` modifier applied to a type. - * For example, in the type `MutableList`, `in Number` is a contravariant projection of the type of class `Number`. - */ - public fun contravariant(type: KType): KTypeProjection = - KTypeProjection(KVariance.IN, type) - - /** - * Creates a covariant projection of a given type, denoted by the `out` modifier applied to a type. - * For example, in the type `Array`, `out Number` is a covariant projection of the type of class `Number`. - */ - public fun covariant(type: KType): KTypeProjection = - KTypeProjection(KVariance.OUT, type) - } + public actual val isMarkedNullable: Boolean } diff --git a/runtime/src/main/kotlin/kotlin/reflect/KVariance.kt b/runtime/src/main/kotlin/kotlin/reflect/KVariance.kt deleted file mode 100644 index babb04cc40f..00000000000 --- a/runtime/src/main/kotlin/kotlin/reflect/KVariance.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. - */ - -package kotlin.reflect - -/** - * Represents variance applied to a type parameter on the declaration site (*declaration-site variance*), - * or to a type in a projection (*use-site variance*). - * - * See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/generics.html#variance) - * for more information. - * - * @see [KTypeParameter.variance] - * @see [KTypeProjection] - */ -@SinceKotlin("1.1") -enum class KVariance { - /** - * The affected type parameter or type is *invariant*, which means it has no variance applied to it. - */ - INVARIANT, - - /** - * The affected type parameter or type is *contravariant*. Denoted by the `in` modifier in the source code. - */ - IN, - - /** - * The affected type parameter or type is *covariant*. Denoted by the `out` modifier in the source code. - */ - OUT, -} \ No newline at end of file