diff --git a/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt index 8b1cf56172b..66400269c06 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -19,11 +19,11 @@ package org.jetbrains.kotlin.config import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project -import org.jetbrains.kotlin.cli.common.arguments.* +import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.copyBean +import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments 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.IdePlatformKind import org.jetbrains.kotlin.utils.DescriptionAware @Deprecated("Use IdePlatformKind instead.", level = DeprecationLevel.ERROR) @@ -189,16 +189,8 @@ class KotlinFacetSettings { val platform: IdePlatform<*, *>? get() { - val compilerArguments = this.compilerArguments - return when (compilerArguments) { - is K2JVMCompilerArguments -> { - val jvmTarget = compilerArguments.jvmTarget ?: JvmTarget.DEFAULT.description - JvmIdePlatformKind.platforms.firstOrNull { it.version.description >= jvmTarget } - } - is K2JSCompilerArguments -> JsIdePlatformKind.Platform - is K2MetadataCompilerArguments -> CommonIdePlatformKind.Platform - else -> null - } + val compilerArguments = this.compilerArguments ?: return null + return IdePlatformKind.platformByCompilerArguments(compilerArguments) } var coroutineSupport: LanguageFeature.State? diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt index 00abe124cbd..58726b74a88 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.config.TargetPlatformVersion import org.jetbrains.kotlin.utils.DescriptionAware -abstract class IdePlatform, Arguments : CommonCompilerArguments> : DescriptionAware { +abstract class IdePlatform, out Arguments : CommonCompilerArguments> : DescriptionAware { abstract val kind: Kind abstract val version: TargetPlatformVersion 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 a0cb990fa63..e4315c5c527 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt @@ -13,6 +13,7 @@ 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.resolve.TargetPlatform +import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult abstract class IdePlatformKind> { abstract val compilerPlatform: TargetPlatform @@ -20,6 +21,8 @@ abstract class IdePlatformKind> { abstract val defaultPlatform: IdePlatform + abstract fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform? + abstract val argumentsClass: Class abstract val name: String @@ -47,6 +50,11 @@ abstract class IdePlatformKind> { val All_PLATFORMS by lazy { ALL_KINDS.flatMap { it.platforms } } val IDE_PLATFORMS_BY_COMPILER_PLATFORMS by lazy { ALL_KINDS.map { it.compilerPlatform to it }.toMap() } + + fun platformByCompilerArguments(arguments: Args): IdePlatform<*, Args> { + return ALL_KINDS.firstNotNullResult { it.platformByCompilerArguments(arguments) as IdePlatform<*, Args>? }!! + } + } } 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 1f5407a399c..a04bddf8f77 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 @@ -14,6 +14,12 @@ import org.jetbrains.kotlin.platform.IdePlatformKind import org.jetbrains.kotlin.resolve.TargetPlatform object CommonIdePlatformKind : IdePlatformKind() { + + override fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform? { + return if (arguments is K2MetadataCompilerArguments) Platform + else null + } + override val compilerPlatform get() = TargetPlatform.Common override val platforms get() = listOf(Platform) 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 40951c4d30a..4d323e3b5af 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 @@ -6,6 +6,7 @@ @file:JvmName("JsIdePlatformUtil") 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.config.TargetPlatformVersion import org.jetbrains.kotlin.js.resolve.JsPlatform @@ -13,6 +14,12 @@ import org.jetbrains.kotlin.platform.IdePlatform import org.jetbrains.kotlin.platform.IdePlatformKind object JsIdePlatformKind : IdePlatformKind() { + + override fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform? { + return if (arguments is K2JSCompilerArguments) Platform + else null + } + override val compilerPlatform get() = JsPlatform override val platforms get() = listOf(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 d5087f9b57d..a4aa3a3b836 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 @@ -6,6 +6,7 @@ @file:JvmName("JvmIdePlatformUtil") package org.jetbrains.kotlin.platform.impl +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 @@ -13,6 +14,14 @@ import org.jetbrains.kotlin.platform.IdePlatformKind import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform object JvmIdePlatformKind : IdePlatformKind() { + + override fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform? { + return if (arguments is K2JVMCompilerArguments) { + val jvmTarget = arguments.jvmTarget ?: JvmTarget.DEFAULT.description + JvmIdePlatformKind.platforms.firstOrNull { it.version.description >= jvmTarget } + } else null + } + override val compilerPlatform get() = JvmPlatform override val platforms = JvmTarget.values().map { ver -> Platform(ver) }