From 9c87cfcddc2a4639cd06d207e976febb27505aca Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 24 Oct 2013 16:21:05 +0200 Subject: [PATCH] RootIndex: support libs inside modules and vice versa --- .../openapi/roots/impl/RootIndex.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) 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 1047e66215d6..17c36841e5c6 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 @@ -172,6 +172,45 @@ class RootIndex { for (Map.Entry> mapEntry : libSourceRootEntries.entrySet()) { fillMapWithOrderEntries(mapEntry.getKey(), mapEntry.getValue(), null, null, mapEntry.getKey()); } + + mergeWithParentInfos(); + } + + private void mergeWithParentInfos() { + for (Map.Entry entry : myRoots.entrySet()) { + DirectoryInfo info = entry.getValue(); + Module module = info.getModule(); + VirtualFile libraryClassRoot = info.getLibraryClassRoot(); + boolean inModuleSource = info.isInModuleSource(); + boolean inLibrarySource = info.isInLibrarySource(); + + boolean nested = false; + + VirtualFile eachFile = entry.getKey().getParent(); + while (eachFile != null) { + DirectoryInfo eachInfo = myRoots.get(eachFile); + if (eachInfo != null) { + nested = true; + if (module == null) { + module = eachInfo.getModule(); + } + if (libraryClassRoot == null) { + libraryClassRoot = eachInfo.getLibraryClassRoot(); + } + inModuleSource |= eachInfo.isInModuleSource(); + inLibrarySource |= eachInfo.isInLibrarySource(); + } + if (isAnyExcludeRoot(eachFile)) { + break; + } + + eachFile = eachFile.getParent(); + } + if (nested) { + int sourceRootTypeData = DirectoryInfo.createSourceRootTypeData(inModuleSource, inLibrarySource, info.getSourceRootTypeId()); + entry.setValue(info.with(module, info.getContentRoot(), info.getSourceRoot(), libraryClassRoot, sourceRootTypeData, info.getOrderEntries())); + } + } } public void checkConsistency() { @@ -268,7 +307,7 @@ class RootIndex { if (info != null) { return info; } - if (myProjectExcludedRoots.contains(root) || myLibraryExcludedRoots.contains(root)) { + if (isAnyExcludeRoot(root)) { return null; } } @@ -276,6 +315,10 @@ class RootIndex { return null; } + private boolean isAnyExcludeRoot(VirtualFile root) { + return myProjectExcludedRoots.contains(root) || myLibraryExcludedRoots.contains(root); + } + public boolean isProjectExcludeRoot(@NotNull final VirtualFile dir) { return myProjectExcludedRoots.contains(dir); }