IJPL-157852,IJPL-16008: Refactoring: extract methods (JpsFileContentWriter)

GitOrigin-RevId: 4f8a1418a8c186be3f68af48bb97662250c5a53c
This commit is contained in:
Andrei.Kuznetsov
2024-09-27 14:53:42 +00:00
committed by intellij-monorepo-bot
parent 21164d9381
commit 24bf640322
@@ -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)
}
}