diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt index 8f5ea46b079e..5c43675221fe 100644 --- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt @@ -24,6 +24,7 @@ import com.intellij.openapi.application.invokeAndWaitIfNeed import com.intellij.openapi.application.runReadAction import com.intellij.openapi.components.* import com.intellij.openapi.components.StateStorage.SaveSession +import com.intellij.openapi.components.impl.ServiceManagerImpl import com.intellij.openapi.components.impl.stores.IComponentStore import com.intellij.openapi.components.impl.stores.IProjectStore import com.intellij.openapi.components.impl.stores.StoreUtil @@ -460,25 +461,34 @@ fun removeWorkspaceComponentConfiguration(defaultProject: Project, element: Elem @Suppress("DEPRECATION") val projectComponents = defaultProject.getComponents(PersistentStateComponent::class.java) projectComponents.forEachGuaranteed { - val stateAnnotation = StoreUtil.getStateSpec(it.javaClass) - if (stateAnnotation == null || stateAnnotation.name.isNullOrEmpty()) { - return@forEachGuaranteed + getNameIfWorkspaceStorage(it.javaClass)?.let { + workspaceComponentNames.add(it) } + } - val storage = stateAnnotation.storages.sortByDeprecated().firstOrNull() ?: return@forEachGuaranteed - if (storage.path != StoragePathMacros.WORKSPACE_FILE) { - return@forEachGuaranteed + ServiceManagerImpl.processAllImplementationClasses(defaultProject as ProjectImpl) { aClass, pluginDescriptor -> + getNameIfWorkspaceStorage(aClass)?.let { + workspaceComponentNames.add(it) } - - workspaceComponentNames.add(stateAnnotation.name) + true } val iterator = componentElements.iterator() for (componentElement in iterator) { - val name = componentElement.getAttributeValue("name") - if (name != null && workspaceComponentNames.contains(name)) { + val name = componentElement.getAttributeValue("name") ?: continue + if (workspaceComponentNames.contains(name)) { iterator.remove() } } return +} + +private fun getNameIfWorkspaceStorage(aClass: Class<*>): String? { + val stateAnnotation = StoreUtil.getStateSpec(aClass) + if (stateAnnotation == null || stateAnnotation.name.isNullOrEmpty()) { + return null + } + + val storage = stateAnnotation.storages.sortByDeprecated().firstOrNull() ?: return null + return if (storage.path == StoragePathMacros.WORKSPACE_FILE) stateAnnotation.name else null } \ No newline at end of file diff --git a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt index 69e9fb96cb2e..6ea2f8a8604f 100644 --- a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt +++ b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt @@ -220,14 +220,7 @@ open class StateStorageManagerImpl(private val rootTagName: String, return constructor.newInstance(componentManager!!, this) as StateStorage } - val effectiveRoamingType: RoamingType - if (roamingType != RoamingType.DISABLED && (collapsedPath == StoragePathMacros.WORKSPACE_FILE || collapsedPath == "other.xml")) { - effectiveRoamingType = RoamingType.DISABLED - } - else { - effectiveRoamingType = roamingType - } - + val effectiveRoamingType = getEffectiveRoamingType(roamingType, collapsedPath) if (isUseVfsListener == ThreeState.UNSURE) { isUseVfsListener = ThreeState.fromBoolean(streamProvider == null || !streamProvider!!.isApplicable(collapsedPath, effectiveRoamingType)) } @@ -451,4 +444,14 @@ fun removeMacroIfStartsWith(path: String, macro: String) = if (path.startsWithMa @Suppress("DEPRECATION") internal val Storage.path: String - get() = if (value.isNullOrEmpty()) file else value \ No newline at end of file + get() = if (value.isNullOrEmpty()) file else value + + +private fun getEffectiveRoamingType(roamingType: RoamingType, collapsedPath: String): RoamingType { + if (roamingType != RoamingType.DISABLED && (collapsedPath == StoragePathMacros.WORKSPACE_FILE || collapsedPath == "other.xml")) { + return RoamingType.DISABLED + } + else { + return roamingType + } +} \ No newline at end of file