diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/moduleFileListener.kt b/platform/lang-impl/src/com/intellij/openapi/module/impl/moduleFileListener.kt index 3e7a2f2f047a..ca6ed30e430e 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/moduleFileListener.kt +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/moduleFileListener.kt @@ -19,9 +19,9 @@ import com.intellij.openapi.components.StateStorage import com.intellij.openapi.components.stateStore import com.intellij.openapi.module.Module import com.intellij.openapi.roots.impl.ModuleRootManagerImpl -import com.intellij.openapi.roots.impl.ProjectRootManagerComponent import com.intellij.openapi.roots.impl.storage.ClasspathStorage import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.newvfs.BulkFileListener import com.intellij.openapi.vfs.newvfs.events.VFileEvent @@ -53,8 +53,6 @@ internal class ModuleFileListener(private val moduleManager: ModuleManagerCompon return } - val roots = THashSet() - val parentPath = event.file.parent?.path ?: return var someModulePathIsChanged = false val newAncestorPath = "${parentPath}/${event.newValue}" @@ -72,7 +70,7 @@ internal class ModuleFileListener(private val moduleManager: ModuleManagerCompon // if ancestor path is a direct parent of module file - root will be serialized as $MODULE_DIR$ and, so, we don't need to mark it as changed to save if (PathUtilRt.getParentPath(moduleFilePath) != ancestorPath) { - checkRootModification(module, newAncestorPath, roots) + checkRootModification(module, newAncestorPath) } } @@ -86,8 +84,6 @@ internal class ModuleFileListener(private val moduleManager: ModuleManagerCompon return } - val roots = THashSet() - val dirName = event.file.nameSequence val ancestorPath = "${event.oldParent.path}/$dirName" val newAncestorPath = "${event.newParent.path}/$dirName" @@ -101,18 +97,17 @@ internal class ModuleFileListener(private val moduleManager: ModuleManagerCompon setModuleFilePath(module, "${event.newParent.path}/$dirName/${FileUtil.getRelativePath(ancestorPath, moduleFilePath, '/')}") } - checkRootModification(module, newAncestorPath, roots) + checkRootModification(module, newAncestorPath) } } // https://youtrack.jetbrains.com/issue/IDEA-168933 - private fun checkRootModification(module: Module, newAncestorPath: String, roots: THashSet) { - roots.clear() - + private fun checkRootModification(module: Module, newAncestorPath: String) { val moduleRootManager = module.rootManager as? ModuleRootManagerImpl ?: return - ProjectRootManagerComponent.addRootsToTrack(moduleRootManager.contentRootUrls, roots, roots) - ProjectRootManagerComponent.addRootsToTrack(moduleRootManager.sourceRootUrls, roots, roots) + val roots = THashSet() + moduleRootManager.contentRootUrls.forEach { roots.add(VfsUtilCore.urlToPath(it)) } + moduleRootManager.sourceRootUrls.forEach { roots.add(VfsUtilCore.urlToPath(it)) } if (roots.contains(newAncestorPath)) { moduleRootManager.stateChanged() } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java index ae34a462b50d..c0a148e3229e 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java @@ -265,7 +265,7 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen return Pair.create(recursive, flat); } - public static void addRootsToTrack(final String[] urls, final Collection recursive, final Collection flat) { + private static void addRootsToTrack(final String[] urls, final Collection recursive, final Collection flat) { for (String url : urls) { if (url != null) { final String protocol = VirtualFileManager.extractProtocol(url);