Configuration: Drop coroutines for language >= 1.3

#KT-25681 Fixed
This commit is contained in:
Alexey Sedunov
2018-07-25 13:22:59 +03:00
committed by Ilya Gorbunov
parent 9f4c8d5b81
commit a490781213
7 changed files with 52 additions and 28 deletions
@@ -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<LanguageFeature, LanguageFeature.State>.configureCoroutinesSupport(coroutineSupport: LanguageFeature.State) {
put(LanguageFeature.Coroutines, coroutineSupport)
fun MutableMap<LanguageFeature, LanguageFeature.State>.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<LanguageFeature, LanguageFeature.State>.configureMultiplatformSupport(
@@ -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
@@ -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
}
}
}
@@ -339,7 +339,7 @@
</component>
</children>
</grid>
<grid id="7f3d" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="7f3d" binding="coroutinesPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
@@ -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());
@@ -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)
}
}
@@ -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