MPP: extend IdePlatformKind EP & determine it by CommonCompilerArguments

This commit is contained in:
Dmitriy Dolovov
2018-09-03 11:52:29 +03:00
committed by Mikhail Glukhikh
parent 2e29a581f2
commit 5633d86cb2
6 changed files with 37 additions and 15 deletions
@@ -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?
@@ -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<Kind : IdePlatformKind<Kind>, Arguments : CommonCompilerArguments> : DescriptionAware {
abstract class IdePlatform<Kind : IdePlatformKind<Kind>, out Arguments : CommonCompilerArguments> : DescriptionAware {
abstract val kind: Kind
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.JvmIdePlatformKind
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
abstract val compilerPlatform: TargetPlatform
@@ -20,6 +21,8 @@ abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
abstract val defaultPlatform: IdePlatform<Kind, *>
abstract fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform<Kind, CommonCompilerArguments>?
abstract val argumentsClass: Class<out CommonCompilerArguments>
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 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
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 platforms get() = listOf(Platform)
@@ -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<JsIdePlatformKind>() {
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): IdePlatform<JsIdePlatformKind, CommonCompilerArguments>? {
return if (arguments is K2JSCompilerArguments) Platform
else null
}
override val compilerPlatform get() = JsPlatform
override val platforms get() = listOf(Platform)
@@ -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<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 platforms = JvmTarget.values().map { ver -> Platform(ver) }