From 4c4d6dfd23777f2aefe47c1b9520f4c2920da707 Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Fri, 17 May 2019 12:45:48 +0300 Subject: [PATCH] [Compatiblity] Restore IdePlatform as well as some related methods Original commit: dfe0493f9ab2ef5318597275427a912f784ff3f2 --- .../jetbrains/kotlin/platform/IdePlatform.kt | 27 ++++++++++++ .../kotlin/platform/IdePlatformKind.kt | 8 +++- .../platform/compat/compatConversions.kt | 41 +++++++++++++++++++ .../platform/impl/CommonIdePlatformKind.kt | 31 ++++++++++++-- .../kotlin/platform/impl/JsIdePlatformKind.kt | 27 ++++++++++++ .../platform/impl/JvmIdePlatformKind.kt | 27 ++++++++++++ .../platform/impl/NativeIdePlatformKind.kt | 27 ++++++++++++ 7 files changed, 183 insertions(+), 5 deletions(-) create mode 100644 jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt create mode 100644 jps/jps-common/src/org/jetbrains/kotlin/platform/compat/compatConversions.kt diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt new file mode 100644 index 00000000000..03747c37be5 --- /dev/null +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.platform + +import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.utils.DescriptionAware + +@Suppress("DEPRECATION_ERROR") +@Deprecated( + message = "This interface is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead", + replaceWith = ReplaceWith("TargetPlatform", "org.jetbrains.kotlin.platform.TargetPlatform"), + level = DeprecationLevel.ERROR +) +abstract class IdePlatform, out Arguments : CommonCompilerArguments> : DescriptionAware { + abstract val kind: Kind + abstract val version: TargetPlatformVersion + + abstract fun createArguments(init: Arguments.() -> Unit = {}): Arguments + + override val description + get() = kind.name + " " + version.description + + override fun toString() = description +} diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt index 62fe6a4ad79..36e678fa59b 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind -import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult abstract class IdePlatformKind> { @@ -21,6 +20,13 @@ abstract class IdePlatformKind> { abstract val defaultPlatform: TargetPlatform + @Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith") + @Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR + ) + abstract fun getDefaultPlatform(): IdePlatform<*, *> + abstract fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? abstract val argumentsClass: Class diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/compat/compatConversions.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/compat/compatConversions.kt new file mode 100644 index 00000000000..eb9b00e02bd --- /dev/null +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/compat/compatConversions.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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("DEPRECATION_ERROR", "TYPEALIAS_EXPANSION_DEPRECATION_ERROR") + +package org.jetbrains.kotlin.platform.compat + +import org.jetbrains.kotlin.platform.CommonPlatforms +import org.jetbrains.kotlin.platform.IdePlatform +import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind +import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind +import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind +import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind +import org.jetbrains.kotlin.platform.js.JsPlatform +import org.jetbrains.kotlin.platform.js.JsPlatforms +import org.jetbrains.kotlin.platform.jvm.JdkPlatform +import org.jetbrains.kotlin.platform.jvm.JvmPlatform +import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.platform.konan.KonanPlatform +import org.jetbrains.kotlin.platform.konan.KonanPlatforms + +typealias OldPlatform = org.jetbrains.kotlin.resolve.TargetPlatform +typealias NewPlatform = org.jetbrains.kotlin.platform.TargetPlatform + +fun NewPlatform.toOldPlatform(): OldPlatform = when (val single = singleOrNull()) { + null -> CommonPlatforms.CompatCommonPlatform + is JvmPlatform -> JvmPlatforms.CompatJvmPlatform + is JsPlatform -> JsPlatforms.CompatJsPlatform + is KonanPlatform -> KonanPlatforms.CompatKonanPlatform + else -> error("Unknown platform $single") +} + +fun IdePlatform<*, *>.toNewPlatform(): NewPlatform = when (this) { + is CommonIdePlatformKind.Platform -> CommonPlatforms.defaultCommonPlatform + is JvmIdePlatformKind.Platform -> JvmPlatforms.jvmPlatformByTargetVersion(this.version) + is JsIdePlatformKind.Platform -> JsPlatforms.defaultJsPlatform + is NativeIdePlatformKind.Platform -> KonanPlatforms.defaultKonanPlatform + else -> error("Unknown platform $this") +} diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/CommonIdePlatformKind.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/CommonIdePlatformKind.kt index 78573f2887c..f4edd270b5a 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/CommonIdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/CommonIdePlatformKind.kt @@ -4,13 +4,13 @@ */ @file:JvmName("CommonIdePlatformUtil") +@file:Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith") + package org.jetbrains.kotlin.platform.impl import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments -import org.jetbrains.kotlin.platform.CommonPlatforms -import org.jetbrains.kotlin.platform.IdePlatformKind -import org.jetbrains.kotlin.platform.TargetPlatform +import org.jetbrains.kotlin.platform.* object CommonIdePlatformKind : IdePlatformKind() { @@ -21,6 +21,12 @@ object CommonIdePlatformKind : IdePlatformKind() { null } + @Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR + ) + override fun getDefaultPlatform(): IdePlatform<*, *> = Platform + override fun createArguments(): CommonCompilerArguments { return K2MetadataCompilerArguments() // TODO(dsavvinov): review that, as now MPP !== K2Metadata } @@ -31,7 +37,24 @@ object CommonIdePlatformKind : IdePlatformKind() { override val argumentsClass get() = K2MetadataCompilerArguments::class.java override val name get() = "Common (experimental)" + + @Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR + ) + object Platform : IdePlatform() { + override val kind get() = CommonIdePlatformKind + override val version get() = TargetPlatformVersion.NoVersion + override fun createArguments(init: CommonCompilerArguments.() -> Unit) = K2MetadataCompilerArguments().apply(init) + } } val IdePlatformKind<*>?.isCommon - get() = this is CommonIdePlatformKind \ No newline at end of file + get() = this is CommonIdePlatformKind + +@Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR +) +val IdePlatform<*, *>.isCommon: Boolean + get() = this is CommonIdePlatformKind.Platform \ No newline at end of file diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JsIdePlatformKind.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JsIdePlatformKind.kt index a6b284144a3..505d6cdd126 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JsIdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JsIdePlatformKind.kt @@ -4,12 +4,16 @@ */ @file:JvmName("JsIdePlatformUtil") +@file:Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith") + package org.jetbrains.kotlin.platform.impl import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments +import org.jetbrains.kotlin.platform.IdePlatform import org.jetbrains.kotlin.platform.IdePlatformKind import org.jetbrains.kotlin.platform.TargetPlatform +import org.jetbrains.kotlin.platform.TargetPlatformVersion import org.jetbrains.kotlin.platform.js.JsPlatforms object JsIdePlatformKind : IdePlatformKind() { @@ -24,6 +28,12 @@ object JsIdePlatformKind : IdePlatformKind() { override val platforms get() = listOf(JsPlatforms.defaultJsPlatform) override val defaultPlatform get() = JsPlatforms.defaultJsPlatform + @Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR + ) + override fun getDefaultPlatform(): IdePlatform<*, *> = Platform + override fun createArguments(): CommonCompilerArguments { return K2JSCompilerArguments() } @@ -31,7 +41,24 @@ object JsIdePlatformKind : IdePlatformKind() { override val argumentsClass get() = K2JSCompilerArguments::class.java override val name get() = "JavaScript" + + @Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR + ) + object Platform : IdePlatform() { + override val kind get() = JsIdePlatformKind + override val version get() = TargetPlatformVersion.NoVersion + override fun createArguments(init: K2JSCompilerArguments.() -> Unit) = K2JSCompilerArguments().apply(init) + } } val IdePlatformKind<*>?.isJavaScript get() = this is JsIdePlatformKind + +@Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR +) +val IdePlatform<*, *>?.isJavaScript + get() = this is JsIdePlatformKind.Platform diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt index 7b0cf7f506b..d996cb294f8 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt @@ -4,6 +4,7 @@ */ @file:JvmName("JvmIdePlatformUtil") +@file:Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith") package org.jetbrains.kotlin.platform.impl @@ -11,6 +12,7 @@ import com.intellij.util.text.VersionComparatorUtil import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.config.JvmTarget +import org.jetbrains.kotlin.platform.IdePlatform import org.jetbrains.kotlin.platform.IdePlatformKind import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.platform.jvm.JvmPlatforms @@ -30,6 +32,12 @@ object JvmIdePlatformKind : IdePlatformKind() { return JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget) } + @Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR + ) + override fun getDefaultPlatform(): Platform = Platform(JvmTarget.JVM_1_6) + override fun createArguments(): CommonCompilerArguments { return K2JVMCompilerArguments() } @@ -40,7 +48,26 @@ object JvmIdePlatformKind : IdePlatformKind() { override val argumentsClass get() = K2JVMCompilerArguments::class.java override val name get() = "JVM" + + @Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR + ) + data class Platform(override val version: JvmTarget) : IdePlatform() { + override val kind get() = JvmIdePlatformKind + + override fun createArguments(init: K2JVMCompilerArguments.() -> Unit) = K2JVMCompilerArguments() + .apply(init) + .apply { jvmTarget = this@Platform.version.description } + } } val IdePlatformKind<*>?.isJvm get() = this is JvmIdePlatformKind + +@Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR +) +val IdePlatform<*, *>.isJvm: Boolean + get() = this is JvmIdePlatformKind.Platform \ No newline at end of file diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt index 2c5c803c0b1..ed0fe8f18f4 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt @@ -4,11 +4,15 @@ */ @file:JvmName("NativeIdePlatformUtil") +@file:Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith") + package org.jetbrains.kotlin.platform.impl import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.platform.IdePlatform import org.jetbrains.kotlin.platform.IdePlatformKind import org.jetbrains.kotlin.platform.TargetPlatform +import org.jetbrains.kotlin.platform.TargetPlatformVersion import org.jetbrains.kotlin.platform.konan.KonanPlatforms object NativeIdePlatformKind : IdePlatformKind() { @@ -27,6 +31,12 @@ object NativeIdePlatformKind : IdePlatformKind() { override val defaultPlatform: TargetPlatform get() = KonanPlatforms.defaultKonanPlatform + @Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR + ) + override fun getDefaultPlatform(): IdePlatform<*, *> = Platform + override val platforms get() = listOf(KonanPlatforms.defaultKonanPlatform) @@ -35,6 +45,16 @@ object NativeIdePlatformKind : IdePlatformKind() { override val name get() = "Native" + + @Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR + ) + object Platform : IdePlatform() { + override val kind get() = NativeIdePlatformKind + override val version get() = TargetPlatformVersion.NoVersion + override fun createArguments(init: FakeK2NativeCompilerArguments.() -> Unit) = FakeK2NativeCompilerArguments().apply(init) + } } // These are fake compiler arguments for Kotlin/Native - only for usage within IDEA plugin: @@ -42,3 +62,10 @@ class FakeK2NativeCompilerArguments : CommonCompilerArguments() val IdePlatformKind<*>?.isKotlinNative get() = this is NativeIdePlatformKind + +@Deprecated( + message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", + level = DeprecationLevel.ERROR +) +val IdePlatform<*, *>?.isKotlinNative + get() = this is NativeIdePlatformKind.Platform