From 24bf640322a9bc230bc3e4df21730bdfe3d7c9e2 Mon Sep 17 00:00:00 2001 From: "Andrei.Kuznetsov" Date: Thu, 26 Sep 2024 15:50:11 +0200 Subject: [PATCH] IJPL-157852,IJPL-16008: Refactoring: extract methods (JpsFileContentWriter) GitOrigin-RevId: 4f8a1418a8c186be3f68af48bb97662250c5a53c --- .../src/ProjectStoreBridge.kt | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/platform/configuration-store-impl/src/ProjectStoreBridge.kt b/platform/configuration-store-impl/src/ProjectStoreBridge.kt index 2a9dbda6af16..ff687691cbcb 100644 --- a/platform/configuration-store-impl/src/ProjectStoreBridge.kt +++ b/platform/configuration-store-impl/src/ProjectStoreBridge.kt @@ -17,6 +17,7 @@ import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.project.Project import com.intellij.openapi.project.getExternalConfigurationDir import com.intellij.openapi.util.JDOMUtil +import com.intellij.openapi.util.NlsSafe import com.intellij.openapi.util.Pair import com.intellij.openapi.util.SystemInfoRt import com.intellij.openapi.util.io.FileUtil @@ -89,24 +90,36 @@ private class JpsStorageContentWriter( override fun saveComponent(fileUrl: String, componentName: String, componentTag: Element?) { val filePath = JpsPathUtil.urlToPath(fileUrl) if (FileUtilRt.extensionEquals(filePath, "iml")) { - session.setModuleComponentState(imlFilePath = filePath, componentName = componentName, componentTag = componentTag) + saveInternalFileModuleComponent(filePath, componentName, componentTag) } else if (isExternalModuleFile(filePath)) { - session.setExternalModuleComponentState( - moduleFileName = FileUtilRt.getNameWithoutExtension(PathUtilRt.getFileName(filePath)), - componentName = componentName, - componentTag = componentTag, - ) + saveExternalFileModuleComponent(filePath, componentName, componentTag) } else { - 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()) - } - else { - producer?.setState(component = null, componentName = componentName, pluginId = PluginManagerCore.CORE_ID, state = componentTag) - } + saveNonModuleComponent(filePath, componentName, componentTag) + } + } + + private fun saveInternalFileModuleComponent(filePath: @NlsSafe String, componentName: String, componentTag: Element?) { + session.setModuleComponentState(imlFilePath = filePath, componentName = componentName, componentTag = componentTag) + } + + private fun saveExternalFileModuleComponent(filePath: @NlsSafe String, componentName: String, componentTag: Element?) { + session.setExternalModuleComponentState( + moduleFileName = FileUtilRt.getNameWithoutExtension(PathUtilRt.getFileName(filePath)), + componentName = componentName, + componentTag = componentTag, + ) + } + + private fun saveNonModuleComponent(filePath: @NlsSafe String, componentName: String, componentTag: Element?) { + 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()) + } + else { + producer?.setState(component = null, componentName = componentName, pluginId = PluginManagerCore.CORE_ID, state = componentTag) } }