diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/analyzer/common/CommonPlatform.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/analyzer/common/CommonPlatform.kt new file mode 100644 index 00000000000..7425214f23e --- /dev/null +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/analyzer/common/CommonPlatform.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. + */ + +@file:Suppress("DEPRECATION_ERROR") + +package org.jetbrains.kotlin.analyzer.common + +import org.jetbrains.kotlin.platform.CommonPlatforms +import org.jetbrains.kotlin.resolve.TargetPlatform + +@Deprecated( + message = "This class is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead", + replaceWith = ReplaceWith("CommonPlatforms.defaultCommonPlatform", "org.jetbrains.kotlin.platform.CommonPlatforms"), + level = DeprecationLevel.ERROR +) +interface CommonPlatform : TargetPlatform { + @JvmDefault + override val platformName: String + get() = "Default" + + companion object { + @JvmField + val INSTANCE: CommonPlatform = CommonPlatforms.CompatCommonPlatform + } +} diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/platform/CommonPlatforms.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/platform/CommonPlatforms.kt index f8590400d7b..6eaa3195107 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/platform/CommonPlatforms.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/platform/CommonPlatforms.kt @@ -13,15 +13,23 @@ import org.jetbrains.kotlin.platform.jvm.JvmPlatforms.jvm18 import org.jetbrains.kotlin.platform.konan.KonanPlatforms import org.jetbrains.kotlin.platform.konan.KonanPlatforms.defaultKonanPlatform +@Suppress("DEPRECATION_ERROR") object CommonPlatforms { - val defaultCommonPlatform: TargetPlatform = TargetPlatform( + @Deprecated( + message = "Should be accessed only by compatibility layer, other clients should use 'defaultJvmPlatform'", + level = DeprecationLevel.ERROR + ) + object CompatCommonPlatform : TargetPlatform( setOf( defaultJvmPlatform.single(), defaultJsPlatform.single(), defaultKonanPlatform.single() ) - ) + ), org.jetbrains.kotlin.analyzer.common.CommonPlatform + + val defaultCommonPlatform: TargetPlatform + get() = CompatCommonPlatform val allSimplePlatforms: List get() = sequence { diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/platform/konan/KonanPlatform.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/platform/konan/KonanPlatform.kt index 1ae71f6a025..f0c10d0adfa 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/platform/konan/KonanPlatform.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/platform/konan/KonanPlatform.kt @@ -14,8 +14,20 @@ abstract class KonanPlatform : SimplePlatform("Native") { get() = "Kotlin/Native " } +@Suppress("DEPRECATION_ERROR") object KonanPlatforms { - val defaultKonanPlatform: TargetPlatform = object : KonanPlatform() {}.toTargetPlatform() + private object DefaultSimpleKonanPlatform : KonanPlatform() + + @Deprecated( + message = "Should be accessed only by compatibility layer, other clients should use 'defaultKonanPlatform'", + level = DeprecationLevel.ERROR + ) + object CompatKonanPlatform : TargetPlatform(setOf(DefaultSimpleKonanPlatform)), + // Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions + org.jetbrains.kotlin.resolve.konan.platform.KonanPlatform {} + + val defaultKonanPlatform: TargetPlatform + get() = CompatKonanPlatform val allKonanPlatforms: List = listOf(defaultKonanPlatform) } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/resolve/konan/platform/KonanPlatform.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/resolve/konan/platform/KonanPlatform.kt new file mode 100644 index 00000000000..ce235acaea1 --- /dev/null +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/resolve/konan/platform/KonanPlatform.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. + */ + +@file:Suppress("DEPRECATION_ERROR") + +package org.jetbrains.kotlin.resolve.konan.platform + +import org.jetbrains.kotlin.platform.konan.KonanPlatforms +import org.jetbrains.kotlin.resolve.TargetPlatform + +@Deprecated( + message = "This class is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead", + replaceWith = ReplaceWith("KonanPlatforms.defaultKonanPlatform", "org.jetbrains.kotlin.platform.konan.KonanPlatforms"), + level = DeprecationLevel.ERROR +) +interface KonanPlatform : TargetPlatform { + @JvmDefault + override val platformName: String + get() = "Native" + + companion object { + @JvmField + val INSTANCE: KonanPlatform = KonanPlatforms.CompatKonanPlatform + } +} diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt new file mode 100644 index 00000000000..b8592a3aac7 --- /dev/null +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2010-2018 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.resolve + +@Deprecated( + message = "This class 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 +) +interface TargetPlatform { + val platformName: String +} diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/platform/jvm/JvmPlatform.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/platform/jvm/JvmPlatform.kt index 1e95c1a111e..0b17a2dbc5e 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/platform/jvm/JvmPlatform.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/platform/jvm/JvmPlatform.kt @@ -16,11 +16,26 @@ abstract class JvmPlatform : SimplePlatform("JVM") { get() = "JVM " } +@Suppress("DEPRECATION_ERROR") object JvmPlatforms { + private object UnspecifiedSimpleJvmPlatform : JvmPlatform() { + override val targetPlatformVersion: TargetPlatformVersion + get() = JvmTarget.JVM_1_6 + } + + @Deprecated( + message = "Should be accessed only by compatibility layer, other clients should use 'defaultJvmPlatform'", + level = DeprecationLevel.ERROR + ) + object CompatJvmPlatform : TargetPlatform(setOf(UnspecifiedSimpleJvmPlatform)), + // Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions + org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform {} + private val jvmTargetToJdkPlatform: Map = JvmTarget.values().map { it to JdkPlatform(it).toTargetPlatform() }.toMap() - val defaultJvmPlatform: TargetPlatform = jvmTargetToJdkPlatform[JvmTarget.DEFAULT]!! + val defaultJvmPlatform: TargetPlatform + get() = CompatJvmPlatform val jvm16: TargetPlatform = jvmTargetToJdkPlatform[JvmTarget.JVM_1_6]!! val jvm18: TargetPlatform = jvmTargetToJdkPlatform[JvmTarget.JVM_1_8]!! diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatform.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatform.kt new file mode 100644 index 00000000000..ac8448ec3bc --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatform.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. + */ + +@file:Suppress("DEPRECATION_ERROR") + +package org.jetbrains.kotlin.resolve.jvm.platform + +import org.jetbrains.kotlin.platform.jvm.JvmPlatforms +import org.jetbrains.kotlin.resolve.TargetPlatform + +@Deprecated( + message = "This class is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead", + replaceWith = ReplaceWith("JvmPlatforms.defaultJvmPlatform", "org.jetbrains.kotlin.platform.jvm.JvmPlatforms"), + level = DeprecationLevel.ERROR +) +interface JvmPlatform : TargetPlatform { + @JvmDefault + override val platformName: String + get() = "JVM" + + companion object { + @JvmField + val INSTANCE: JvmPlatform = JvmPlatforms.CompatJvmPlatform + } +} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/platform/TargetPlatform.kt b/core/descriptors/src/org/jetbrains/kotlin/platform/TargetPlatform.kt index 100b46910d3..88cdb279ade 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/platform/TargetPlatform.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/platform/TargetPlatform.kt @@ -18,12 +18,26 @@ package org.jetbrains.kotlin.platform * it still can be applicable for [TargetPlatform]s with [componentPlatforms] > 1, e.g. when it consists * of two version of JDK, JDK and Android, several versions of Android API, etc. */ -data class TargetPlatform(val componentPlatforms: Set) : Collection by componentPlatforms { +open class TargetPlatform(val componentPlatforms: Set) : Collection by componentPlatforms { init { if (componentPlatforms.isEmpty()) throw IllegalArgumentException("Don't instantiate TargetPlatform with empty set of platforms") } override fun toString(): String = presentableDescription + + override fun equals(other: Any?): Boolean { + if (this === other) return true + + if (other !is TargetPlatform) return false + + if (componentPlatforms != other.componentPlatforms) return false + + return true + } + + override fun hashCode(): Int { + return componentPlatforms.hashCode() + } } /** diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt index 8293ec6ac5a..7b0cf7f506b 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt @@ -34,7 +34,7 @@ object JvmIdePlatformKind : IdePlatformKind() { return K2JVMCompilerArguments() } - override val platforms = JvmTarget.values().map { ver -> JvmPlatforms.jvmPlatformByTargetVersion(ver) } + override val platforms: List = JvmTarget.values().map { ver -> JvmPlatforms.jvmPlatformByTargetVersion(ver) } + listOf(JvmPlatforms.defaultJvmPlatform) override val defaultPlatform get() = JvmPlatforms.defaultJvmPlatform override val argumentsClass get() = K2JVMCompilerArguments::class.java diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatform.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatform.kt new file mode 100644 index 00000000000..92e80de4868 --- /dev/null +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatform.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:Suppress("DEPRECATION_ERROR") + +package org.jetbrains.kotlin.js.resolve + +import org.jetbrains.kotlin.platform.js.JsPlatforms +import org.jetbrains.kotlin.resolve.TargetPlatform + +@Deprecated( + message = "This class is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead", + replaceWith = ReplaceWith("JsPlatforms.defaultJsPlatform", "org.jetbrains.kotlin.platform.js.JsPlatforms"), + level = DeprecationLevel.ERROR +) +interface JsPlatform : TargetPlatform { + @JvmDefault + override val platformName: String + get() = "JS" + + companion object { + @JvmField + val INSTANCE: JsPlatform = JsPlatforms.CompatJsPlatform + } +} diff --git a/js/js.frontend/src/org/jetbrains/kotlin/platform/js/JsPlatform.kt b/js/js.frontend/src/org/jetbrains/kotlin/platform/js/JsPlatform.kt index b20cc4e433b..a850db860b6 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/platform/js/JsPlatform.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/platform/js/JsPlatform.kt @@ -14,8 +14,20 @@ abstract class JsPlatform : SimplePlatform("JS") { get() = "JavaScript " } +@Suppress("DEPRECATION_ERROR") object JsPlatforms { - val defaultJsPlatform: TargetPlatform = object : JsPlatform() {}.toTargetPlatform() + private object DefaultSimpleJsPlatform : JsPlatform() + + @Deprecated( + message = "Should be accessed only by compatibility layer, other clients should use 'defaultJsPlatform'", + level = DeprecationLevel.ERROR + ) + object CompatJsPlatform : TargetPlatform(setOf(DefaultSimpleJsPlatform)), + // Needed for backward compatibility, because old code uses INSTANCEOF checks instead of calling extensions + org.jetbrains.kotlin.js.resolve.JsPlatform {} + + val defaultJsPlatform: TargetPlatform + get() = CompatJsPlatform val allJsPlatforms: List = listOf(defaultJsPlatform) }