Use LanguageFeature.State enum instead of CoroutineSupport
Original commit: 7a240b63c7
This commit is contained in:
@@ -50,31 +50,27 @@ sealed class TargetPlatformKind<out Version : TargetPlatformVersion>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: merge with LanguageFeature.State
|
object CoroutineSupport {
|
||||||
enum class CoroutineSupport(
|
@JvmStatic
|
||||||
override val description: String,
|
fun byCompilerArguments(arguments: CommonCompilerArguments?): LanguageFeature.State =
|
||||||
val compilerArgument: String
|
byCompilerArgumentsOrNull(arguments) ?: LanguageFeature.Coroutines.defaultState
|
||||||
) : DescriptionAware {
|
|
||||||
ENABLED("Enabled", "enable"),
|
|
||||||
ENABLED_WITH_WARNING("Enabled with warning", "warn"),
|
|
||||||
DISABLED("Disabled", "error");
|
|
||||||
|
|
||||||
companion object {
|
fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when {
|
||||||
val DEFAULT = ENABLED_WITH_WARNING
|
arguments == null -> null
|
||||||
|
arguments.coroutinesEnable -> LanguageFeature.State.ENABLED
|
||||||
|
arguments.coroutinesWarn -> LanguageFeature.State.ENABLED_WITH_WARNING
|
||||||
|
arguments.coroutinesError -> LanguageFeature.State.ENABLED_WITH_ERROR
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic fun byCompilerArguments(arguments: CommonCompilerArguments?) = byCompilerArgumentsOrNull(arguments) ?: DEFAULT
|
fun byCompilerArgument(argument: String): LanguageFeature.State =
|
||||||
|
LanguageFeature.State.values().find { getCompilerArgument(it).equals(argument, ignoreCase = true) }
|
||||||
|
?: LanguageFeature.Coroutines.defaultState
|
||||||
|
|
||||||
fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?) = when {
|
fun getCompilerArgument(state: LanguageFeature.State): String = when (state) {
|
||||||
arguments == null -> null
|
LanguageFeature.State.ENABLED -> "enable"
|
||||||
arguments.coroutinesEnable -> ENABLED
|
LanguageFeature.State.ENABLED_WITH_WARNING -> "warn"
|
||||||
arguments.coroutinesWarn -> ENABLED_WITH_WARNING
|
LanguageFeature.State.ENABLED_WITH_ERROR, LanguageFeature.State.DISABLED -> "error"
|
||||||
arguments.coroutinesError -> DISABLED
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun byCompilerArgument(argument: String): CoroutineSupport {
|
|
||||||
return CoroutineSupport.values().find { it.compilerArgument.equals(argument, ignoreCase = true) } ?: DEFAULT
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,13 +111,17 @@ class KotlinFacetSettings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var coroutineSupport: CoroutineSupport
|
var coroutineSupport: LanguageFeature.State
|
||||||
get() = CoroutineSupport.byCompilerArguments(compilerArguments)
|
get() {
|
||||||
|
val languageVersion = languageLevel ?: return LanguageFeature.Coroutines.defaultState
|
||||||
|
if (languageVersion < LanguageFeature.Coroutines.sinceVersion!!) return LanguageFeature.State.DISABLED
|
||||||
|
return CoroutineSupport.byCompilerArguments(compilerArguments)
|
||||||
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
with(compilerArguments!!) {
|
with(compilerArguments!!) {
|
||||||
coroutinesEnable = value == CoroutineSupport.ENABLED
|
coroutinesEnable = value == LanguageFeature.State.ENABLED
|
||||||
coroutinesWarn = value == CoroutineSupport.ENABLED_WITH_WARNING
|
coroutinesWarn = value == LanguageFeature.State.ENABLED_WITH_WARNING
|
||||||
coroutinesError = value == CoroutineSupport.DISABLED
|
coroutinesError = value == LanguageFeature.State.ENABLED_WITH_ERROR || value == LanguageFeature.State.DISABLED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user