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: be54e4b93b
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user