Freezable.{frozen, unfrozen} refactoring: add type safety

This commit is contained in:
Nikita Bobko
2021-12-09 18:56:59 +01:00
parent 8a289440ce
commit 735d46efb4
2 changed files with 9 additions and 10 deletions
@@ -40,8 +40,10 @@ abstract class Freezable {
private var frozen: Boolean = false
private fun getInstanceWithFreezeStatus(value: Boolean) = if (value == frozen) this else copyBean(this).apply { frozen = value }
internal fun getInstanceWithFreezeStatus(value: Boolean) = if (value == frozen) this else copyBean(this).apply { frozen = value }
}
fun frozen() = getInstanceWithFreezeStatus(true)
fun unfrozen() = getInstanceWithFreezeStatus(false)
}
@Suppress("UNCHECKED_CAST")
fun <T : Freezable> T.frozen(): T = getInstanceWithFreezeStatus(true) as T
@Suppress("UNCHECKED_CAST")
fun <T : Freezable> T.unfrozen(): T = getInstanceWithFreezeStatus(false) as T
@@ -7,10 +7,7 @@ package org.jetbrains.kotlin.config
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.cli.common.arguments.Argument
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.copyBean
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.TargetPlatformVersion
@@ -184,13 +181,13 @@ class KotlinFacetSettings {
var compilerArguments: CommonCompilerArguments? = null
set(value) {
field = value?.unfrozen() as CommonCompilerArguments?
field = value?.unfrozen()
updateMergedArguments()
}
var compilerSettings: CompilerSettings? = null
set(value) {
field = value?.unfrozen() as CompilerSettings?
field = value?.unfrozen()
updateMergedArguments()
}