KTIJ-29212 Align Kotlin workspace model entity's types with facet ones

Continue the work that started in e2d229c9. By making some types nullable, I clean up some logic that was based on empty strings

(^KTIJ-29151, ^KTIJ-29212) Fixed

GitOrigin-RevId: 20dba18799afc8786742ccbcc54ca64810ff2302
This commit is contained in:
Aleksei.Cherepanov
2024-03-26 13:06:27 +00:00
committed by intellij-monorepo-bot
parent 2825233df8
commit 2e99ca83dc
10 changed files with 256 additions and 169 deletions
@@ -32,7 +32,10 @@ import com.intellij.platform.workspace.storage.instrumentation.EntityStorageInst
import com.intellij.platform.workspace.storage.instrumentation.MutableEntityStorageInstrumentation
import com.intellij.platform.workspace.storage.metadata.model.EntityMetadata
import com.intellij.util.descriptors.ConfigFileItem
import org.jetbrains.kotlin.config.KotlinFacetSettings
import org.jetbrains.kotlin.config.KotlinModuleKind
import org.jetbrains.kotlin.idea.facet.KotlinFacetType
import org.jetbrains.kotlin.idea.workspaceModel.KotlinSettingsEntity.Builder
@GeneratedCodeApiVersion(3)
@GeneratedCodeImplVersion(5)
@@ -145,19 +148,19 @@ open class KotlinSettingsEntityImpl(private val dataSource: KotlinSettingsEntity
return dataSource.kind
}
override val compilerArguments: String
override val compilerArguments: String?
get() {
readField("compilerArguments")
return dataSource.compilerArguments
}
override val compilerSettings: CompilerSettingsData
override val compilerSettings: CompilerSettingsData?
get() {
readField("compilerSettings")
return dataSource.compilerSettings
}
override val targetPlatform: String
override val targetPlatform: String?
get() {
readField("targetPlatform")
return dataSource.targetPlatform
@@ -267,15 +270,6 @@ open class KotlinSettingsEntityImpl(private val dataSource: KotlinSettingsEntity
if (!getEntityData().isKindInitialized()) {
error("Field KotlinSettingsEntity#kind should be initialized")
}
if (!getEntityData().isCompilerArgumentsInitialized()) {
error("Field KotlinSettingsEntity#compilerArguments should be initialized")
}
if (!getEntityData().isCompilerSettingsInitialized()) {
error("Field KotlinSettingsEntity#compilerSettings should be initialized")
}
if (!getEntityData().isTargetPlatformInitialized()) {
error("Field KotlinSettingsEntity#targetPlatform should be initialized")
}
if (!getEntityData().isExternalSystemRunTasksInitialized()) {
error("Field KotlinSettingsEntity#externalSystemRunTasks should be initialized")
}
@@ -332,17 +326,17 @@ open class KotlinSettingsEntityImpl(private val dataSource: KotlinSettingsEntity
if (this.implementedModuleNames != dataSource.implementedModuleNames) this.implementedModuleNames = dataSource.implementedModuleNames.toMutableList()
if (this.dependsOnModuleNames != dataSource.dependsOnModuleNames) this.dependsOnModuleNames = dataSource.dependsOnModuleNames.toMutableList()
if (this.additionalVisibleModuleNames != dataSource.additionalVisibleModuleNames) this.additionalVisibleModuleNames = dataSource.additionalVisibleModuleNames.toMutableSet()
if (this.productionOutputPath != dataSource.productionOutputPath) this.productionOutputPath = dataSource.productionOutputPath
if (this.testOutputPath != dataSource.testOutputPath) this.testOutputPath = dataSource.testOutputPath
if (this.productionOutputPath != dataSource?.productionOutputPath) this.productionOutputPath = dataSource.productionOutputPath
if (this.testOutputPath != dataSource?.testOutputPath) this.testOutputPath = dataSource.testOutputPath
if (this.sourceSetNames != dataSource.sourceSetNames) this.sourceSetNames = dataSource.sourceSetNames.toMutableList()
if (this.isTestModule != dataSource.isTestModule) this.isTestModule = dataSource.isTestModule
if (this.externalProjectId != dataSource.externalProjectId) this.externalProjectId = dataSource.externalProjectId
if (this.isHmppEnabled != dataSource.isHmppEnabled) this.isHmppEnabled = dataSource.isHmppEnabled
if (this.pureKotlinSourceFolders != dataSource.pureKotlinSourceFolders) this.pureKotlinSourceFolders = dataSource.pureKotlinSourceFolders.toMutableList()
if (this.kind != dataSource.kind) this.kind = dataSource.kind
if (this.compilerArguments != dataSource.compilerArguments) this.compilerArguments = dataSource.compilerArguments
if (this.compilerSettings != dataSource.compilerSettings) this.compilerSettings = dataSource.compilerSettings
if (this.targetPlatform != dataSource.targetPlatform) this.targetPlatform = dataSource.targetPlatform
if (this.compilerArguments != dataSource?.compilerArguments) this.compilerArguments = dataSource.compilerArguments
if (this.compilerSettings != dataSource?.compilerSettings) this.compilerSettings = dataSource.compilerSettings
if (this.targetPlatform != dataSource?.targetPlatform) this.targetPlatform = dataSource.targetPlatform
if (this.externalSystemRunTasks != dataSource.externalSystemRunTasks) this.externalSystemRunTasks = dataSource.externalSystemRunTasks.toMutableList()
if (this.version != dataSource.version) this.version = dataSource.version
if (this.flushNeeded != dataSource.flushNeeded) this.flushNeeded = dataSource.flushNeeded
@@ -627,7 +621,7 @@ open class KotlinSettingsEntityImpl(private val dataSource: KotlinSettingsEntity
}
override var compilerArguments: String
override var compilerArguments: String?
get() = getEntityData().compilerArguments
set(value) {
checkModificationAllowed()
@@ -635,7 +629,7 @@ open class KotlinSettingsEntityImpl(private val dataSource: KotlinSettingsEntity
changedProperty.add("compilerArguments")
}
override var compilerSettings: CompilerSettingsData
override var compilerSettings: CompilerSettingsData?
get() = getEntityData().compilerSettings
set(value) {
checkModificationAllowed()
@@ -644,7 +638,7 @@ open class KotlinSettingsEntityImpl(private val dataSource: KotlinSettingsEntity
}
override var targetPlatform: String
override var targetPlatform: String?
get() = getEntityData().targetPlatform
set(value) {
checkModificationAllowed()
@@ -703,20 +697,20 @@ class KotlinSettingsEntityData : WorkspaceEntityData.WithCalculableSymbolicId<Ko
lateinit var implementedModuleNames: MutableList<String>
lateinit var dependsOnModuleNames: MutableList<String>
lateinit var additionalVisibleModuleNames: MutableSet<String>
var productionOutputPath: String? = null
var testOutputPath: String? = null
lateinit var sourceSetNames: MutableList<String>
var isTestModule: Boolean = false
lateinit var externalProjectId: String
var isHmppEnabled: Boolean = false
lateinit var pureKotlinSourceFolders: MutableList<String>
lateinit var kind: KotlinModuleKind
lateinit var compilerArguments: String
lateinit var compilerSettings: CompilerSettingsData
lateinit var targetPlatform: String
var compilerArguments: String? = null
var compilerSettings: CompilerSettingsData? = null
var targetPlatform: String? = null
lateinit var externalSystemRunTasks: MutableList<String>
var version: Int = 0
var flushNeeded: Boolean = false
var productionOutputPath: String? = null
var testOutputPath: String? = null
internal fun isNameInitialized(): Boolean = ::name.isInitialized
internal fun isModuleIdInitialized(): Boolean = ::moduleId.isInitialized
@@ -732,9 +726,6 @@ class KotlinSettingsEntityData : WorkspaceEntityData.WithCalculableSymbolicId<Ko
internal fun isPureKotlinSourceFoldersInitialized(): Boolean = ::pureKotlinSourceFolders.isInitialized
internal fun isKindInitialized(): Boolean = ::kind.isInitialized
internal fun isCompilerArgumentsInitialized(): Boolean = ::compilerArguments.isInitialized
internal fun isCompilerSettingsInitialized(): Boolean = ::compilerSettings.isInitialized
internal fun isTargetPlatformInitialized(): Boolean = ::targetPlatform.isInitialized
internal fun isExternalSystemRunTasksInitialized(): Boolean = ::externalSystemRunTasks.isInitialized
@@ -876,9 +867,13 @@ class KotlinSettingsEntityData : WorkspaceEntityData.WithCalculableSymbolicId<Ko
override fun createDetachedEntity(parents: List<WorkspaceEntity.Builder<*>>): WorkspaceEntity.Builder<*> {
return KotlinSettingsEntity(name, moduleId, sourceRoots, configFileItems, useProjectSettings, implementedModuleNames,
dependsOnModuleNames, additionalVisibleModuleNames, productionOutputPath, testOutputPath, sourceSetNames,
isTestModule, externalProjectId, isHmppEnabled, pureKotlinSourceFolders, kind, compilerArguments,
compilerSettings, targetPlatform, externalSystemRunTasks, version, flushNeeded, entitySource) {
dependsOnModuleNames, additionalVisibleModuleNames, sourceSetNames, isTestModule, externalProjectId,
isHmppEnabled, pureKotlinSourceFolders, kind, externalSystemRunTasks, version, flushNeeded, entitySource) {
this.productionOutputPath = this@KotlinSettingsEntityData.productionOutputPath
this.testOutputPath = this@KotlinSettingsEntityData.testOutputPath
this.compilerArguments = this@KotlinSettingsEntityData.compilerArguments
this.compilerSettings = this@KotlinSettingsEntityData.compilerSettings
this.targetPlatform = this@KotlinSettingsEntityData.targetPlatform
parents.filterIsInstance<ModuleEntity.Builder>().singleOrNull()?.let { this.module = it }
}
}
@@ -16,14 +16,15 @@ object MetadataStorageImpl: MetadataStorageBase() {
val primitiveTypeListNotNullable = ValueTypeMetadata.SimpleType.PrimitiveType(isNullable = false, type = "List")
val primitiveTypeBooleanNotNullable = ValueTypeMetadata.SimpleType.PrimitiveType(isNullable = false, type = "Boolean")
val primitiveTypeSetNotNullable = ValueTypeMetadata.SimpleType.PrimitiveType(isNullable = false, type = "Set")
val primitiveTypeStringNullable = ValueTypeMetadata.SimpleType.PrimitiveType(isNullable = true, type = "String")
val primitiveTypeIntNotNullable = ValueTypeMetadata.SimpleType.PrimitiveType(isNullable = false, type = "Int")
var typeMetadata: StorageTypeMetadata
typeMetadata = FinalClassMetadata.ClassMetadata(fqName = "org.jetbrains.kotlin.idea.workspaceModel.KotlinSettingsId", properties = listOf(OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "presentableName", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "name", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "parentId", valueType = ValueTypeMetadata.SimpleType.CustomType(isNullable = false, typeMetadata = FinalClassMetadata.ClassMetadata(fqName = "com.intellij.platform.workspace.jps.entities.ModuleId", properties = listOf(OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "presentableName", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "name", valueType = primitiveTypeStringNotNullable, withDefault = false)), supertypes = listOf("com.intellij.platform.workspace.storage.SymbolicEntityId"))), withDefault = false)), supertypes = listOf("com.intellij.platform.workspace.storage.SymbolicEntityId"))
typeMetadata = FinalClassMetadata.ClassMetadata(fqName = "org.jetbrains.kotlin.idea.workspaceModel.KotlinSettingsId", properties = listOf(OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "name", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "parentId", valueType = ValueTypeMetadata.SimpleType.CustomType(isNullable = false, typeMetadata = FinalClassMetadata.ClassMetadata(fqName = "com.intellij.platform.workspace.jps.entities.ModuleId", properties = listOf(OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "name", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "presentableName", valueType = primitiveTypeStringNotNullable, withDefault = false)), supertypes = listOf("com.intellij.platform.workspace.storage.SymbolicEntityId"))), withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "presentableName", valueType = primitiveTypeStringNotNullable, withDefault = false)), supertypes = listOf("com.intellij.platform.workspace.storage.SymbolicEntityId"))
addMetadata(typeMetadata)
@@ -41,8 +42,8 @@ OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name =
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "implementedModuleNames", valueType = ValueTypeMetadata.ParameterizedType(generics = listOf(primitiveTypeStringNotNullable), primitive = primitiveTypeListNotNullable), withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "dependsOnModuleNames", valueType = ValueTypeMetadata.ParameterizedType(generics = listOf(primitiveTypeStringNotNullable), primitive = primitiveTypeListNotNullable), withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "additionalVisibleModuleNames", valueType = ValueTypeMetadata.ParameterizedType(generics = listOf(primitiveTypeStringNotNullable), primitive = primitiveTypeSetNotNullable), withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "productionOutputPath", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "testOutputPath", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "productionOutputPath", valueType = primitiveTypeStringNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "testOutputPath", valueType = primitiveTypeStringNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "sourceSetNames", valueType = ValueTypeMetadata.ParameterizedType(generics = listOf(primitiveTypeStringNotNullable), primitive = primitiveTypeListNotNullable), withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "isTestModule", valueType = primitiveTypeBooleanNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "externalProjectId", valueType = primitiveTypeStringNotNullable, withDefault = false),
@@ -53,14 +54,13 @@ OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name =
"java.io.Serializable"), values = listOf("DEFAULT",
"SOURCE_SET_HOLDER",
"COMPILATION_AND_SOURCE_SET_HOLDER"))), withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "compilerArguments", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "compilerSettings", valueType = ValueTypeMetadata.SimpleType.CustomType(isNullable = false, typeMetadata = FinalClassMetadata.ClassMetadata(fqName = "org.jetbrains.kotlin.idea.workspaceModel.CompilerSettingsData", properties = listOf(OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "additionalArguments", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "compilerArguments", valueType = primitiveTypeStringNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "compilerSettings", valueType = ValueTypeMetadata.SimpleType.CustomType(isNullable = true, typeMetadata = FinalClassMetadata.ClassMetadata(fqName = "org.jetbrains.kotlin.idea.workspaceModel.CompilerSettingsData", properties = listOf(OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "additionalArguments", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "scriptTemplates", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "scriptTemplatesClasspath", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "copyJsLibraryFiles", valueType = primitiveTypeBooleanNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "outputDirectoryForJsLibraryFiles", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "isInitialized", valueType = primitiveTypeBooleanNotNullable, withDefault = false)), supertypes = listOf())), withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "targetPlatform", valueType = primitiveTypeStringNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "outputDirectoryForJsLibraryFiles", valueType = primitiveTypeStringNotNullable, withDefault = false)), supertypes = listOf())), withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "targetPlatform", valueType = primitiveTypeStringNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "externalSystemRunTasks", valueType = ValueTypeMetadata.ParameterizedType(generics = listOf(primitiveTypeStringNotNullable), primitive = primitiveTypeListNotNullable), withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "version", valueType = primitiveTypeIntNotNullable, withDefault = false),
OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name = "flushNeeded", valueType = primitiveTypeBooleanNotNullable, withDefault = false),
@@ -73,13 +73,13 @@ OwnPropertyMetadata(isComputable = false, isKey = false, isOpen = false, name =
}
override fun initializeMetadataHash() {
addMetadataHash(typeFqn = "org.jetbrains.kotlin.idea.workspaceModel.KotlinSettingsEntity", metadataHash = -1478960381)
addMetadataHash(typeFqn = "com.intellij.platform.workspace.jps.entities.ModuleId", metadataHash = -684863835)
addMetadataHash(typeFqn = "org.jetbrains.kotlin.idea.workspaceModel.KotlinSettingsEntity", metadataHash = 1261471986)
addMetadataHash(typeFqn = "com.intellij.platform.workspace.jps.entities.ModuleId", metadataHash = -575206713)
addMetadataHash(typeFqn = "com.intellij.util.descriptors.ConfigFileItem", metadataHash = -445249281)
addMetadataHash(typeFqn = "org.jetbrains.kotlin.config.KotlinModuleKind", metadataHash = -848779934)
addMetadataHash(typeFqn = "org.jetbrains.kotlin.idea.workspaceModel.CompilerSettingsData", metadataHash = 26052836)
addMetadataHash(typeFqn = "org.jetbrains.kotlin.idea.workspaceModel.KotlinSettingsId", metadataHash = -1378190363)
addMetadataHash(typeFqn = "com.intellij.platform.workspace.storage.SymbolicEntityId", metadataHash = -592653735)
addMetadataHash(typeFqn = "org.jetbrains.kotlin.idea.workspaceModel.CompilerSettingsData", metadataHash = -2034595788)
addMetadataHash(typeFqn = "org.jetbrains.kotlin.idea.workspaceModel.KotlinSettingsId", metadataHash = 236435207)
addMetadataHash(typeFqn = "com.intellij.platform.workspace.storage.SymbolicEntityId", metadataHash = -1609236105)
}
}
@@ -56,10 +56,8 @@ class KotlinFacetSettingsWorkspaceModel(val entity: KotlinSettingsEntity.Builder
}
val serializedArguments = entity.compilerArguments
_compilerArguments = if (serializedArguments.isNotEmpty()) {
CompilerArgumentsSerializer.deserializeFromString(serializedArguments)
} else {
null
_compilerArguments = serializedArguments?.let {
CompilerArgumentsSerializer.deserializeFromString(it)
}
return _compilerArguments
@@ -91,9 +89,7 @@ class KotlinFacetSettingsWorkspaceModel(val entity: KotlinSettingsEntity.Builder
}
val compilerSettingsData = entity.compilerSettings
if (!compilerSettingsData.isInitialized) return null
_compilerSettings = compilerSettingsData.toCompilerSettings { newSettings ->
_compilerSettings = compilerSettingsData?.toCompilerSettings { newSettings ->
entity.compilerSettings = newSettings.toCompilerSettingsData()
updateMergedArguments()
}
@@ -183,7 +179,7 @@ class KotlinFacetSettingsWorkspaceModel(val entity: KotlinSettingsEntity.Builder
get() = _productionOutputPath
set(value) {
_productionOutputPath = value
entity.productionOutputPath = value ?: ""
entity.productionOutputPath = value
}
private var _pureKotlinSourceFolders: List<String> = entity.pureKotlinSourceFolders
@@ -204,24 +200,24 @@ class KotlinFacetSettingsWorkspaceModel(val entity: KotlinSettingsEntity.Builder
override var targetPlatform: TargetPlatform?
get() {
val args = compilerArguments
val deserializedTargetPlatform =
entity.targetPlatform.takeIf { it.isNotEmpty() }.deserializeTargetPlatformByComponentPlatforms()
val singleSimplePlatform = deserializedTargetPlatform?.componentPlatforms?.singleOrNull()
entity.targetPlatform?.deserializeTargetPlatformByComponentPlatforms() ?: return null
val args = compilerArguments
val singleSimplePlatform = deserializedTargetPlatform.componentPlatforms.singleOrNull()
if (args != null && singleSimplePlatform == JvmPlatforms.defaultJvmPlatform.singleOrNull()) {
return IdePlatformKind.platformByCompilerArguments(args)
}
return deserializedTargetPlatform
}
set(value) {
entity.targetPlatform = value?.serializeComponentPlatforms() ?: ""
entity.targetPlatform = value?.serializeComponentPlatforms()
}
private var _testOutputPath: String? = entity.testOutputPath
override var testOutputPath: String?
get() = _testOutputPath
set(value) {
entity.testOutputPath = value ?: ""
entity.testOutputPath = value
_testOutputPath = value
}
}
@@ -31,17 +31,12 @@ class KotlinFacetConfigurationBridge : KotlinFacetConfiguration, FacetConfigurat
implementedModuleNames = emptyList(),
dependsOnModuleNames = emptyList(),
additionalVisibleModuleNames = emptySet(),
productionOutputPath = "",
testOutputPath = "",
sourceSetNames = emptyList(),
isTestModule = false,
externalProjectId = "",
isHmppEnabled = false,
pureKotlinSourceFolders = emptyList(),
kind = KotlinModuleKind.DEFAULT,
compilerArguments = "",
compilerSettings = CompilerSettingsData("", "", "", true, "lib", false),
targetPlatform = "",
externalSystemRunTasks = emptyList(),
version = KotlinFacetSettings.CURRENT_VERSION,
flushNeeded = false,
@@ -58,24 +53,23 @@ class KotlinFacetConfigurationBridge : KotlinFacetConfiguration, FacetConfigurat
originKotlinSettingsEntity.implementedModuleNames,
originKotlinSettingsEntity.dependsOnModuleNames,
originKotlinSettingsEntity.additionalVisibleModuleNames,
originKotlinSettingsEntity.productionOutputPath,
originKotlinSettingsEntity.testOutputPath,
originKotlinSettingsEntity.sourceSetNames,
originKotlinSettingsEntity.isTestModule,
originKotlinSettingsEntity.externalProjectId,
originKotlinSettingsEntity.isHmppEnabled,
originKotlinSettingsEntity.pureKotlinSourceFolders,
originKotlinSettingsEntity.kind,
originKotlinSettingsEntity.compilerArguments,
originKotlinSettingsEntity.compilerSettings,
originKotlinSettingsEntity.targetPlatform,
originKotlinSettingsEntity.externalSystemRunTasks,
originKotlinSettingsEntity.version,
originKotlinSettingsEntity.flushNeeded,
originKotlinSettingsEntity.entitySource
) {
}) {
}
productionOutputPath = originKotlinSettingsEntity.productionOutputPath
testOutputPath = originKotlinSettingsEntity.testOutputPath
compilerArguments = originKotlinSettingsEntity.compilerArguments
compilerSettings = originKotlinSettingsEntity.compilerSettings
targetPlatform = originKotlinSettingsEntity.targetPlatform
})
override fun init(moduleEntity: ModuleEntity, entitySource: EntitySource) {
kotlinSettingsEntity.moduleId = moduleEntity.symbolicId
@@ -96,23 +90,23 @@ class KotlinFacetConfigurationBridge : KotlinFacetConfiguration, FacetConfigurat
kotlinSettingsEntity.implementedModuleNames,
kotlinSettingsEntity.dependsOnModuleNames,
kotlinSettingsEntity.additionalVisibleModuleNames,
kotlinSettingsEntity.productionOutputPath,
kotlinSettingsEntity.testOutputPath,
kotlinSettingsEntity.sourceSetNames,
kotlinSettingsEntity.isTestModule,
kotlinSettingsEntity.externalProjectId,
kotlinSettingsEntity.isHmppEnabled,
kotlinSettingsEntity.pureKotlinSourceFolders,
kotlinSettingsEntity.kind,
kotlinSettingsEntity.compilerArguments,
kotlinSettingsEntity.compilerSettings,
kotlinSettingsEntity.targetPlatform,
kotlinSettingsEntity.externalSystemRunTasks,
kotlinSettingsEntity.version,
kotlinSettingsEntity.flushNeeded,
kotlinSettingsEntity.entitySource,
) {
module = moduleEntity
productionOutputPath = kotlinSettingsEntity.productionOutputPath
testOutputPath = kotlinSettingsEntity.testOutputPath
compilerArguments = kotlinSettingsEntity.compilerArguments
compilerSettings = kotlinSettingsEntity.compilerSettings
targetPlatform = kotlinSettingsEntity.targetPlatform
}
}
@@ -34,28 +34,23 @@ class KotlinModuleSettingsSerializer : CustomFacetRelatedEntitySerializer<Kotlin
) {
val entitySource = evaluateEntitySource(facetState)
val kotlinSettingsEntity = KotlinSettingsEntity(
facetState.name, ModuleId(moduleEntity.name),
emptyList(),
emptyList(),
true,
emptyList(),
emptyList(),
emptySet(),
"",
"",
emptyList(),
false,
"",
false,
emptyList(),
KotlinModuleKind.DEFAULT,
"",
CompilerSettingsData("", "", "", true, "lib", false),
"",
emptyList(),
KotlinFacetSettings.CURRENT_VERSION,
false,
entitySource
name = facetState.name, moduleId = ModuleId(moduleEntity.name),
sourceRoots = emptyList(),
configFileItems = emptyList(),
useProjectSettings = true,
implementedModuleNames = emptyList(),
dependsOnModuleNames = emptyList(),
additionalVisibleModuleNames = emptySet(),
sourceSetNames = emptyList(),
isTestModule = false,
externalProjectId = "",
isHmppEnabled = false,
pureKotlinSourceFolders = emptyList(),
kind = KotlinModuleKind.DEFAULT,
externalSystemRunTasks = emptyList(),
version = KotlinFacetSettings.CURRENT_VERSION,
flushNeeded = false,
entitySource = entitySource
) {
module = moduleEntity
}
@@ -76,27 +71,22 @@ class KotlinModuleSettingsSerializer : CustomFacetRelatedEntitySerializer<Kotlin
kotlinSettingsEntity.testOutputPath = kotlinFacetSettings.testOutputPath
kotlinSettingsEntity.sourceSetNames = kotlinFacetSettings.sourceSetNames.toMutableList()
kotlinSettingsEntity.isTestModule = kotlinFacetSettings.isTestModule
kotlinSettingsEntity.targetPlatform = kotlinFacetSettings.targetPlatform?.serializeComponentPlatforms() ?: ""
kotlinSettingsEntity.targetPlatform = kotlinFacetSettings.targetPlatform?.serializeComponentPlatforms()
kotlinSettingsEntity.externalProjectId = kotlinFacetSettings.externalProjectId
kotlinSettingsEntity.isHmppEnabled = kotlinFacetSettings.isHmppEnabled
kotlinSettingsEntity.pureKotlinSourceFolders = kotlinFacetSettings.pureKotlinSourceFolders.toMutableList()
kotlinSettingsEntity.kind = kotlinFacetSettings.kind
if (kotlinFacetSettings.compilerArguments != null) {
kotlinSettingsEntity.compilerArguments = CompilerArgumentsSerializer.serializeToString(kotlinFacetSettings.compilerArguments!!)
}
val compilerSettings = kotlinFacetSettings.compilerSettings
if (compilerSettings != null) {
kotlinSettingsEntity.compilerSettings = CompilerSettingsData(
compilerSettings.additionalArguments,
compilerSettings.scriptTemplates,
compilerSettings.scriptTemplatesClasspath,
compilerSettings.copyJsLibraryFiles,
compilerSettings.outputDirectoryForJsLibraryFiles,
true
kotlinSettingsEntity.compilerArguments = CompilerArgumentsSerializer.serializeToString(kotlinFacetSettings.compilerArguments)
kotlinSettingsEntity.compilerSettings = kotlinFacetSettings.compilerSettings?.let {
CompilerSettingsData(
it.additionalArguments,
it.scriptTemplates,
it.scriptTemplatesClasspath,
it.copyJsLibraryFiles,
it.outputDirectoryForJsLibraryFiles
)
}
kotlinSettingsEntity.externalSystemRunTasks =
kotlinFacetSettings.externalSystemRunTasks.map { it.serializeExternalSystemTestRunTask() }.toMutableList()
kotlinSettingsEntity.flushNeeded =
@@ -109,23 +99,23 @@ class KotlinModuleSettingsSerializer : CustomFacetRelatedEntitySerializer<Kotlin
version = entity.version
useProjectSettings = entity.useProjectSettings
compilerArguments =
if (entity.compilerArguments.isEmpty()) null else CompilerArgumentsSerializer.deserializeFromString(entity.compilerArguments)
compilerArguments = CompilerArgumentsSerializer.deserializeFromString(entity.compilerArguments)
val compilerSettingsFromEntity = entity.compilerSettings
compilerSettings = CompilerSettings().apply {
additionalArguments = compilerSettingsFromEntity.additionalArguments
scriptTemplates = compilerSettingsFromEntity.scriptTemplates
scriptTemplatesClasspath = compilerSettingsFromEntity.scriptTemplatesClasspath
copyJsLibraryFiles = compilerSettingsFromEntity.copyJsLibraryFiles
outputDirectoryForJsLibraryFiles = compilerSettingsFromEntity.outputDirectoryForJsLibraryFiles
compilerSettings = entity.compilerSettings?.let {
CompilerSettings().apply {
additionalArguments = it.additionalArguments
scriptTemplates = it.scriptTemplates
scriptTemplatesClasspath = it.scriptTemplatesClasspath
copyJsLibraryFiles = it.copyJsLibraryFiles
outputDirectoryForJsLibraryFiles = it.outputDirectoryForJsLibraryFiles
}
}
implementedModuleNames = entity.implementedModuleNames
dependsOnModuleNames = entity.dependsOnModuleNames
additionalVisibleModuleNames = entity.additionalVisibleModuleNames
productionOutputPath = entity.productionOutputPath?.ifEmpty { null }
testOutputPath = entity.testOutputPath?.ifEmpty { null }
productionOutputPath = entity.productionOutputPath
testOutputPath = entity.testOutputPath
kind = entity.kind
sourceSetNames = entity.sourceSetNames
isTestModule = entity.isTestModule
@@ -136,7 +126,7 @@ class KotlinModuleSettingsSerializer : CustomFacetRelatedEntitySerializer<Kotlin
val args = compilerArguments
val deserializedTargetPlatform =
entity.targetPlatform.takeIf { it.isNotEmpty() }.deserializeTargetPlatformByComponentPlatforms()
entity.targetPlatform?.deserializeTargetPlatformByComponentPlatforms()
val singleSimplePlatform = deserializedTargetPlatform?.componentPlatforms?.singleOrNull()
if (singleSimplePlatform == JvmPlatforms.defaultJvmPlatform.singleOrNull() && args != null) {
targetPlatform = IdePlatformKind.platformByCompilerArguments(args)
@@ -15,7 +15,10 @@ import com.intellij.platform.workspace.storage.annotations.Child
import com.intellij.platform.workspace.storage.impl.containers.toMutableWorkspaceList
import com.intellij.platform.workspace.storage.impl.containers.toMutableWorkspaceSet
import com.intellij.util.descriptors.ConfigFileItem
import org.jetbrains.kotlin.config.KotlinFacetSettings
import org.jetbrains.kotlin.config.KotlinModuleKind
import org.jetbrains.kotlin.idea.facet.KotlinFacetType
import org.jetbrains.kotlin.idea.workspaceModel.KotlinSettingsEntity.Builder
interface KotlinSettingsEntity : ModuleSettingsBase {
val sourceRoots: List<String>
@@ -42,25 +45,115 @@ interface KotlinSettingsEntity : ModuleSettingsBase {
val kind: KotlinModuleKind
//non-trivial parameters
val compilerArguments: String
val compilerSettings: CompilerSettingsData
val compilerArguments: String?
val compilerSettings: CompilerSettingsData?
val targetPlatform: String
val targetPlatform: String?
val externalSystemRunTasks: List<String>
val version: Int
val flushNeeded: Boolean
override val symbolicId: KotlinSettingsId
get() = KotlinSettingsId(name, moduleId)
//region generated code
@GeneratedCodeApiVersion(3)
interface Builder : WorkspaceEntity.Builder<KotlinSettingsEntity>, ModuleSettingsBase.Builder<KotlinSettingsEntity> {
override var entitySource: EntitySource
override var name: String
override var moduleId: ModuleId
var sourceRoots: MutableList<String>
var configFileItems: MutableList<ConfigFileItem>
var module: ModuleEntity.Builder
var useProjectSettings: Boolean
var implementedModuleNames: MutableList<String>
var dependsOnModuleNames: MutableList<String>
var additionalVisibleModuleNames: MutableSet<String>
var productionOutputPath: String?
var testOutputPath: String?
var sourceSetNames: MutableList<String>
var isTestModule: Boolean
var externalProjectId: String
var isHmppEnabled: Boolean
var pureKotlinSourceFolders: MutableList<String>
var kind: KotlinModuleKind
var compilerArguments: String?
var compilerSettings: CompilerSettingsData?
var targetPlatform: String?
var externalSystemRunTasks: MutableList<String>
var version: Int
var flushNeeded: Boolean
}
companion object : EntityType<KotlinSettingsEntity, Builder>(ModuleSettingsBase) {
@JvmOverloads
@JvmStatic
@JvmName("create")
operator fun invoke(
name: String,
moduleId: ModuleId,
sourceRoots: List<String>,
configFileItems: List<ConfigFileItem>,
useProjectSettings: Boolean,
implementedModuleNames: List<String>,
dependsOnModuleNames: List<String>,
additionalVisibleModuleNames: Set<String>,
sourceSetNames: List<String>,
isTestModule: Boolean,
externalProjectId: String,
isHmppEnabled: Boolean,
pureKotlinSourceFolders: List<String>,
kind: KotlinModuleKind,
externalSystemRunTasks: List<String>,
version: Int,
flushNeeded: Boolean,
entitySource: EntitySource,
init: (Builder.() -> Unit)? = null,
): Builder {
val builder = builder()
builder.name = name
builder.moduleId = moduleId
builder.sourceRoots = sourceRoots.toMutableWorkspaceList()
builder.configFileItems = configFileItems.toMutableWorkspaceList()
builder.useProjectSettings = useProjectSettings
builder.implementedModuleNames = implementedModuleNames.toMutableWorkspaceList()
builder.dependsOnModuleNames = dependsOnModuleNames.toMutableWorkspaceList()
builder.additionalVisibleModuleNames = additionalVisibleModuleNames.toMutableWorkspaceSet()
builder.sourceSetNames = sourceSetNames.toMutableWorkspaceList()
builder.isTestModule = isTestModule
builder.externalProjectId = externalProjectId
builder.isHmppEnabled = isHmppEnabled
builder.pureKotlinSourceFolders = pureKotlinSourceFolders.toMutableWorkspaceList()
builder.kind = kind
builder.externalSystemRunTasks = externalSystemRunTasks.toMutableWorkspaceList()
builder.version = version
builder.flushNeeded = flushNeeded
builder.entitySource = entitySource
init?.invoke(builder)
return builder
}
}
//endregion
}
//region generated code
fun MutableEntityStorage.modifyEntity(
entity: KotlinSettingsEntity,
modification: KotlinSettingsEntity.Builder.() -> Unit,
): KotlinSettingsEntity {
return modifyEntity(KotlinSettingsEntity.Builder::class.java, entity, modification)
}
var ModuleEntity.Builder.kotlinSettings: @Child List<KotlinSettingsEntity.Builder>
by WorkspaceEntity.extensionBuilder(KotlinSettingsEntity::class.java)
//endregion
data class CompilerSettingsData(
val additionalArguments: String,
val scriptTemplates: String,
val scriptTemplatesClasspath: String,
val copyJsLibraryFiles: Boolean,
val outputDirectoryForJsLibraryFiles: String,
val isInitialized: Boolean
val outputDirectoryForJsLibraryFiles: String
)
val ModuleEntity.kotlinSettings: List<@Child KotlinSettingsEntity>
@@ -51,15 +51,15 @@ fun CompilerSettingsData.toCompilerSettings(notifier: (CompilerSettings) -> Unit
it.outputDirectoryForJsLibraryFiles = this.outputDirectoryForJsLibraryFiles
}
fun CompilerSettings?.toCompilerSettingsData(): CompilerSettingsData =
fun CompilerSettings?.toCompilerSettingsData(): CompilerSettingsData? = this?.let {
CompilerSettingsData(
this?.additionalArguments ?: "",
this?.scriptTemplates ?: "",
this?.scriptTemplatesClasspath ?: "",
this?.copyJsLibraryFiles ?: true,
this?.outputDirectoryForJsLibraryFiles ?: "lib",
true
additionalArguments,
scriptTemplates,
scriptTemplatesClasspath,
copyJsLibraryFiles,
outputDirectoryForJsLibraryFiles
)
}
fun ExternalSystemRunTask.serializeExternalSystemTestRunTask(): String {
return when(this) {
@@ -96,17 +96,15 @@ object CompilerArgumentsSerializer {
"D" to CommonCompilerArguments.DummyImpl::class.java
)
fun serializeToString(commonCompilerArguments: CommonCompilerArguments?): String {
return commonCompilerArguments?.let {
val classIdentifier = argumentsTypeMap.entries.firstOrNull { it.value == commonCompilerArguments.javaClass }?.key
?: error("Class not found: ${commonCompilerArguments.javaClass}")
fun serializeToString(commonCompilerArguments: CommonCompilerArguments?): String? = commonCompilerArguments?.let {
val classIdentifier = argumentsTypeMap.entries.firstOrNull { it.value == commonCompilerArguments.javaClass }?.key
?: error("Class not found: ${commonCompilerArguments.javaClass}")
classIdentifier + gson.toJson(commonCompilerArguments)
} ?: ""
classIdentifier + gson.toJson(commonCompilerArguments)
}
fun deserializeFromString(serializedArguments: String): CommonCompilerArguments? {
return when {
fun deserializeFromString(serializedArguments: String?): CommonCompilerArguments? = serializedArguments?.let {
when {
serializedArguments.isEmpty() -> null
serializedArguments.isNotBlank() && serializedArguments[0].isLetter() -> {
val classIdentifier = serializedArguments.substring(0, 1)
@@ -95,6 +95,19 @@ class KotlinFacetBridgeTest : KotlinFacetTestCase() {
fireFacetChangedAndValidateKotlinFacet(mainFacet)
}
fun testCreateFacetAndCheckNullableTypes() {
val mainFacet = getKotlinFacet()
checkStorageForEntityAndFacet()
mainFacet.configuration.settings.compilerArguments = null
mainFacet.configuration.settings.compilerSettings = null
mainFacet.configuration.settings.targetPlatform = null
mainFacet.configuration.settings.productionOutputPath = null
mainFacet.configuration.settings.testOutputPath = null
fireFacetChangedAndValidateKotlinFacet(mainFacet)
}
private fun fireFacetChangedAndValidateKotlinFacet(mainFacet: KotlinFacet) {
val allFacets = FacetManager.getInstance(myModule).allFacets
assertSize(1, allFacets)
@@ -135,5 +148,25 @@ class KotlinFacetBridgeTest : KotlinFacetTestCase() {
"externalSystemRunTasks differs. Entity: ${entity.externalSystemRunTasks}, facet: ${facet.configuration.settings.externalSystemRunTasks}",
entity.externalSystemRunTasks.map { deserializeExternalSystemTestRunTask(it) } == facet.configuration.settings.externalSystemRunTasks
)
assertTrue(
"compilerArguments is not null",
entity.compilerArguments == null
)
assertTrue(
"compilerSettings is not null",
entity.compilerSettings == null
)
assertTrue(
"targetPlatform differs. Entity: ${entity.targetPlatform}, facet: ${facet.configuration.settings.targetPlatform}",
entity.targetPlatform == null
)
assertTrue(
"productionOutputPath differs. Entity: ${entity.productionOutputPath}, facet: ${facet.configuration.settings.productionOutputPath}",
entity.productionOutputPath == facet.configuration.settings.productionOutputPath
)
assertTrue(
"testOutputPath differs. Entity: ${entity.testOutputPath}, facet: ${facet.configuration.settings.testOutputPath}",
entity.testOutputPath == facet.configuration.settings.testOutputPath
)
}
}
@@ -251,17 +251,12 @@ class KotlinFacetEventListenerTest {
implementedModuleNames = emptyList(),
dependsOnModuleNames = emptyList(),
additionalVisibleModuleNames = emptySet(),
productionOutputPath = "",
testOutputPath = "",
sourceSetNames = emptyList(),
isTestModule = false,
externalProjectId = "",
isHmppEnabled = false,
pureKotlinSourceFolders = emptyList(),
kind = KotlinModuleKind.DEFAULT,
compilerArguments = "",
compilerSettings = CompilerSettingsData("", "", "", true, "lib", false),
targetPlatform = "",
externalSystemRunTasks = emptyList(),
version = KotlinFacetSettings.CURRENT_VERSION,
flushNeeded = false,
@@ -56,17 +56,12 @@ class KotlinMavenImporterEx : KotlinMavenImporter(), MavenWorkspaceFacetConfigur
emptyList(),
emptyList(),
emptySet(),
"",
"",
emptyList(),
false,
"",
false,
emptyList(),
KotlinModuleKind.DEFAULT,
"",
CompilerSettingsData("", "", "", true, "lib", true),
"",
emptyList(),
KotlinFacetSettings.CURRENT_VERSION,
false,
@@ -233,8 +228,8 @@ class KotlinMavenImporterEx : KotlinMavenImporter(), MavenWorkspaceFacetConfigur
this.implementedModuleNames = kotlinFacetSettings.implementedModuleNames.toMutableList()
this.dependsOnModuleNames = kotlinFacetSettings.dependsOnModuleNames.toMutableList()
this.additionalVisibleModuleNames = kotlinFacetSettings.additionalVisibleModuleNames.toMutableSet()
this.productionOutputPath = kotlinFacetSettings.productionOutputPath ?: ""
this.testOutputPath = kotlinFacetSettings.testOutputPath ?: ""
this.productionOutputPath = kotlinFacetSettings.productionOutputPath
this.testOutputPath = kotlinFacetSettings.testOutputPath
this.sourceSetNames = kotlinFacetSettings.sourceSetNames.toMutableList()
this.isTestModule = kotlinFacetSettings.isTestModule
this.externalProjectId = "Maven"
@@ -242,18 +237,16 @@ class KotlinMavenImporterEx : KotlinMavenImporter(), MavenWorkspaceFacetConfigur
this.pureKotlinSourceFolders = kotlinFacetSettings.pureKotlinSourceFolders.toMutableList()
this.kind = kotlinFacetSettings.kind
this.compilerArguments = CompilerArgumentsSerializer.serializeToString(kotlinFacetSettings.compilerArguments)
val compilerSettings = kotlinFacetSettings.compilerSettings
this.compilerSettings =
if (compilerSettings == null) CompilerSettingsData("", "", "", true, "lib", false)
else CompilerSettingsData(
compilerSettings.additionalArguments,
compilerSettings.scriptTemplates,
compilerSettings.scriptTemplatesClasspath,
compilerSettings.copyJsLibraryFiles,
compilerSettings.outputDirectoryForJsLibraryFiles,
true
this.compilerSettings = kotlinFacetSettings.compilerSettings?.let {
CompilerSettingsData(
it.additionalArguments,
it.scriptTemplates,
it.scriptTemplatesClasspath,
it.copyJsLibraryFiles,
it.outputDirectoryForJsLibraryFiles
)
this.targetPlatform = kotlinFacetSettings.targetPlatform?.serializeComponentPlatforms() ?: ""
}
this.targetPlatform = kotlinFacetSettings.targetPlatform?.serializeComponentPlatforms()
}
}