Extract interface from KotinFacetSettings

This commit is contained in:
Aleksei.Cherepanov
2023-06-19 16:45:14 +02:00
committed by Space Team
parent 5f5e76a09b
commit feeddc4ea3
@@ -157,52 +157,37 @@ data class ExternalSystemNativeMainRunTask(
} }
} }
class KotlinFacetSettings { interface IKotlinFacetSettings {
companion object { var version: Int
// Increment this when making serialization-incompatible changes to configuration data var useProjectSettings: Boolean
val CURRENT_VERSION = 5 val mergedCompilerArguments: CommonCompilerArguments?
val DEFAULT_VERSION = 0 var compilerArguments: CommonCompilerArguments?
} var compilerSettings: CompilerSettings?
var languageLevel: LanguageVersion?
var apiLevel: LanguageVersion?
var targetPlatform: TargetPlatform?
var externalSystemRunTasks: List<ExternalSystemRunTask>
var implementedModuleNames: List<String>
var dependsOnModuleNames: List<String>
var additionalVisibleModuleNames: Set<String>
var productionOutputPath: String?
var testOutputPath: String?
var kind: KotlinModuleKind
var sourceSetNames: List<String>
var isTestModule: Boolean
var externalProjectId: String
var isHmppEnabled: Boolean
val mppVersion: KotlinMultiplatformVersion?
var pureKotlinSourceFolders: List<String>
var version = CURRENT_VERSION fun updateMergedArguments()
var useProjectSettings: Boolean = true
var mergedCompilerArguments: CommonCompilerArguments? = null
private set
// TODO: Workaround for unwanted facet settings modification on code analysis
// To be replaced with proper API for settings update (see BaseKotlinCompilerSettings as an example)
fun updateMergedArguments() {
val compilerArguments = compilerArguments
val compilerSettings = compilerSettings
mergedCompilerArguments = if (compilerArguments != null) {
compilerArguments.copyOf().apply {
if (compilerSettings != null) {
parseCommandLineArguments(compilerSettings.additionalArgumentsAsList, this)
}
if (this is K2JVMCompilerArguments) this.classpath = ""
}
} else null
}
var compilerArguments: CommonCompilerArguments? = null
set(value) {
field = value?.unfrozen()
updateMergedArguments()
}
var compilerSettings: CompilerSettings? = null
set(value) {
field = value?.unfrozen()
updateMergedArguments()
} }
/* /*
This function is needed as some setting values may not be present in compilerArguments This function is needed as some setting values may not be present in compilerArguments
but present in additional arguments instead, so we have to check both cases manually but present in additional arguments instead, so we have to check both cases manually
*/ */
inline fun <reified A : CommonCompilerArguments> isCompilerSettingPresent(settingReference: KProperty1<A, Boolean>): Boolean { inline fun <reified A : CommonCompilerArguments> IKotlinFacetSettings.isCompilerSettingPresent(settingReference: KProperty1<A, Boolean>): Boolean {
val isEnabledByCompilerArgument = compilerArguments?.safeAs<A>()?.let(settingReference::get) val isEnabledByCompilerArgument = compilerArguments?.safeAs<A>()?.let(settingReference::get)
if (isEnabledByCompilerArgument == true) return true if (isEnabledByCompilerArgument == true) return true
val isEnabledByAdditionalSettings = run { val isEnabledByAdditionalSettings = run {
@@ -212,7 +197,50 @@ class KotlinFacetSettings {
return isEnabledByAdditionalSettings ?: false return isEnabledByAdditionalSettings ?: false
} }
var languageLevel: LanguageVersion? class KotlinFacetSettings: IKotlinFacetSettings {
companion object {
// Increment this when making serialization-incompatible changes to configuration data
val CURRENT_VERSION = 5
val DEFAULT_VERSION = 0
}
override var version = CURRENT_VERSION
override var useProjectSettings: Boolean = true
private var _mergedCompilerArguments: CommonCompilerArguments? = null
override val mergedCompilerArguments: CommonCompilerArguments?
get() = _mergedCompilerArguments
// TODO: Workaround for unwanted facet settings modification on code analysis
// To be replaced with proper API for settings update (see BaseKotlinCompilerSettings as an example)
override fun updateMergedArguments() {
val compilerArguments = compilerArguments
val compilerSettings = compilerSettings
_mergedCompilerArguments = if (compilerArguments != null) {
compilerArguments.copyOf().apply {
if (compilerSettings != null) {
parseCommandLineArguments(compilerSettings.additionalArgumentsAsList, this)
}
if (this is K2JVMCompilerArguments) this.classpath = ""
}
} else null
}
override var compilerArguments: CommonCompilerArguments? = null
set(value) {
field = value?.unfrozen()
updateMergedArguments()
}
override var compilerSettings: CompilerSettings? = null
set(value) {
field = value?.unfrozen()
updateMergedArguments()
}
override var languageLevel: LanguageVersion?
get() = compilerArguments?.languageVersion?.let { LanguageVersion.fromFullVersionString(it) } get() = compilerArguments?.languageVersion?.let { LanguageVersion.fromFullVersionString(it) }
set(value) { set(value) {
compilerArguments?.apply { compilerArguments?.apply {
@@ -220,7 +248,7 @@ class KotlinFacetSettings {
} }
} }
var apiLevel: LanguageVersion? override var apiLevel: LanguageVersion?
get() = compilerArguments?.apiVersion?.let { LanguageVersion.fromFullVersionString(it) } get() = compilerArguments?.apiVersion?.let { LanguageVersion.fromFullVersionString(it) }
set(value) { set(value) {
compilerArguments?.apply { compilerArguments?.apply {
@@ -228,7 +256,7 @@ class KotlinFacetSettings {
} }
} }
var targetPlatform: TargetPlatform? = null override var targetPlatform: TargetPlatform? = null
get() { get() {
// This work-around is required in order to fix importing of the proper JVM target version and works only // This work-around is required in order to fix importing of the proper JVM target version and works only
// for fully actualized JVM target platform // for fully actualized JVM target platform
@@ -241,7 +269,7 @@ class KotlinFacetSettings {
return field return field
} }
var externalSystemRunTasks: List<ExternalSystemRunTask> = emptyList() override var externalSystemRunTasks: List<ExternalSystemRunTask> = emptyList()
@Suppress("DEPRECATION_ERROR") @Suppress("DEPRECATION_ERROR")
@Deprecated( @Deprecated(
@@ -253,25 +281,25 @@ class KotlinFacetSettings {
return targetPlatform?.toIdePlatform() return targetPlatform?.toIdePlatform()
} }
var implementedModuleNames: List<String> = emptyList() // used for first implementation of MPP, aka 'old' MPP override var implementedModuleNames: List<String> = emptyList() // used for first implementation of MPP, aka 'old' MPP
var dependsOnModuleNames: List<String> = emptyList() // used for New MPP and later implementations override var dependsOnModuleNames: List<String> = emptyList() // used for New MPP and later implementations
var additionalVisibleModuleNames: Set<String> = emptySet() override var additionalVisibleModuleNames: Set<String> = emptySet()
var productionOutputPath: String? = null override var productionOutputPath: String? = null
var testOutputPath: String? = null override var testOutputPath: String? = null
var kind: KotlinModuleKind = KotlinModuleKind.DEFAULT override var kind: KotlinModuleKind = KotlinModuleKind.DEFAULT
var sourceSetNames: List<String> = emptyList() override var sourceSetNames: List<String> = emptyList()
var isTestModule: Boolean = false override var isTestModule: Boolean = false
var externalProjectId: String = "" override var externalProjectId: String = ""
var isHmppEnabled: Boolean = false override var isHmppEnabled: Boolean = false
@Deprecated(message = "Use mppVersion.isHmppEnabled", ReplaceWith("mppVersion.isHmpp")) @Deprecated(message = "Use mppVersion.isHmppEnabled", ReplaceWith("mppVersion.isHmpp"))
get get
val mppVersion: KotlinMultiplatformVersion? override val mppVersion: KotlinMultiplatformVersion?
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
get() = when { get() = when {
isHmppEnabled -> KotlinMultiplatformVersion.M3 isHmppEnabled -> KotlinMultiplatformVersion.M3
@@ -280,5 +308,5 @@ class KotlinFacetSettings {
else -> null else -> null
} }
var pureKotlinSourceFolders: List<String> = emptyList() override var pureKotlinSourceFolders: List<String> = emptyList()
} }