From 583d835f4a97c43e08e3129cd20315cffefc503f Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 6 Aug 2021 09:07:44 +0200 Subject: [PATCH] cleanup GitOrigin-RevId: 872122679caae8571c1edf88adb6f7e0a31b7aab --- .../src/ComponentStoreImpl.kt | 12 +++++++----- .../module/impl/NonPersistentModuleStore.kt | 15 ++++++++++++--- .../intellij/openapi/client/ClientSessionImpl.kt | 9 +++++++++ .../components/impl/stores/IComponentStore.kt | 12 ++++-------- .../serviceContainer/ServiceComponentAdapter.kt | 15 +++++++-------- .../serviceContainer/TestComponentManager.kt | 11 ++++++++++- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/platform/configuration-store-impl/src/ComponentStoreImpl.kt b/platform/configuration-store-impl/src/ComponentStoreImpl.kt index e240738fbe32..37fb08108a7f 100644 --- a/platform/configuration-store-impl/src/ComponentStoreImpl.kt +++ b/platform/configuration-store-impl/src/ComponentStoreImpl.kt @@ -1,4 +1,5 @@ // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +@file:Suppress("ReplaceGetOrSet") package com.intellij.configurationStore import com.intellij.configurationStore.statistic.eventLog.FeatureUsageSettingsEvents @@ -20,8 +21,8 @@ import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.JDOMUtil -import com.intellij.openapi.util.* import com.intellij.openapi.util.registry.Registry +import com.intellij.openapi.util.use import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess import com.intellij.util.ArrayUtilRt import com.intellij.util.SmartList @@ -41,6 +42,7 @@ import java.io.IOException import java.util.* import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.TimeUnit +import java.util.function.Consumer internal val LOG = logger() private val SAVE_MOD_LOG = Logger.getInstance("#configurationStore.save.skip") @@ -87,9 +89,9 @@ abstract class ComponentStoreImpl : IComponentStore { internal fun getComponents(): Map = components override fun clearCaches() { - components.values.forEach { + components.values.forEach(Consumer { it.updateModificationCount(-1) - } + }) (storageManager as? StateStorageManagerImpl)?.clearStorages() } @@ -107,8 +109,8 @@ abstract class ComponentStoreImpl : IComponentStore { return } - val info = createComponentInfo(component, stateSpec, serviceDescriptor) - initComponent(info, null, ThreeState.NO) + val info = createComponentInfo(component, null, serviceDescriptor) + initComponent(info = info, changedStorages = null, reloadData = ThreeState.NO) } else { componentName = stateSpec.name diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/NonPersistentModuleStore.kt b/platform/lang-impl/src/com/intellij/openapi/module/impl/NonPersistentModuleStore.kt index e2cc542ed86b..de7d4129e8bf 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/NonPersistentModuleStore.kt +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/NonPersistentModuleStore.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.module.impl import com.intellij.configurationStore.SaveSessionProducer @@ -11,7 +11,6 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.messages.MessageBus import org.jetbrains.annotations.ApiStatus import java.nio.file.Path -import java.nio.file.Paths @ApiStatus.Internal internal class NonPersistentModuleStore : ModuleStore { @@ -19,7 +18,11 @@ internal class NonPersistentModuleStore : ModuleStore { override fun setPath(path: Path): Unit = Unit override fun setPath(path: Path, virtualFile: VirtualFile?, isNew: Boolean) { } + override fun initComponent(component: Any, serviceDescriptor: ServiceDescriptor?, pluginId: PluginId?): Unit = Unit + override fun unloadComponent(component: Any) { + } + override fun initPersistencePlainComponent(component: Any, key: String): Unit = Unit override fun reloadStates(componentNames: Set, messageBus: MessageBus): Unit = Unit override fun reloadState(componentClass: Class>): Unit = Unit @@ -28,6 +31,12 @@ internal class NonPersistentModuleStore : ModuleStore { override fun saveComponent(component: PersistentStateComponent<*>): Unit = Unit override fun removeComponent(name: String) { } + + override fun clearCaches() { + } + + override fun release() { + } } private object NonPersistentStateStorageManager : StateStorageManager { @@ -36,7 +45,7 @@ private object NonPersistentStateStorageManager : StateStorageManager { override fun addStreamProvider(provider: StreamProvider, first: Boolean) = Unit override fun removeStreamProvider(clazz: Class) = Unit override fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation): StateStorage? = null - override fun expandMacro(path: String): Path = Paths.get(path) + override fun expandMacro(collapsedPath: String): Path = Path.of(collapsedPath) } private object NonPersistentStateStorage : StateStorage { diff --git a/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionImpl.kt b/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionImpl.kt index 60ea06e829c3..75d2ba1b75c3 100644 --- a/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/client/ClientSessionImpl.kt @@ -149,6 +149,9 @@ class ClientSessionComponentStore : IComponentStore { } } + override fun unloadComponent(component: Any) { + } + override fun initPersistencePlainComponent(component: Any, key: String) { } @@ -170,6 +173,12 @@ class ClientSessionComponentStore : IComponentStore { override fun removeComponent(name: String) { } + + override fun clearCaches() { + } + + override fun release() { + } } @ApiStatus.Internal diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.kt b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.kt index d5fdabeee546..d2bdc3ea2d17 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.kt +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.components.impl.stores import com.intellij.configurationStore.SaveSession @@ -21,9 +21,7 @@ interface IComponentStore { fun initComponent(component: Any, serviceDescriptor: ServiceDescriptor?, pluginId: PluginId?) - @JvmDefault - fun unloadComponent(component: Any) { - } + fun unloadComponent(component: Any) fun initPersistencePlainComponent(component: Any, @NlsSafe key: String) @@ -42,11 +40,9 @@ interface IComponentStore { fun removeComponent(name: String) @TestOnly - @JvmDefault - fun clearCaches() {} + fun clearCaches() - @JvmDefault - fun release() {} + fun release() } @ApiStatus.Internal diff --git a/platform/service-container/src/com/intellij/serviceContainer/ServiceComponentAdapter.kt b/platform/service-container/src/com/intellij/serviceContainer/ServiceComponentAdapter.kt index 76e823d37e87..d5f1c52ded6e 100644 --- a/platform/service-container/src/com/intellij/serviceContainer/ServiceComponentAdapter.kt +++ b/platform/service-container/src/com/intellij/serviceContainer/ServiceComponentAdapter.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.serviceContainer import com.intellij.openapi.Disposable @@ -32,16 +32,15 @@ internal class ServiceComponentAdapter(val descriptor: ServiceDescriptor, } } - if (indicator == null) { + val progressManager = if (indicator == null) null else ProgressManager.getInstance() + if (progressManager == null || progressManager.isInNonCancelableSection) { return createAndInitialize(componentManager, implementationClass) } - - // don't use here computeInNonCancelableSection - it is kotlin and no need of such awkward and stack-trace unfriendly methods - var instance: T? = null - ProgressManager.getInstance().executeNonCancelableSection { - instance = createAndInitialize(componentManager, implementationClass) + else { + return progressManager.computeInNonCancelableSection { + createAndInitialize(componentManager, implementationClass) + } } - return instance!! } private fun createAndInitialize(componentManager: ComponentManagerImpl, implementationClass: Class): T { diff --git a/platform/service-container/testSrc/com/intellij/serviceContainer/TestComponentManager.kt b/platform/service-container/testSrc/com/intellij/serviceContainer/TestComponentManager.kt index 41a3e61ace4a..40445acfa94d 100644 --- a/platform/service-container/testSrc/com/intellij/serviceContainer/TestComponentManager.kt +++ b/platform/service-container/testSrc/com/intellij/serviceContainer/TestComponentManager.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.serviceContainer import com.intellij.configurationStore.StateStorageManager @@ -36,6 +36,9 @@ private class TestComponentStore : IComponentStore { override fun initComponent(component: Any, serviceDescriptor: ServiceDescriptor?, pluginId: PluginId?) { } + override fun unloadComponent(component: Any) { + } + override fun initPersistencePlainComponent(component: Any, key: String) { } @@ -55,4 +58,10 @@ private class TestComponentStore : IComponentStore { override fun removeComponent(name: String) { } + + override fun clearCaches() { + } + + override fun release() { + } } \ No newline at end of file