From abacf2845f36de44989049d6edb7de36997a6432 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 5 Apr 2017 19:00:53 +0300 Subject: [PATCH] Get rid of coroutinesWarn/coroutinesEnable/coroutinesError Use a single coroutinesState instead. Change the coroutines state in some tests from "warn" to "enable"/"error" to test that deserialization of older config files works ("warn" is the default value, so it wasn't testing anything here) Original commit: be54e4b93bc10cb16b8c4538f2191082f80fbeea --- .../kotlin/config/KotlinFacetSettings.kt | 19 ++++++++-------- .../kotlin/config/facetSerialization.kt | 22 ++++++++++++++++++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt index c0fb60d7972..cfcd52a3b9d 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -55,11 +55,10 @@ object CoroutineSupport { fun byCompilerArguments(arguments: CommonCompilerArguments?): LanguageFeature.State = byCompilerArgumentsOrNull(arguments) ?: LanguageFeature.Coroutines.defaultState - fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when { - arguments == null -> null - arguments.coroutinesEnable -> LanguageFeature.State.ENABLED - arguments.coroutinesWarn -> LanguageFeature.State.ENABLED_WITH_WARNING - arguments.coroutinesError -> LanguageFeature.State.ENABLED_WITH_ERROR + fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when (arguments?.coroutinesState) { + CommonCompilerArguments.ENABLE -> LanguageFeature.State.ENABLED + CommonCompilerArguments.WARN -> LanguageFeature.State.ENABLED_WITH_WARNING + CommonCompilerArguments.ERROR -> LanguageFeature.State.ENABLED_WITH_ERROR else -> null } @@ -77,7 +76,7 @@ object CoroutineSupport { class KotlinFacetSettings { companion object { // Increment this when making serialization-incompatible changes to configuration data - val CURRENT_VERSION = 2 + val CURRENT_VERSION = 3 val DEFAULT_VERSION = 0 } @@ -118,10 +117,10 @@ class KotlinFacetSettings { return CoroutineSupport.byCompilerArguments(compilerArguments) } set(value) { - with(compilerArguments!!) { - coroutinesEnable = value == LanguageFeature.State.ENABLED - coroutinesWarn = value == LanguageFeature.State.ENABLED_WITH_WARNING - coroutinesError = value == LanguageFeature.State.ENABLED_WITH_ERROR || value == LanguageFeature.State.DISABLED + compilerArguments!!.coroutinesState = when (value) { + 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/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt b/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt index 1aab95c697b..d58533299e6 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt @@ -85,7 +85,7 @@ private fun readV1Config(element: Element): KotlinFacetSettings { } } -private fun readV2Config(element: Element): KotlinFacetSettings { +private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings { return KotlinFacetSettings().apply { element.getAttributeValue("useProjectSettings")?.let { useProjectSettings = it.toBoolean() } val platformName = element.getAttributeValue("platform") @@ -101,6 +101,25 @@ private fun readV2Config(element: Element): KotlinFacetSettings { } } +private fun readV2Config(element: Element): KotlinFacetSettings { + return readV2AndLaterConfig(element).apply { + element.getChild("compilerArguments")?.children?.let { args -> + when { + args.any { arg -> arg.attributes[0].value == "coroutinesEnable" && arg.attributes[1].booleanValue } -> + compilerArguments!!.coroutinesState = CommonCompilerArguments.ENABLE + args.any { arg -> arg.attributes[0].value == "coroutinesWarn" && arg.attributes[1].booleanValue } -> + compilerArguments!!.coroutinesState = CommonCompilerArguments.WARN + args.any { arg -> arg.attributes[0].value == "coroutinesError" && arg.attributes[1].booleanValue } -> + compilerArguments!!.coroutinesState = CommonCompilerArguments.ERROR + } + } + } +} + +private fun readLatestConfig(element: Element): KotlinFacetSettings { + return readV2AndLaterConfig(element) +} + fun deserializeFacetSettings(element: Element): KotlinFacetSettings { val version = try { @@ -112,6 +131,7 @@ fun deserializeFacetSettings(element: Element): KotlinFacetSettings { return when (version) { 1 -> readV1Config(element) 2 -> readV2Config(element) + KotlinFacetSettings.CURRENT_VERSION -> readLatestConfig(element) else -> KotlinFacetSettings() // Reset facet configuration if versions don't match } }