From 64bae740b03ae6a53da1f0b1418e22c1c5a08a03 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 20 Mar 2017 16:28:35 +0100 Subject: [PATCH 1/3] Cleanup (formatting) --- .../src/com/intellij/openapi/module/impl/moduleFileListener.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 891104f97ff1..3e7a2f2f047a 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 @@ -35,7 +35,8 @@ import gnu.trove.THashSet * Why this class is required if we have StorageVirtualFileTracker? * Because StorageVirtualFileTracker doesn't detect (intentionally) parent file changes — * - * If module file is foo/bar/hello.iml and directory foo is renamed to oof then we must update module path. And StorageVirtualFileTracker doesn't help us here (and is not going to help by intention). + * If module file is foo/bar/hello.iml and directory foo is renamed to oof then we must update module path. + * And StorageVirtualFileTracker doesn't help us here (and is not going to help by intention). */ internal class ModuleFileListener(private val moduleManager: ModuleManagerComponent) : BulkFileListener { override fun after(events: List) { From 4605b230a388d756f920ec82ee8af2e136e4033a Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 20 Mar 2017 16:40:51 +0100 Subject: [PATCH 2/3] Cleanup (simpler code; needlessly exposed method) --- .../openapi/module/impl/moduleFileListener.kt | 19 +++++++------------ .../impl/ProjectRootManagerComponent.java | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) 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); From 32b0e7c2793f0b99cc0ad9aaef4ae3fa5a1ea5ee Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 20 Mar 2017 16:45:43 +0100 Subject: [PATCH 3/3] Cleanup (duplicate) --- .../roots/impl/ProjectRootManagerComponent.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) 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 c0a148e3229e..8e3d6d9a4d42 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 @@ -176,7 +176,7 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen if (roots == null) return false; for (VirtualFilePointer pointer : pointers) { - final String path = url2path(pointer.getUrl()); + String path = extractLocalPath(pointer.getUrl()); if (roots.first.contains(path) || roots.second.contains(path)) return true; } @@ -209,14 +209,6 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen } } - private static String url2path(String url) { - String path = VfsUtilCore.urlToPath(url); - - int separatorIndex = path.indexOf(JarFileSystem.JAR_SEPARATOR); - if (separatorIndex < 0) return path; - return path.substring(0, separatorIndex); - } - @Nullable private Pair, Set> getAllRoots(boolean includeSourceRoots) { if (myProject.isDefault()) return null;