IJPL-148837 cleanup

GitOrigin-RevId: 5f67c4c65927d4924b93191377e9b092cb39e8ee
This commit is contained in:
Vladimir Krivosheev
2024-05-17 08:18:43 +02:00
committed by intellij-monorepo-bot
parent 8d811792ce
commit 0904aef625
6 changed files with 83 additions and 135 deletions

View File

@@ -465,8 +465,7 @@ abstract class ComponentStoreImpl : IComponentStore {
private fun registerComponent(name: String, info: ComponentInfo): ComponentInfo {
val existing = components.putIfAbsent(name, info)
if (existing != null && existing.component !== info.component) {
LOG.error("Conflicting component name '$name': ${existing.component.javaClass} and ${info.component.javaClass} " +
"(componentManager=${storageManager.componentManager})")
LOG.error("Conflicting component name '$name': ${existing.component.javaClass} and ${info.component.javaClass} (componentManager=${storageManager.componentManager})")
return existing
}
else {
@@ -478,9 +477,7 @@ abstract class ComponentStoreImpl : IComponentStore {
@Suppress("UNCHECKED_CAST")
val component = info.component as PersistentStateComponent<Any>
if (info.stateSpec == null) {
val configurationSchemaKey = info.configurationSchemaKey
?: throw UnsupportedOperationException(
"configurationSchemaKey must be specified for ${component.javaClass.name}")
val configurationSchemaKey = info.configurationSchemaKey ?: throw UnsupportedOperationException("configurationSchemaKey must be specified for ${component.javaClass.name}")
return initComponentWithoutStateSpec(component = component, configurationSchemaKey = configurationSchemaKey, pluginId = info.pluginId)
}
else {

View File

@@ -9,7 +9,7 @@ import com.intellij.openapi.project.impl.UnableToSaveProjectNotification
import com.intellij.openapi.vfs.VirtualFile
internal open class ProjectSaveSessionProducerManager(@JvmField protected val project: Project, isUseVfsForWrite: Boolean)
: SaveSessionProducerManager(isUseVfsForWrite, collectVfsEvents = true)
: SaveSessionProducerManager(isUseVfsForWrite = isUseVfsForWrite, collectVfsEvents = true)
{
suspend fun saveAndValidate(saveSessions: Collection<SaveSession>, saveResult: SaveResult) {
saveSessions(saveSessions, saveResult)
@@ -56,8 +56,9 @@ internal open class ProjectSaveSessionProducerManager(@JvmField protected val pr
}
}
private fun getUnableToSaveNotifications(): Array<out UnableToSaveProjectNotification> =
serviceIfCreated<NotificationsManager>()?.getNotificationsOfType(UnableToSaveProjectNotification::class.java, project) ?: emptyArray()
private fun getUnableToSaveNotifications(): Array<out UnableToSaveProjectNotification> {
return serviceIfCreated<NotificationsManager>()?.getNotificationsOfType(UnableToSaveProjectNotification::class.java, project) ?: emptyArray()
}
private fun getFileList(readonlyFiles: List<SaveSessionAndFile>): List<VirtualFile> = readonlyFiles.map { it.file }
}

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("ReplacePutWithAssignment")
@file:Suppress("ReplacePutWithAssignment", "ReplaceGetOrSet")
package com.intellij.configurationStore
@@ -58,10 +58,10 @@ open class ProjectWithModuleStoreImpl(project: Project) : ProjectStoreImpl(proje
projectSessionManager as ProjectWithModulesSaveSessionProducerManager
val writer = JpsStorageContentWriter(session = projectSessionManager, store = this, project = project)
JpsProjectModelSynchronizer.getInstance(project).saveChangedProjectEntities(writer)
project.serviceAsync<JpsProjectModelSynchronizer>().saveChangedProjectEntities(writer)
for (module in ModuleManager.getInstance(project).modules) {
val moduleStore = module.getService(IComponentStore::class.java) as? ComponentStoreImpl ?: continue
for (module in project.serviceAsync<ModuleManager>().modules) {
val moduleStore = module.serviceAsync<IComponentStore>() as? ComponentStoreImpl ?: continue
val moduleSessionManager = moduleStore.createSaveSessionProducerManager()
moduleStore.commitComponents(isForce = forceSavingAllSettings, sessionManager = moduleSessionManager, saveResult = saveResult)
projectSessionManager.commitComponents(moduleStore = moduleStore, moduleSaveSessionManager = moduleSessionManager)
@@ -74,7 +74,7 @@ open class ProjectWithModuleStoreImpl(project: Project) : ProjectStoreImpl(proje
}
override fun createContentReader(): JpsFileContentReaderWithCache {
return StorageJpsConfigurationReader(project, getJpsProjectConfigLocation(project)!!)
return StorageJpsConfigurationReader(project = project, configLocation = getJpsProjectConfigLocation(project)!!)
}
}
@@ -99,11 +99,7 @@ private class JpsStorageContentWriter(
val stateStorage = getProjectStateStorage(filePath = filePath, store = store, project = project)
val producer = session.getProducer(stateStorage)
if (producer is DirectoryBasedSaveSessionProducer) {
producer.setFileState(
fileName = PathUtilRt.getFileName(filePath),
componentName = componentName,
element = componentTag?.children?.first(),
)
producer.setFileState(fileName = PathUtilRt.getFileName(filePath), componentName = componentName, element = componentTag?.children?.first())
}
else {
producer?.setState(component = null, componentName = componentName, pluginId = PluginManagerCore.CORE_ID, state = componentTag)
@@ -113,11 +109,11 @@ private class JpsStorageContentWriter(
override fun getReplacePathMacroMap(fileUrl: String): PathMacroMap {
val filePath = JpsPathUtil.urlToPath(fileUrl)
return if (FileUtilRt.extensionEquals(filePath, "iml") || isExternalModuleFile(filePath)) {
ModulePathMacroManager.createInstance(project::getProjectFilePath, Supplier { filePath }).replacePathMap
if (FileUtilRt.extensionEquals(filePath, "iml") || isExternalModuleFile(filePath)) {
return ModulePathMacroManager.createInstance(project::getProjectFilePath, Supplier { filePath }).replacePathMap
}
else {
ProjectPathMacroManager.getInstance(project).replacePathMap
return ProjectPathMacroManager.getInstance(project).replacePathMap
}
}
}
@@ -163,7 +159,7 @@ private class ProjectWithModulesSaveSessionProducerManager(project: Project, isU
}
val moduleFilePath = moduleStore.storageManager.expandMacro(StoragePathMacros.MODULE_FILE)
val internalComponents = internalModuleComponents[moduleFilePath.invariantSeparatorsPathString]
val internalComponents = internalModuleComponents.get(moduleFilePath.invariantSeparatorsPathString)
if (internalComponents != null) {
commitToStorage(MODULE_FILE_STORAGE_ANNOTATION, internalComponents)
}
@@ -178,8 +174,7 @@ private class ProjectWithModulesSaveSessionProducerManager(project: Project, isU
}
}
internal class StorageJpsConfigurationReader(private val project: Project,
private val configLocation: JpsProjectConfigLocation) : JpsFileContentReaderWithCache {
internal class StorageJpsConfigurationReader(private val project: Project, private val configLocation: JpsProjectConfigLocation) : JpsFileContentReaderWithCache {
@Volatile
private var fileContentCachingReader: CachingJpsFileContentReader? = null
private val externalConfigurationDir = lazy { project.getExternalConfigurationDir() }
@@ -266,9 +261,7 @@ internal class StorageJpsConfigurationReader(private val project: Project,
}
}
fun getProjectStateStorage(filePath: String,
store: IProjectStore,
project: Project): StateStorageBase<StateMap> {
fun getProjectStateStorage(filePath: String, store: IProjectStore, project: Project): StateStorageBase<StateMap> {
val storageSpec = getStorageSpec(filePath, project)
@Suppress("UNCHECKED_CAST")
return store.storageManager.getStateStorage(storageSpec) as StateStorageBase<StateMap>
@@ -314,7 +307,7 @@ private fun getStorageSpec(filePath: String, project: Project): Storage {
}
}
}
return FileStorageAnnotation(collapsedPath, false, splitterClass)
return FileStorageAnnotation(/* path = */ collapsedPath, /* deprecated = */ false, /* splitterClass = */ splitterClass)
}
/**

View File

@@ -4,11 +4,7 @@ package com.intellij.configurationStore
import com.intellij.codeWithMe.ClientId
import com.intellij.codeWithMe.asContextElement
import com.intellij.conversion.ConversionService
import com.intellij.ide.GeneralSettings
import com.intellij.ide.IdeBundle
import com.intellij.ide.IdleTracker
import com.intellij.ide.SaveAndSyncHandler
import com.intellij.ide.SaveAndSyncHandlerListener
import com.intellij.ide.*
import com.intellij.openapi.application.*
import com.intellij.openapi.application.impl.LaterInvocator
import com.intellij.openapi.components.ComponentManager
@@ -87,33 +83,33 @@ internal class SaveAndSyncHandlerImpl(private val coroutineScope: CoroutineScope
coroutineScope.launch(CoroutineName("save requests flow processing")) {
// not collectLatest - wait for previous execution
saveRequests
.collect {
val forceExecuteImmediately = forceExecuteImmediatelyState.compareAndSet(true, false)
if (!forceExecuteImmediately) {
delay(300.milliseconds)
}
saveRequests.collect {
val forceExecuteImmediately = forceExecuteImmediatelyState.compareAndSet(true, false)
if (!forceExecuteImmediately) {
delay(300.milliseconds)
}
if (blockSaveOnFrameDeactivationCount.get() != 0) {
return@collect
}
if (blockSaveOnFrameDeactivationCount.get() != 0) {
return@collect
}
val job = currentJob.updateAndGet { oldJob ->
oldJob?.cancel()
launch(start = CoroutineStart.LAZY) {
processTasks(forceExecuteImmediately)
}
}!!
try {
if (job.start()) {
job.join()
}
val job = currentJob.updateAndGet { oldJob ->
oldJob?.cancel()
launch(start = CoroutineStart.LAZY) {
processTasks(forceExecuteImmediately)
}
catch (_: CancellationException) { }
finally {
currentJob.compareAndSet(job, null)
}!!
try {
if (job.start()) {
job.join()
}
}
catch (_: CancellationException) {
}
finally {
currentJob.compareAndSet(job, null)
}
}
}
coroutineScope.launch {

View File

@@ -43,51 +43,51 @@ internal open class SaveSessionProducerManager(private val isUseVfsForWrite: Boo
if (isUseVfsForWrite) {
writeAction {
for (saveSession in saveSessions) {
executeSaveBlocking(saveSession, saveResult)
try {
saveSession.saveBlocking()
}
catch (e: ReadOnlyModificationException) {
LOG.warn(e)
saveResult.addReadOnlyFile(SaveSessionAndFile(e.session ?: saveSession, e.file))
}
catch (e: ProcessCanceledException) {
throw e
}
catch (e: CancellationException) {
throw e
}
catch (e: Exception) {
saveResult.addError(e)
}
}
}
}
else {
val events = if (collectVfsEvents) ArrayList<VFileEvent>() else null
val syncList = if (events != null) Collections.synchronizedList(events) else null
val syncList = if (events == null) null else Collections.synchronizedList(events)
for (saveSession in saveSessions) {
executeSave(saveSession, saveResult, syncList)
try {
saveSession.save(syncList)
}
catch (e: ReadOnlyModificationException) {
LOG.warn(e)
saveResult.addReadOnlyFile(SaveSessionAndFile(e.session ?: saveSession, e.file))
}
catch (e: ProcessCanceledException) {
throw e
}
catch (e: CancellationException) {
throw e
}
catch (e: Exception) {
saveResult.addError(e)
}
}
if (events != null && events.isNotEmpty()) {
if (!events.isNullOrEmpty()) {
blockingContext {
RefreshQueue.getInstance().processEvents(false, events)
}
}
}
}
private suspend fun executeSave(session: SaveSession, result: SaveResult, events: MutableList<VFileEvent>?) {
try {
session.save(events)
}
catch (e: ReadOnlyModificationException) {
LOG.warn(e)
result.addReadOnlyFile(SaveSessionAndFile(e.session ?: session, e.file))
}
catch (e: ProcessCanceledException) { throw e }
catch (e: CancellationException) { throw e }
catch (e: Exception) {
result.addError(e)
}
}
private fun executeSaveBlocking(session: SaveSession, result: SaveResult) {
try {
session.saveBlocking()
}
catch (e: ReadOnlyModificationException) {
LOG.warn(e)
result.addReadOnlyFile(SaveSessionAndFile(e.session ?: session, e.file))
}
catch (e: ProcessCanceledException) { throw e }
catch (e: CancellationException) { throw e }
catch (e: Exception) {
result.addError(e)
}
}
}

View File

@@ -29,32 +29,14 @@ internal class StateStorageBackedByController(
@JvmField val controller: SettingsControllerMediator,
private val tags: List<SettingTag>,
) : StateStorage {
override fun <T : Any> getState(
component: Any?,
componentName: String,
pluginId: PluginId,
stateClass: Class<T>,
mergeInto: T?,
reload: Boolean,
): T? {
override fun <T : Any> getState(component: Any?, componentName: String, pluginId: PluginId, stateClass: Class<T>, mergeInto: T?, reload: Boolean): T? {
@Suppress("DEPRECATION", "UNCHECKED_CAST")
when {
stateClass === Element::class.java -> {
return deserializeAsJdomElement(
localValue = null,
controller = controller,
componentName = componentName,
pluginId = pluginId,
tags = tags,
) as T?
return deserializeAsJdomElement(localValue = null, controller = controller, componentName = componentName, pluginId = pluginId, tags = tags) as T?
}
com.intellij.openapi.util.JDOMExternalizable::class.java.isAssignableFrom(stateClass) -> {
return readDataForDeprecatedJdomExternalizable(
componentName = componentName,
mergeInto = mergeInto,
stateClass = stateClass,
pluginId = pluginId,
)
return readDataForDeprecatedJdomExternalizable(componentName = componentName, mergeInto = mergeInto, stateClass = stateClass, pluginId = pluginId)
}
else -> {
try {
@@ -64,12 +46,7 @@ internal class StateStorageBackedByController(
return rootBinding.fromJson(currentValue = null, element = data) as T
}
else {
return getXmlSerializationState(
mergeInto = mergeInto,
beanBinding = rootBinding,
componentName = componentName,
pluginId = pluginId,
)
return getXmlSerializationState(mergeInto = mergeInto, beanBinding = rootBinding, componentName = componentName, pluginId = pluginId)
}
}
catch (e: SerializationException) {
@@ -82,19 +59,8 @@ internal class StateStorageBackedByController(
}
}
private fun <T : Any> readDataForDeprecatedJdomExternalizable(
componentName: String,
pluginId: PluginId,
mergeInto: T?,
stateClass: Class<T>,
): T? {
val data = deserializeAsJdomElement(
localValue = null,
controller = controller,
componentName = componentName,
pluginId = pluginId,
tags = tags,
) ?: return mergeInto
private fun <T : Any> readDataForDeprecatedJdomExternalizable(componentName: String, pluginId: PluginId, mergeInto: T?, stateClass: Class<T>): T? {
val data = deserializeAsJdomElement(localValue = null, controller = controller, componentName = componentName, pluginId = pluginId, tags = tags) ?: return mergeInto
if (mergeInto != null) {
thisLogger().error("State is ${stateClass.name}, merge into is $mergeInto, state element text is $data")
}
@@ -108,12 +74,7 @@ internal class StateStorageBackedByController(
return t as T
}
private fun <T : Any> getXmlSerializationState(
mergeInto: T?,
beanBinding: Binding,
componentName: String,
pluginId: PluginId,
): T? {
private fun <T : Any> getXmlSerializationState(mergeInto: T?, beanBinding: Binding, componentName: String, pluginId: PluginId): T? {
var result = mergeInto
val bindings = (beanBinding as BeanBinding).bindings!!
for (binding in bindings) {