IJPL-136 cleanup

GitOrigin-RevId: dbe478c8bf949fd105503428c3d207dfa6e900bd
This commit is contained in:
Vladimir Krivosheev
2024-02-12 11:09:52 +01:00
committed by intellij-monorepo-bot
parent f4a601a4a1
commit d670b446d9
6 changed files with 67 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:Suppress("ReplaceGetOrSet")
@file:Suppress("ReplaceGetOrSet", "ReplaceJavaStaticMethodWithKotlinAnalog")
package com.intellij.configurationStore
@@ -18,7 +18,7 @@ import com.intellij.openapi.diagnostic.*
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.JDOMUtil
import com.intellij.openapi.util.SafeStAXStreamBuilder
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.util.use
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
@@ -27,6 +27,7 @@ import com.intellij.util.ResourceUtil
import com.intellij.util.ThreeState
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.intellij.util.messages.MessageBus
import com.intellij.util.xml.dom.createXmlStreamReader
import com.intellij.util.xmlb.XmlSerializerUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@@ -188,8 +189,10 @@ abstract class ComponentStoreImpl : IComponentStore {
final override fun initPersistencePlainComponent(component: Any, key: String) {
val stateSpec = StateAnnotation(key, FileStorageAnnotation(StoragePathMacros.WORKSPACE_FILE, false))
registerComponent(name = stateSpec.name,
info = createComponentInfo(PersistenceStateAdapter(component), stateSpec, serviceDescriptor = null))
registerComponent(
name = stateSpec.name,
info = createComponentInfo(component = PersistenceStateAdapter(component), stateSpec = stateSpec, serviceDescriptor = null),
)
}
override suspend fun save(forceSavingAllSettings: Boolean) {
@@ -296,7 +299,12 @@ abstract class ComponentStoreImpl : IComponentStore {
VfsRootAccess.allowRootAccess(it, absolutePath)
@Suppress("DEPRECATION")
runUnderModalProgressIfIsEdt {
commitComponent(saveManager, ComponentInfoImpl(component, stateSpec), componentName = null, modificationCountChanged = false)
commitComponent(
sessionManager = saveManager,
info = ComponentInfoImpl(component, stateSpec),
componentName = null,
modificationCountChanged = false,
)
val saveResult = SaveResult()
saveManager.save(saveResult)
saveResult.rethrow()
@@ -363,7 +371,7 @@ abstract class ComponentStoreImpl : IComponentStore {
val sessionProducer = sessionManager.getProducer(storage) ?: continue
if (resolution == Resolution.CLEAR ||
(storageSpec.deprecated && storageSpecs.none { !it.deprecated && it.value == storageSpec.value })) {
sessionProducer.setState(component, effectiveComponentName, state = null)
sessionProducer.setState(component = component, componentName = effectiveComponentName, state = null)
}
else {
if (!stateRequested) {
@@ -423,7 +431,11 @@ abstract class ComponentStoreImpl : IComponentStore {
protected fun initComponentWithoutStateSpec(component: PersistentStateComponent<Any>, configurationSchemaKey: String): Boolean {
val stateClass = ComponentSerializationUtil.getStateClass<Any>(component.javaClass)
val storage = getReadOnlyStorage(component.javaClass, stateClass, configurationSchemaKey)
val storage = getReadOnlyStorage(
componentClass = component.javaClass,
stateClass = stateClass,
configurationSchemaKey = configurationSchemaKey,
)
val state = storage?.getState(component = component, componentName = "", stateClass = stateClass, mergeInto = null, reload = false)
if (state == null) {
component.noStateLoaded()
@@ -530,8 +542,10 @@ abstract class ComponentStoreImpl : IComponentStore {
return !storageSpec.deprecated && stateSpec.reportStatistic && storageSpec.value != StoragePathMacros.CACHE_FILE
}
private fun isStorageChanged(changedStorages: Set<StateStorage>, storage: StateStorage): Boolean =
changedStorages.contains(storage) || (storage is ExternalStorageWithInternalPart && changedStorages.contains(storage.internalStorage))
private fun isStorageChanged(changedStorages: Set<StateStorage>, storage: StateStorage): Boolean {
return changedStorages.contains(storage) ||
(storage is ExternalStorageWithInternalPart && changedStorages.contains(storage.internalStorage))
}
protected open fun doCreateStateGetter(reloadData: Boolean,
storage: StateStorage,
@@ -560,7 +574,13 @@ abstract class ComponentStoreImpl : IComponentStore {
val classLoader = component.javaClass.classLoader
val data = ResourceUtil.getResourceAsBytes("$componentName.xml", classLoader) ?: return null
try {
val element = JDOMUtil.load(data)
val xmlStreamReader = createXmlStreamReader(data)
val element = try {
SafeStAXStreamBuilder.build(xmlStreamReader, true, false, SafeStAXStreamBuilder.FACTORY)
}
finally {
xmlStreamReader.close()
}
getPathMacroManagerForDefaults()?.expandPaths(element)
return deserializeState(stateElement = element, stateClass = stateClass)
}
@@ -622,14 +642,14 @@ abstract class ComponentStoreImpl : IComponentStore {
}
override fun reloadStates(componentNames: Set<String>, messageBus: MessageBus) {
reinitComponents(componentNames, changedStorages = emptySet(), notReloadableComponents = emptySet())
reinitComponents(componentNames = componentNames, changedStorages = emptySet(), notReloadableComponents = emptySet())
}
internal fun batchReloadStates(componentNames: Set<String>, messageBus: MessageBus) {
val publisher = messageBus.syncPublisher(BatchUpdateListener.TOPIC)
publisher.onBatchUpdateStarted()
try {
reinitComponents(componentNames, changedStorages = emptySet(), notReloadableComponents = emptySet())
reinitComponents(componentNames = componentNames, changedStorages = emptySet(), notReloadableComponents = emptySet())
}
finally {
publisher.onBatchUpdateFinished()
@@ -640,7 +660,7 @@ abstract class ComponentStoreImpl : IComponentStore {
val stateSpec = getStateSpecOrError(componentClass)
val info = components.get(stateSpec.name) ?: return
(info.component as? PersistentStateComponent<*>)?.let {
initComponent(info, emptySet(), ThreeState.YES)
initComponent(info = info, changedStorages = emptySet(), reloadData = ThreeState.YES)
}
}
@@ -767,7 +787,7 @@ private fun notifyUnknownMacros(store: IComponentStore, project: Project, compon
}
LOG.debug("Reporting unknown path macros $macros in component $componentName")
doNotify(macros, project, Collections.singletonMap(substitutor, store))
doNotify(macros = macros, project = project, substitutorToStore = Collections.singletonMap(substitutor, store))
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.configurationStore
import com.intellij.openapi.components.*
@@ -10,23 +10,15 @@ import org.jetbrains.annotations.TestOnly
@Internal
internal interface ProjectIdManager {
companion object {
fun getInstance(project: Project): ProjectIdManager = project.service()
}
var id: @NonNls String?
}
@State(
name = "ProjectId",
storages = [(Storage(StoragePathMacros.WORKSPACE_FILE))],
reportStatistic = false,
)
private class ProjectIdManagerImpl : SimplePersistentStateComponent<ProjectIdManagerImpl.State>(State()),
ProjectIdManager {
@State(name = "ProjectId", storages = [(Storage(StoragePathMacros.WORKSPACE_FILE))], reportStatistic = false)
private class ProjectIdManagerImpl : SimplePersistentStateComponent<ProjectIdManagerImpl.State>(State()), ProjectIdManager {
override var id: @NonNls String?
get() = state.id
set(value) {
@@ -41,6 +33,5 @@ private class ProjectIdManagerImpl : SimplePersistentStateComponent<ProjectIdMan
@TestOnly
private class MockProjectIdManager : ProjectIdManager {
override var id: String? = null
}

View File

@@ -20,8 +20,19 @@ abstract class StateStorageBase<T : Any> : StateStorage {
abstract val controller: SettingsController?
final override fun <T : Any> getState(component: Any?, componentName: String, stateClass: Class<T>, mergeInto: T?, reload: Boolean): T? {
val stateElement = getSerializedState(getStorageData(reload), component, componentName, archive = false)
return deserializeStateWithController(stateElement, stateClass, mergeInto, controller, componentName)
val stateElement = getSerializedState(
storageData = getStorageData(reload = reload),
component = component,
componentName = componentName,
archive = false,
)
return deserializeStateWithController(
stateElement = stateElement,
stateClass = stateClass,
mergeInto = mergeInto,
controller = controller,
componentName = componentName,
)
}
@ApiStatus.Internal

View File

@@ -250,7 +250,12 @@ private class StateGetterImpl<S : Any, T : Any>(
override fun getState(mergeInto: S?): S? {
LOG.assertTrue(serializedState == null)
serializedState = storage.getSerializedState(storageData, component, componentName, archive = false)
serializedState = storage.getSerializedState(
storageData = storageData,
component = component,
componentName = componentName,
archive = false,
)
return deserializeStateWithController(
stateElement = serializedState,
stateClass = stateClass,

View File

@@ -13,16 +13,19 @@ import org.jetbrains.annotations.CalledInAny
internal const val VERSION_OPTION: String = "version"
@JvmField
internal val XML_PROLOG: ByteArray = """<?xml version="1.0" encoding="UTF-8"?>""".toByteArray()
internal fun isSpecialStorage(collapsedPath: String): Boolean =
collapsedPath == StoragePathMacros.CACHE_FILE || collapsedPath == StoragePathMacros.PRODUCT_WORKSPACE_FILE
internal fun isSpecialStorage(collapsedPath: String): Boolean {
return collapsedPath == StoragePathMacros.CACHE_FILE || collapsedPath == StoragePathMacros.PRODUCT_WORKSPACE_FILE
}
@CalledInAny
internal suspend fun ensureFilesWritable(project: Project, files: Collection<VirtualFile>): ReadonlyStatusHandler.OperationStatus =
withContext(Dispatchers.EDT) {
internal suspend fun ensureFilesWritable(project: Project, files: Collection<VirtualFile>): ReadonlyStatusHandler.OperationStatus {
return withContext(Dispatchers.EDT) {
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files)
}
}
internal val useBackgroundSave: Boolean
get() = Registry.`is`("ide.background.save.settings", false)

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.components
import com.intellij.configurationStore.SaveSessionProducer
@@ -24,8 +24,9 @@ interface StateStorage {
*/
fun analyzeExternalChangesAndUpdateIfNeeded(componentNames: MutableSet<in String>)
fun getResolution(component: PersistentStateComponent<*>, operation: StateStorageOperation): StateStorageChooserEx.Resolution =
StateStorageChooserEx.Resolution.DO
fun getResolution(component: PersistentStateComponent<*>, operation: StateStorageOperation): StateStorageChooserEx.Resolution {
return StateStorageChooserEx.Resolution.DO
}
}
interface StateStorageChooserEx {