From 5750a96b13670e3e1604246493672549811951e8 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 29 Mar 2017 15:49:46 +0300 Subject: [PATCH] Write to configuration files only version without description --- .../org/jetbrains/kotlin/config/ApiVersion.kt | 9 +++- .../KotlinCompilerConfigurableTab.java | 53 +++++++++++-------- .../idea/facet/KotlinFacetEditorGeneralTab.kt | 8 +-- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/compiler/util/src/org/jetbrains/kotlin/config/ApiVersion.kt b/compiler/util/src/org/jetbrains/kotlin/config/ApiVersion.kt index 1a2a2e89632..904c58ac13a 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/ApiVersion.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/ApiVersion.kt @@ -17,11 +17,18 @@ package org.jetbrains.kotlin.config import org.jetbrains.kotlin.serialization.deserialization.descriptors.SinceKotlinInfo +import org.jetbrains.kotlin.utils.DescriptionAware class ApiVersion private constructor( val version: MavenComparableVersion, val versionString: String -) : Comparable { +) : Comparable, DescriptionAware { + val isStable: Boolean + get() = this <= ApiVersion.LATEST_STABLE + + override val description: String + get() = if (isStable) versionString else "$versionString (EXPERIMENTAL)" + override fun compareTo(other: ApiVersion): Int = version.compareTo(other.version) diff --git a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java index 8cebe43409e..5e562d66ae7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java +++ b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java @@ -272,8 +272,13 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co return jvmVersion != null ? jvmVersion : JvmTarget.DEFAULT.getDescription(); } - private static String getLanguageVersionOrDefault(@Nullable String languageVersion) { - return languageVersion != null ? languageVersion : LanguageVersion.LATEST_STABLE.getVersionString(); + private static LanguageVersion getLanguageVersionOrDefault(@Nullable String languageVersion) { + LanguageVersion version = LanguageVersion.fromVersionString(languageVersion); + return version != null ? version : LanguageVersion.LATEST_STABLE; + } + + private static ApiVersion getApiVersionOrDefault(@Nullable String apiVersion) { + return apiVersion != null ? ApiVersion.Companion.parse(apiVersion) : ApiVersion.LATEST_STABLE; } private static void setupFileChooser( @@ -302,15 +307,15 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co @SuppressWarnings("unchecked") private void restrictAPIVersions() { - String selectedAPIVersion = getSelectedAPIVersion(); - final String selectedLanguageVersion = getSelectedLanguageVersion(); - List permittedAPIVersions = ArraysKt.mapNotNull( + ApiVersion selectedAPIVersion = getSelectedAPIVersion(); + final LanguageVersion selectedLanguageVersion = getSelectedLanguageVersion(); + List permittedAPIVersions = ArraysKt.mapNotNull( LanguageVersion.values(), - new Function1() { + new Function1() { @Override - public String invoke(LanguageVersion version) { - return VersionComparatorUtil.compare(version.getVersionString(), selectedLanguageVersion) <= 0 - ? version.getVersionString() + public ApiVersion invoke(LanguageVersion version) { + return VersionComparatorUtil.compare(version.getVersionString(), selectedLanguageVersion.getVersionString()) <= 0 + ? ApiVersion.createByLanguageVersion(version) : null; } } @@ -319,7 +324,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co new DefaultComboBoxModel(permittedAPIVersions.toArray()) ); apiVersionComboBox.setSelectedItem( - VersionComparatorUtil.compare(selectedAPIVersion, selectedLanguageVersion) <= 0 + VersionComparatorUtil.compare(selectedAPIVersion.getVersionString(), selectedLanguageVersion.getVersionString()) <= 0 ? selectedAPIVersion : selectedLanguageVersion ); @@ -339,9 +344,11 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co continue; } - languageVersionComboBox.addItem(version.getDescription()); - apiVersionComboBox.addItem(version.getDescription()); + languageVersionComboBox.addItem(version); + apiVersionComboBox.addItem(ApiVersion.createByLanguageVersion(version)); } + languageVersionComboBox.setRenderer(new DescriptionListCellRenderer()); + apiVersionComboBox.setRenderer(new DescriptionListCellRenderer()); } @SuppressWarnings("unchecked") @@ -392,7 +399,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co public boolean isModified() { return ComparingUtils.isModified(reportWarningsCheckBox, !commonCompilerArguments.suppressWarnings) || !getSelectedLanguageVersion().equals(getLanguageVersionOrDefault(commonCompilerArguments.languageVersion)) || - !getSelectedAPIVersion().equals(getLanguageVersionOrDefault(commonCompilerArguments.apiVersion)) || + !getSelectedAPIVersion().equals(getApiVersionOrDefault(commonCompilerArguments.apiVersion)) || !coroutineSupportComboBox.getSelectedItem().equals(CoroutineSupport.byCompilerArguments(commonCompilerArguments)) || ComparingUtils.isModified(additionalArgsOptionsField, compilerSettings.additionalArguments) || ComparingUtils.isModified(scriptTemplatesField, compilerSettings.scriptTemplates) || @@ -423,13 +430,15 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co } @NotNull - private String getSelectedLanguageVersion() { - return getLanguageVersionOrDefault((String) languageVersionComboBox.getSelectedItem()); + private LanguageVersion getSelectedLanguageVersion() { + Object item = languageVersionComboBox.getSelectedItem(); + return item != null ? (LanguageVersion) item : LanguageVersion.LATEST_STABLE; } @NotNull - private String getSelectedAPIVersion() { - return getLanguageVersionOrDefault((String) apiVersionComboBox.getSelectedItem()); + private ApiVersion getSelectedAPIVersion() { + Object item = apiVersionComboBox.getSelectedItem(); + return item != null ? (ApiVersion) item : ApiVersion.LATEST_STABLE; } public void applyTo( @@ -440,8 +449,8 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co ) throws ConfigurationException { if (isProjectSettings) { boolean shouldInvalidateCaches = - commonCompilerArguments.languageVersion != getSelectedLanguageVersion() || - commonCompilerArguments.apiVersion != getSelectedAPIVersion() || + commonCompilerArguments.languageVersion != getSelectedLanguageVersion().getVersionString() || + commonCompilerArguments.apiVersion != getSelectedAPIVersion().getVersionString() || !coroutineSupportComboBox.getSelectedItem().equals(CoroutineSupport.byCompilerArguments(commonCompilerArguments)); if (shouldInvalidateCaches) { @@ -458,8 +467,8 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co } commonCompilerArguments.suppressWarnings = !reportWarningsCheckBox.isSelected(); - commonCompilerArguments.languageVersion = getSelectedLanguageVersion(); - commonCompilerArguments.apiVersion = getSelectedAPIVersion(); + commonCompilerArguments.languageVersion = getSelectedLanguageVersion().getVersionString(); + commonCompilerArguments.apiVersion = getSelectedAPIVersion().getVersionString(); LanguageFeature.State coroutineSupport = (LanguageFeature.State) coroutineSupportComboBox.getSelectedItem(); commonCompilerArguments.coroutinesEnable = coroutineSupport == LanguageFeature.State.ENABLED; commonCompilerArguments.coroutinesWarn = coroutineSupport == LanguageFeature.State.ENABLED_WITH_WARNING; @@ -507,7 +516,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co public void reset() { reportWarningsCheckBox.setSelected(!commonCompilerArguments.suppressWarnings); languageVersionComboBox.setSelectedItem(getLanguageVersionOrDefault(commonCompilerArguments.languageVersion)); - apiVersionComboBox.setSelectedItem(getLanguageVersionOrDefault(commonCompilerArguments.apiVersion)); + apiVersionComboBox.setSelectedItem(getApiVersionOrDefault(commonCompilerArguments.apiVersion)); restrictAPIVersions(); coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments)); additionalArgsOptionsField.setText(compilerSettings.additionalArguments); diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt index db21b2c01ae..375a6ce881e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 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. @@ -150,13 +150,15 @@ class KotlinFacetEditorGeneralTab( inner class VersionValidator : FacetEditorValidator() { override fun check(): ValidationResult { - val apiLevel = editor.compilerConfigurable.apiVersionComboBox.selectedItem as? LanguageVersion? + val apiLevel = editor.compilerConfigurable.apiVersionComboBox.selectedItem as? ApiVersion? ?: return ValidationResult.OK val languageLevel = editor.compilerConfigurable.languageVersionComboBox.selectedItem as? LanguageVersion? ?: return ValidationResult.OK val targetPlatform = editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*>? val libraryLevel = getLibraryLanguageLevel(editorContext.module, editorContext.rootModel, targetPlatform) - if (languageLevel < apiLevel || libraryLevel < apiLevel) { + + val apiLevelVersion = LanguageVersion.fromVersionString(apiLevel.versionString) ?: return ValidationResult.OK + if (languageLevel < apiLevelVersion || libraryLevel < apiLevelVersion) { return ValidationResult("Language version/Runtime version may not be less than API version", null) } return ValidationResult.OK