diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt index e5675e5e82d..24f79bbf67b 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt @@ -128,7 +128,10 @@ fun Project.getLanguageVersionSettings( ) val extraLanguageFeatures = additionalArguments.configureLanguageFeatures(MessageCollector.NONE).apply { - configureCoroutinesSupport(CoroutineSupport.byCompilerArguments(KotlinCommonCompilerArgumentsHolder.getInstance(this@getLanguageVersionSettings).settings)) + configureCoroutinesSupport( + CoroutineSupport.byCompilerArguments(KotlinCommonCompilerArgumentsHolder.getInstance(this@getLanguageVersionSettings).settings), + languageVersion + ) if (isReleaseCoroutines != null) { put( LanguageFeature.ReleaseCoroutines, @@ -183,7 +186,7 @@ private fun Module.computeLanguageVersionSettings(): LanguageVersionSettings { val apiVersion = facetSettings.apiLevel ?: languageVersion val languageFeatures = facetSettings.mergedCompilerArguments?.configureLanguageFeatures(MessageCollector.NONE)?.apply { - configureCoroutinesSupport(facetSettings.coroutineSupport) + configureCoroutinesSupport(facetSettings.coroutineSupport, languageVersion) configureMultiplatformSupport(facetSettings.targetPlatformKind, this@computeLanguageVersionSettings) }.orEmpty() @@ -226,8 +229,16 @@ private fun parseArguments( return arguments } -fun MutableMap.configureCoroutinesSupport(coroutineSupport: LanguageFeature.State) { - put(LanguageFeature.Coroutines, coroutineSupport) +fun MutableMap.configureCoroutinesSupport( + coroutineSupport: LanguageFeature.State?, + languageVersion: LanguageVersion +) { + val state = if (languageVersion >= LanguageVersion.KOTLIN_1_3) { + LanguageFeature.State.ENABLED + } else { + coroutineSupport ?: LanguageFeature.Coroutines.defaultState + } + put(LanguageFeature.Coroutines, state) } fun MutableMap.configureMultiplatformSupport( diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt index 35d34a6fdea..11f0be6a6ba 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -187,14 +187,15 @@ class KotlinFacetSettings { } } - var coroutineSupport: LanguageFeature.State + var coroutineSupport: LanguageFeature.State? get() { val languageVersion = languageLevel ?: return LanguageFeature.Coroutines.defaultState if (languageVersion < LanguageFeature.Coroutines.sinceVersion!!) return LanguageFeature.State.DISABLED - return CoroutineSupport.byCompilerArguments(compilerArguments) + return CoroutineSupport.byCompilerArgumentsOrNull(compilerArguments) } set(value) { compilerArguments!!.coroutinesState = when (value) { + null -> CommonCompilerArguments.DEFAULT LanguageFeature.State.ENABLED -> CommonCompilerArguments.ENABLE LanguageFeature.State.ENABLED_WITH_WARNING -> CommonCompilerArguments.WARN LanguageFeature.State.ENABLED_WITH_ERROR, LanguageFeature.State.DISABLED -> CommonCompilerArguments.ERROR diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt index c4a7e07407a..85b0b7cba4b 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt @@ -153,6 +153,7 @@ private fun readV2Config(element: Element): KotlinFacetSettings { compilerArguments!!.coroutinesState = CommonCompilerArguments.WARN args.any { arg -> arg.attributes[0].value == "coroutinesError" && arg.attributes[1].booleanValue } -> compilerArguments!!.coroutinesState = CommonCompilerArguments.ERROR + else -> compilerArguments!!.coroutinesState = CommonCompilerArguments.DEFAULT } } } diff --git a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form index b79037f4f26..eb3aea3d7b6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form +++ b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.form @@ -339,7 +339,7 @@ - + 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 f3bfafe0d71..d9cc2c1bc22 100644 --- a/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java +++ b/idea/src/org/jetbrains/kotlin/idea/compiler/configuration/KotlinCompilerConfigurableTab.java @@ -110,6 +110,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co private JTextField sourceMapPrefix; private JLabel labelForSourceMapPrefix; private JComboBox sourceMapEmbedSources; + private JPanel coroutinesPanel; private boolean isEnabled = true; public KotlinCompilerConfigurableTab( @@ -136,7 +137,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - restrictAPIVersions(getSelectedLanguageVersionView()); + onLanguageLevelChanged(getSelectedLanguageVersionView()); } } ); @@ -321,8 +322,13 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co return VersionComparatorUtil.compare(version.getVersionString(), upperBound.getVersionString()) <= 0; } + public void onLanguageLevelChanged(VersionView languageLevel) { + restrictAPIVersions(languageLevel); + coroutinesPanel.setVisible(languageLevel.getVersion().compareTo(LanguageVersion.KOTLIN_1_3) < 0); + } + @SuppressWarnings("unchecked") - public void restrictAPIVersions(VersionView upperBoundView) { + private void restrictAPIVersions(VersionView upperBoundView) { VersionView selectedAPIView = getSelectedAPIVersionView(); LanguageVersion selectedAPIVersion = selectedAPIView.getVersion(); LanguageVersion upperBound = upperBoundView.getVersion(); @@ -432,7 +438,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co return isModified(reportWarningsCheckBox, !commonCompilerArguments.getSuppressWarnings()) || !getSelectedLanguageVersionView().equals(KotlinFacetSettingsKt.getLanguageVersionView(commonCompilerArguments)) || !getSelectedAPIVersionView().equals(KotlinFacetSettingsKt.getApiVersionView(commonCompilerArguments)) || - !coroutineSupportComboBox.getSelectedItem().equals(CoroutineSupport.byCompilerArguments(commonCompilerArguments)) || + !getSelectedCoroutineState().equals(commonCompilerArguments.getCoroutinesState()) || !additionalArgsOptionsField.getText().equals(compilerSettings.getAdditionalArguments()) || isModified(scriptDependenciesAutoReload, getScriptingSettings().isAutoReloadEnabled()) || isModified(scriptTemplatesField, compilerSettings.getScriptTemplates()) || @@ -481,6 +487,22 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co return item != null ? (VersionView) item : VersionView.LatestStable.INSTANCE; } + @NotNull + private String getSelectedCoroutineState() { + if (getSelectedLanguageVersionView().getVersion().compareTo(LanguageVersion.KOTLIN_1_3) >= 0) { + return CommonCompilerArguments.DEFAULT; + } + + LanguageFeature.State state = (LanguageFeature.State) coroutineSupportComboBox.getSelectedItem(); + if (state == null) return CommonCompilerArguments.DEFAULT; + switch (state) { + case ENABLED: return CommonCompilerArguments.ENABLE; + case ENABLED_WITH_WARNING: return CommonCompilerArguments.WARN; + case ENABLED_WITH_ERROR: return CommonCompilerArguments.ERROR; + default: return CommonCompilerArguments.DEFAULT; + } + } + public void applyTo( CommonCompilerArguments commonCompilerArguments, K2JVMCompilerArguments k2jvmCompilerArguments, @@ -491,7 +513,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co boolean shouldInvalidateCaches = !getSelectedLanguageVersionView().equals(KotlinFacetSettingsKt.getLanguageVersionView(commonCompilerArguments)) || !getSelectedAPIVersionView().equals(KotlinFacetSettingsKt.getApiVersionView(commonCompilerArguments)) || - !coroutineSupportComboBox.getSelectedItem().equals(CoroutineSupport.byCompilerArguments(commonCompilerArguments)) || + !getSelectedCoroutineState().equals(commonCompilerArguments.getCoroutinesState()) || !additionalArgsOptionsField.getText().equals(compilerSettings.getAdditionalArguments()); if (shouldInvalidateCaches) { @@ -511,18 +533,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co KotlinFacetSettingsKt.setLanguageVersionView(commonCompilerArguments, getSelectedLanguageVersionView()); KotlinFacetSettingsKt.setApiVersionView(commonCompilerArguments, getSelectedAPIVersionView()); - switch ((LanguageFeature.State) coroutineSupportComboBox.getSelectedItem()) { - case ENABLED: - commonCompilerArguments.setCoroutinesState(CommonCompilerArguments.ENABLE); - break; - case ENABLED_WITH_WARNING: - commonCompilerArguments.setCoroutinesState(CommonCompilerArguments.WARN); - break; - case ENABLED_WITH_ERROR: - case DISABLED: - commonCompilerArguments.setCoroutinesState(CommonCompilerArguments.ERROR); - break; - } + commonCompilerArguments.setCoroutinesState(getSelectedCoroutineState()); compilerSettings.setAdditionalArguments(additionalArgsOptionsField.getText()); compilerSettings.setScriptTemplates(scriptTemplatesField.getText()); @@ -574,7 +585,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co public void reset() { reportWarningsCheckBox.setSelected(!commonCompilerArguments.getSuppressWarnings()); languageVersionComboBox.setSelectedItem(KotlinFacetSettingsKt.getLanguageVersionView(commonCompilerArguments)); - restrictAPIVersions(getSelectedLanguageVersionView()); + onLanguageLevelChanged(getSelectedLanguageVersionView()); apiVersionComboBox.setSelectedItem(KotlinFacetSettingsKt.getApiVersionView(commonCompilerArguments)); coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments)); additionalArgsOptionsField.setText(compilerSettings.getAdditionalArguments()); diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt index 12856b93bf3..421b8906b35 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/KotlinFacetEditorGeneralTab.kt @@ -222,7 +222,7 @@ class KotlinFacetEditorGeneralTab( copyRuntimeFilesCheckBox.validateOnChange() moduleKindComboBox.validateOnChange() languageVersionComboBox.addActionListener { - restrictAPIVersions() + onLanguageLevelChanged() doValidate() } apiVersionComboBox.validateOnChange() @@ -233,9 +233,9 @@ class KotlinFacetEditorGeneralTab( editor.updateCompilerConfigurable() } - private fun restrictAPIVersions() { + private fun onLanguageLevelChanged() { with(editor.compilerConfigurable) { - restrictAPIVersions(selectedLanguageVersionView) + onLanguageLevelChanged(selectedLanguageVersionView) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt index 154819f541f..7228b69b99f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt @@ -166,7 +166,7 @@ fun KotlinFacet.configureFacet( if (languageLevel != null && apiLevel != null && apiLevel > languageLevel) { this.apiLevel = languageLevel } - this.coroutineSupport = coroutineSupport + this.coroutineSupport = if (languageLevel != null && languageLevel < LanguageVersion.KOTLIN_1_3) coroutineSupport else null } module.externalCompilerVersion = compilerVersion