Kotlin Facet: Reuse JvmTarget and LanguageVersion in facet configuration
This commit is contained in:
+2
-2
@@ -34,8 +34,8 @@ open class DefaultValues(val defaultValue: String, val possibleValues: List<Stri
|
||||
)
|
||||
|
||||
object JvmTargetVersions : DefaultValues(
|
||||
"\"" + JvmTarget.DEFAULT.string + "\"",
|
||||
JvmTarget.values().map { "\"${it.string}\"" }
|
||||
"\"" + JvmTarget.DEFAULT.description + "\"",
|
||||
JvmTarget.values().map { "\"${it.description}\"" }
|
||||
)
|
||||
|
||||
object JsEcmaVersions : DefaultValues(
|
||||
|
||||
@@ -134,7 +134,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
else {
|
||||
val errorMessage = "Unknown JVM target version: ${arguments.jvmTarget}\n" +
|
||||
"Supported versions: ${JvmTarget.values().joinToString { it.string }}"
|
||||
"Supported versions: ${JvmTarget.values().joinToString { it.description }}"
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, errorMessage, CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.config
|
||||
|
||||
enum class JvmTarget(val string: String) {
|
||||
import org.jetbrains.kotlin.utils.DescriptionAware
|
||||
|
||||
enum class JvmTarget(override val description: String) : DescriptionAware {
|
||||
JVM_1_6("1.6"),
|
||||
JVM_1_8("1.8"),
|
||||
;
|
||||
@@ -26,6 +28,6 @@ enum class JvmTarget(val string: String) {
|
||||
val DEFAULT = JVM_1_6
|
||||
|
||||
@JvmStatic
|
||||
fun fromString(string: String) = values().find { it.string == string }
|
||||
fun fromString(string: String) = values().find { it.description == string }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.config
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageVersion.KOTLIN_1_1
|
||||
import org.jetbrains.kotlin.utils.DescriptionAware
|
||||
|
||||
enum class LanguageFeature(val sinceVersion: LanguageVersion) {
|
||||
// Note: names of these entries are also used in diagnostic tests
|
||||
@@ -43,10 +44,13 @@ enum class LanguageFeature(val sinceVersion: LanguageVersion) {
|
||||
}
|
||||
}
|
||||
|
||||
enum class LanguageVersion(val versionString: String) {
|
||||
enum class LanguageVersion(val versionString: String) : DescriptionAware {
|
||||
KOTLIN_1_0("1.0"),
|
||||
KOTLIN_1_1("1.1");
|
||||
|
||||
override val description: String
|
||||
get() = versionString
|
||||
|
||||
override fun toString() = versionString
|
||||
|
||||
companion object {
|
||||
|
||||
+1
-17
@@ -14,23 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright 2010-2016 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.config;
|
||||
package org.jetbrains.kotlin.utils;
|
||||
|
||||
interface DescriptionAware {
|
||||
val description: String
|
||||
@@ -11,5 +11,6 @@
|
||||
<orderEntry type="library" name="kotlin-reflect" level="project" />
|
||||
<orderEntry type="library" name="intellij-core" level="project" />
|
||||
<orderEntry type="module" module-name="cli-common" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -36,11 +36,7 @@ import com.intellij.util.xmlb.annotations.Property
|
||||
import com.intellij.util.xmlb.annotations.Transient
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
|
||||
enum class LanguageLevel(override val description: String) : DescriptionAware {
|
||||
KOTLIN_1_0("1.0"),
|
||||
KOTLIN_1_1("1.1")
|
||||
}
|
||||
import org.jetbrains.kotlin.utils.DescriptionAware
|
||||
|
||||
sealed class TargetPlatformKind<out Version : DescriptionAware>(
|
||||
val version: Version,
|
||||
@@ -57,24 +53,19 @@ object NoVersion : DescriptionAware {
|
||||
override val description = ""
|
||||
}
|
||||
|
||||
enum class JVMVersion(override val description: String) : DescriptionAware {
|
||||
JVM_1_6("1.6"),
|
||||
JVM_1_8("1.8")
|
||||
}
|
||||
|
||||
class JVMPlatform(version: JVMVersion) : TargetPlatformKind<JVMVersion>(version, "JVM") {
|
||||
class JVMPlatform(version: JvmTarget) : TargetPlatformKind<JvmTarget>(version, "JVM") {
|
||||
companion object {
|
||||
val JVM_PLATFORMS by lazy { JVMVersion.values().map(::JVMPlatform) }
|
||||
val JVM_PLATFORMS by lazy { JvmTarget.values().map(::JVMPlatform) }
|
||||
|
||||
operator fun get(version: JVMVersion) = JVM_PLATFORMS[version.ordinal]
|
||||
operator fun get(version: JvmTarget) = JVM_PLATFORMS[version.ordinal]
|
||||
}
|
||||
}
|
||||
|
||||
object JSPlatform : TargetPlatformKind<NoVersion>(NoVersion, "JavaScript")
|
||||
|
||||
data class KotlinVersionInfo(
|
||||
var languageLevel: LanguageLevel? = null,
|
||||
var apiLevel: LanguageLevel? = null,
|
||||
var languageLevel: LanguageVersion? = null,
|
||||
var apiLevel: LanguageVersion? = null,
|
||||
@get:Transient var targetPlatformKindKind: TargetPlatformKind<*>? = null
|
||||
) {
|
||||
// To be serialized
|
||||
|
||||
@@ -20,9 +20,9 @@ import com.intellij.facet.impl.ui.libraries.DelegatingLibrariesValidatorContext
|
||||
import com.intellij.facet.ui.*
|
||||
import com.intellij.facet.ui.libraries.FrameworkLibraryValidator
|
||||
import com.intellij.util.ui.FormBuilder
|
||||
import org.jetbrains.kotlin.config.DescriptionAware
|
||||
import org.jetbrains.kotlin.config.LanguageLevel
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
||||
import org.jetbrains.kotlin.utils.DescriptionAware
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Component
|
||||
import javax.swing.*
|
||||
@@ -43,8 +43,8 @@ class KotlinFacetEditorGeneralTab(
|
||||
|
||||
inner class VersionValidator : FacetEditorValidator() {
|
||||
override fun check(): ValidationResult {
|
||||
val apiLevel = apiVersionComboBox.selectedItem as? LanguageLevel? ?: return ValidationResult.OK
|
||||
val languageLevel = languageVersionComboBox.selectedItem as? LanguageLevel? ?: return ValidationResult.OK
|
||||
val apiLevel = apiVersionComboBox.selectedItem as? LanguageVersion? ?: return ValidationResult.OK
|
||||
val languageLevel = languageVersionComboBox.selectedItem as? LanguageVersion? ?: return ValidationResult.OK
|
||||
val targetPlatform = targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?
|
||||
val libraryLevel = getLibraryLanguageLevel(editorContext.module, editorContext.rootModel, targetPlatform)
|
||||
if (languageLevel < apiLevel || libraryLevel < apiLevel) {
|
||||
@@ -55,12 +55,12 @@ class KotlinFacetEditorGeneralTab(
|
||||
}
|
||||
|
||||
private val languageVersionComboBox =
|
||||
JComboBox<LanguageLevel>(LanguageLevel.values()).apply {
|
||||
JComboBox<LanguageVersion>(LanguageVersion.values()).apply {
|
||||
setRenderer(DescriptionListCellRenderer())
|
||||
}
|
||||
|
||||
private val apiVersionComboBox =
|
||||
JComboBox<LanguageLevel>(LanguageLevel.values()).apply {
|
||||
JComboBox<LanguageVersion>(LanguageVersion.values()).apply {
|
||||
setRenderer(DescriptionListCellRenderer())
|
||||
}
|
||||
|
||||
@@ -122,9 +122,9 @@ class KotlinFacetEditorGeneralTab(
|
||||
|
||||
override fun apply() {
|
||||
with(configuration.state.versionInfo) {
|
||||
languageLevel = languageVersionComboBox.selectedItem as LanguageLevel?
|
||||
languageLevel = languageVersionComboBox.selectedItem as LanguageVersion?
|
||||
targetPlatformKindKind = targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?
|
||||
apiLevel = apiVersionComboBox.selectedItem as LanguageLevel?
|
||||
apiLevel = apiVersionComboBox.selectedItem as LanguageVersion?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,23 +66,23 @@ private fun getDefaultTargetPlatform(module: Module, rootModel: ModuleRootModel?
|
||||
val sdk = ((rootModel ?: ModuleRootManager.getInstance(module))).sdk
|
||||
val sdkVersion = (sdk?.sdkType as? JavaSdk)?.getVersion(sdk!!)
|
||||
return when {
|
||||
sdkVersion != null && sdkVersion <= JavaSdkVersion.JDK_1_6 -> JVMPlatform[JVMVersion.JVM_1_6]
|
||||
else -> JVMPlatform[JVMVersion.JVM_1_8]
|
||||
sdkVersion != null && sdkVersion <= JavaSdkVersion.JDK_1_6 -> JVMPlatform[JvmTarget.JVM_1_6]
|
||||
else -> JVMPlatform[JvmTarget.JVM_1_8]
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDefaultLanguageLevel(
|
||||
module: Module,
|
||||
explicitVersion: String? = null
|
||||
): LanguageLevel {
|
||||
): LanguageVersion {
|
||||
val libVersion = explicitVersion
|
||||
?: KotlinVersionInfoProvider.EP_NAME.extensions
|
||||
.mapNotNull { it.getCompilerVersion(module) }
|
||||
.minWith(VersionComparatorUtil.COMPARATOR)
|
||||
?: bundledRuntimeVersion()
|
||||
return when {
|
||||
libVersion.startsWith("1.0") -> LanguageLevel.KOTLIN_1_0
|
||||
else -> LanguageLevel.KOTLIN_1_1
|
||||
libVersion.startsWith("1.0") -> LanguageVersion.KOTLIN_1_0
|
||||
else -> LanguageVersion.KOTLIN_1_1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +90,8 @@ internal fun getLibraryLanguageLevel(
|
||||
module: Module,
|
||||
rootModel: ModuleRootModel?,
|
||||
targetPlatform: TargetPlatformKind<*>?
|
||||
): LanguageLevel {
|
||||
val minVersion = getRuntimeLibraryVersions(module, rootModel, targetPlatform ?: JVMPlatform[JVMVersion.JVM_1_8])
|
||||
): LanguageVersion {
|
||||
val minVersion = getRuntimeLibraryVersions(module, rootModel, targetPlatform ?: JVMPlatform[JvmTarget.JVM_1_8])
|
||||
.minWith(VersionComparatorUtil.COMPARATOR)
|
||||
return getDefaultLanguageLevel(module, minVersion)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user