MPP: extend IdePlatformKind EP & determine it by CommonCompilerArguments
Original commit: 5633d86cb2
This commit is contained in:
committed by
Mikhail Glukhikh
parent
57c71058b0
commit
63b8d88249
@@ -19,11 +19,11 @@ package org.jetbrains.kotlin.config
|
|||||||
import com.intellij.openapi.components.ServiceManager
|
import com.intellij.openapi.components.ServiceManager
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.project.Project
|
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.IdePlatform
|
||||||
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
|
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||||
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
|
|
||||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
|
||||||
import org.jetbrains.kotlin.utils.DescriptionAware
|
import org.jetbrains.kotlin.utils.DescriptionAware
|
||||||
|
|
||||||
@Deprecated("Use IdePlatformKind instead.", level = DeprecationLevel.ERROR)
|
@Deprecated("Use IdePlatformKind instead.", level = DeprecationLevel.ERROR)
|
||||||
@@ -189,16 +189,8 @@ class KotlinFacetSettings {
|
|||||||
|
|
||||||
val platform: IdePlatform<*, *>?
|
val platform: IdePlatform<*, *>?
|
||||||
get() {
|
get() {
|
||||||
val compilerArguments = this.compilerArguments
|
val compilerArguments = this.compilerArguments ?: return null
|
||||||
return when (compilerArguments) {
|
return IdePlatformKind.platformByCompilerArguments(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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var coroutineSupport: LanguageFeature.State?
|
var coroutineSupport: LanguageFeature.State?
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
|||||||
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
||||||
import org.jetbrains.kotlin.utils.DescriptionAware
|
import org.jetbrains.kotlin.utils.DescriptionAware
|
||||||
|
|
||||||
abstract class IdePlatform<Kind : IdePlatformKind<Kind>, Arguments : CommonCompilerArguments> : DescriptionAware {
|
abstract class IdePlatform<Kind : IdePlatformKind<Kind>, out Arguments : CommonCompilerArguments> : DescriptionAware {
|
||||||
abstract val kind: Kind
|
abstract val kind: Kind
|
||||||
abstract val version: TargetPlatformVersion
|
abstract val version: TargetPlatformVersion
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
|
|||||||
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
|
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
|
||||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||||
|
|
||||||
abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
|
abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
|
||||||
abstract val compilerPlatform: TargetPlatform
|
abstract val compilerPlatform: TargetPlatform
|
||||||
@@ -20,6 +21,8 @@ abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
|
|||||||
|
|
||||||
abstract val defaultPlatform: IdePlatform<Kind, *>
|
abstract val defaultPlatform: IdePlatform<Kind, *>
|
||||||
|
|
||||||
|
abstract fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform<Kind, CommonCompilerArguments>?
|
||||||
|
|
||||||
abstract val argumentsClass: Class<out CommonCompilerArguments>
|
abstract val argumentsClass: Class<out CommonCompilerArguments>
|
||||||
|
|
||||||
abstract val name: String
|
abstract val name: String
|
||||||
@@ -47,6 +50,11 @@ abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
|
|||||||
val All_PLATFORMS by lazy { ALL_KINDS.flatMap { it.platforms } }
|
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() }
|
val IDE_PLATFORMS_BY_COMPILER_PLATFORMS by lazy { ALL_KINDS.map { it.compilerPlatform to it }.toMap() }
|
||||||
|
|
||||||
|
fun <Args : CommonCompilerArguments> platformByCompilerArguments(arguments: Args): IdePlatform<*, Args> {
|
||||||
|
return ALL_KINDS.firstNotNullResult { it.platformByCompilerArguments(arguments) as IdePlatform<*, Args>? }!!
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ import org.jetbrains.kotlin.platform.IdePlatformKind
|
|||||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||||
|
|
||||||
object CommonIdePlatformKind : IdePlatformKind<CommonIdePlatformKind>() {
|
object CommonIdePlatformKind : IdePlatformKind<CommonIdePlatformKind>() {
|
||||||
|
|
||||||
|
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform<CommonIdePlatformKind, CommonCompilerArguments>? {
|
||||||
|
return if (arguments is K2MetadataCompilerArguments) Platform
|
||||||
|
else null
|
||||||
|
}
|
||||||
|
|
||||||
override val compilerPlatform get() = TargetPlatform.Common
|
override val compilerPlatform get() = TargetPlatform.Common
|
||||||
|
|
||||||
override val platforms get() = listOf(Platform)
|
override val platforms get() = listOf(Platform)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
@file:JvmName("JsIdePlatformUtil")
|
@file:JvmName("JsIdePlatformUtil")
|
||||||
package org.jetbrains.kotlin.platform.impl
|
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.cli.common.arguments.K2JSCompilerArguments
|
||||||
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
import org.jetbrains.kotlin.config.TargetPlatformVersion
|
||||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||||
@@ -13,6 +14,12 @@ import org.jetbrains.kotlin.platform.IdePlatform
|
|||||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||||
|
|
||||||
object JsIdePlatformKind : IdePlatformKind<JsIdePlatformKind>() {
|
object JsIdePlatformKind : IdePlatformKind<JsIdePlatformKind>() {
|
||||||
|
|
||||||
|
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform<JsIdePlatformKind, CommonCompilerArguments>? {
|
||||||
|
return if (arguments is K2JSCompilerArguments) Platform
|
||||||
|
else null
|
||||||
|
}
|
||||||
|
|
||||||
override val compilerPlatform get() = JsPlatform
|
override val compilerPlatform get() = JsPlatform
|
||||||
|
|
||||||
override val platforms get() = listOf(Platform)
|
override val platforms get() = listOf(Platform)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
@file:JvmName("JvmIdePlatformUtil")
|
@file:JvmName("JvmIdePlatformUtil")
|
||||||
package org.jetbrains.kotlin.platform.impl
|
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.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.config.JvmTarget
|
import org.jetbrains.kotlin.config.JvmTarget
|
||||||
import org.jetbrains.kotlin.platform.IdePlatform
|
import org.jetbrains.kotlin.platform.IdePlatform
|
||||||
@@ -13,6 +14,14 @@ import org.jetbrains.kotlin.platform.IdePlatformKind
|
|||||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||||
|
|
||||||
object JvmIdePlatformKind : IdePlatformKind<JvmIdePlatformKind>() {
|
object JvmIdePlatformKind : IdePlatformKind<JvmIdePlatformKind>() {
|
||||||
|
|
||||||
|
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform<JvmIdePlatformKind, CommonCompilerArguments>? {
|
||||||
|
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 compilerPlatform get() = JvmPlatform
|
||||||
|
|
||||||
override val platforms = JvmTarget.values().map { ver -> Platform(ver) }
|
override val platforms = JvmTarget.values().map { ver -> Platform(ver) }
|
||||||
|
|||||||
Reference in New Issue
Block a user