[Compatiblity] Restore IdePlatform as well as some related methods
Original commit: dfe0493f9a
This commit is contained in:
@@ -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<Kind : IdePlatformKind<Kind>, 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
|
||||
}
|
||||
@@ -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<Kind : IdePlatformKind<Kind>> {
|
||||
@@ -21,6 +20,13 @@ abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
|
||||
|
||||
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<out CommonCompilerArguments>
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
@@ -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<CommonIdePlatformKind>() {
|
||||
|
||||
@@ -21,6 +21,12 @@ object CommonIdePlatformKind : IdePlatformKind<CommonIdePlatformKind>() {
|
||||
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<CommonIdePlatformKind>() {
|
||||
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<CommonIdePlatformKind, CommonCompilerArguments>() {
|
||||
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
|
||||
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
|
||||
@@ -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<JsIdePlatformKind>() {
|
||||
@@ -24,6 +28,12 @@ object JsIdePlatformKind : IdePlatformKind<JsIdePlatformKind>() {
|
||||
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<JsIdePlatformKind>() {
|
||||
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<JsIdePlatformKind, K2JSCompilerArguments>() {
|
||||
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
|
||||
|
||||
@@ -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<JvmIdePlatformKind>() {
|
||||
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<JvmIdePlatformKind>() {
|
||||
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<JvmIdePlatformKind, K2JVMCompilerArguments>() {
|
||||
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
|
||||
@@ -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<NativeIdePlatformKind>() {
|
||||
@@ -27,6 +31,12 @@ object NativeIdePlatformKind : IdePlatformKind<NativeIdePlatformKind>() {
|
||||
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<NativeIdePlatformKind>() {
|
||||
|
||||
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<NativeIdePlatformKind, FakeK2NativeCompilerArguments>() {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user