From b7f6cd2ee4e851fdb37af1ceb3b7463b46884229 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 25 Oct 2013 22:05:36 +0200 Subject: [PATCH] RootIndex: ensure transitive dependents end up in order entries cache --- .../roots/impl/DirectoryIndexTest.java | 12 +++++++----- .../openapi/roots/impl/RootIndex.java | 19 ++++++++++++------- .../roots/ModuleRootModificationUtil.java | 9 +++++++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java index be0f122398d3..a68fc213e493 100644 --- a/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java +++ b/java/java-tests/testSrc/com/intellij/openapi/roots/impl/DirectoryIndexTest.java @@ -159,7 +159,7 @@ public class DirectoryIndexTest extends IdeaTestCase { PsiTestUtil.addExcludedRoot(myModule2, myExcludeDir); ModuleRootModificationUtil.addModuleLibrary(myModule2, "lib", singletonList(myLibClsDir.getUrl()), singletonList(myLibSrcDir.getUrl()), - Arrays.asList(myExcludedLibClsDir.getUrl(), myExcludedLibSrcDir.getUrl()), DependencyScope.COMPILE); + Arrays.asList(myExcludedLibClsDir.getUrl(), myExcludedLibSrcDir.getUrl()), DependencyScope.COMPILE, true); } // fill roots of module3 @@ -204,8 +204,8 @@ public class DirectoryIndexTest extends IdeaTestCase { checkInfo(myTestResDir, myModule, false, false, "", JavaResourceRootType.TEST_RESOURCE, myModule); checkInfo(myLibDir, myModule, false, false, null, null); - checkInfo(myLibSrcDir, myModule, false, true, "", null, myModule2); - checkInfo(myLibClsDir, myModule, true, false, "", null, myModule2); + checkInfo(myLibSrcDir, myModule, false, true, "", null, myModule2, myModule3); + checkInfo(myLibClsDir, myModule, true, false, "", null, myModule2, myModule3); checkInfo(myModule2Dir, myModule2, false, false, null, null); checkInfo(mySrcDir2, myModule2, false, false, "", JavaSourceRootType.SOURCE, myModule2, myModule3); @@ -503,9 +503,11 @@ public class DirectoryIndexTest extends IdeaTestCase { checkInfo(myModule1Dir, myModule, true, false, "", null, myModule); checkInfo(mySrcDir1, myModule, true, false, "", JavaSourceRootType.SOURCE, myModule); + //todo this looks strange and inconsistent: the same library classes and sources have different order entries checkInfo(myLibDir, myModule, true, false, "lib", null, myModule); - checkInfo(myLibClsDir, myModule, true, false, "", null, myModule2); - checkInfo(myLibSrcDir, myModule, true, true, "", null, myModule); + checkInfo(myLibClsDir, myModule, true, false, "", null, myModule2, myModule3); + checkInfo(myLibSrcDir, myModule, true, true, "", null, myModule, myModule3); + checkInfo(myResDir, myModule, true, false, "", JavaResourceRootType.RESOURCE, myModule); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootIndex.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootIndex.java index e145ad638352..7e8ca1191afd 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootIndex.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/RootIndex.java @@ -117,8 +117,9 @@ class RootIndex { } } else if (orderEntry instanceof ModuleSourceOrderEntry) { - for (VirtualFile sourceRoot : ((ModuleSourceOrderEntry)orderEntry).getRootModel().getSourceRoots()) { - depEntries.putValue(sourceRoot, orderEntry); + final VirtualFile[] sourceRoots = ((ModuleSourceOrderEntry)orderEntry).getRootModel().getSourceRoots(); + for (VirtualFile sourceRoot : sourceRoots) { + fillMapWithOrderEntries(sourceRoot, Arrays.asList(orderEntry), orderEntry.getOwnerModule(), null, null); } } else if (orderEntry instanceof LibraryOrSdkOrderEntry) { @@ -164,13 +165,13 @@ class RootIndex { // fill ordered entries for (Map.Entry> mapEntry : depEntries.entrySet()) { - fillMapWithOrderEntries(mapEntry.getKey(), mapEntry.getValue(), null, null); + fillMapWithOrderEntries(mapEntry.getKey(), mapEntry.getValue(), null, null, null); } for (Map.Entry> mapEntry : libClassRootEntries.entrySet()) { - fillMapWithOrderEntries(mapEntry.getKey(), mapEntry.getValue(), mapEntry.getKey(), null); + fillMapWithOrderEntries(mapEntry.getKey(), mapEntry.getValue(), null, mapEntry.getKey(), null); } for (Map.Entry> mapEntry : libSourceRootEntries.entrySet()) { - fillMapWithOrderEntries(mapEntry.getKey(), mapEntry.getValue(), null, mapEntry.getKey()); + fillMapWithOrderEntries(mapEntry.getKey(), mapEntry.getValue(), null, null, mapEntry.getKey()); } mergeWithParentInfos(); @@ -261,6 +262,7 @@ class RootIndex { private void fillMapWithOrderEntries(final VirtualFile root, @NotNull final Collection orderEntries, + @Nullable final Module module, @Nullable final VirtualFile libraryClassRoot, @Nullable final VirtualFile librarySourceRoot) { @@ -273,7 +275,10 @@ class RootIndex { DirectoryInfo info = myRoots.get(root); if (info == null) return; - if (libraryClassRoot != null) { + if (module != null) { + if (info.getModule() != module) return; + if (!info.isInModuleSource()) return; + } else if (libraryClassRoot != null) { if (info.getLibraryClassRoot() != libraryClassRoot) return; if (info.isInModuleSource()) return; } else if (librarySourceRoot != null) { @@ -285,7 +290,7 @@ class RootIndex { OrderEntry[] orderEntriesArray = orderEntries.toArray(new OrderEntry[orderEntries.size()]); Arrays.sort(orderEntriesArray, DirectoryInfo.BY_OWNER_MODULE); - myRoots.put(root, info.withInternedEntries(orderEntriesArray)); + myRoots.put(root, info.withInternedEntries(info.calcNewOrderEntries(orderEntriesArray, null, info.getOrderEntries()))); } @NotNull diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/ModuleRootModificationUtil.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/ModuleRootModificationUtil.java index ac33bed01964..cadd8915bfb6 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/ModuleRootModificationUtil.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/ModuleRootModificationUtil.java @@ -49,6 +49,14 @@ public class ModuleRootModificationUtil { final List sourceRoots, final List excludedRoots, final DependencyScope scope) { + addModuleLibrary(module, libName, classesRoots, sourceRoots, excludedRoots, scope, false); + } + public static void addModuleLibrary(final Module module, final String libName, + final List classesRoots, + final List sourceRoots, + final List excludedRoots, + final DependencyScope scope, + final boolean exported) { updateModel(module, new Consumer() { @Override public void consume(final ModifiableRootModel model) { @@ -68,6 +76,7 @@ public class ModuleRootModificationUtil { LibraryOrderEntry entry = model.findLibraryOrderEntry(library); assert entry != null : library; entry.setScope(scope); + entry.setExported(exported); doWriteAction(new Runnable() { @Override