From 210595fa4476a34c26a5987b16070f7eee4f7b69 Mon Sep 17 00:00:00 2001 From: "Rustam.Vishnyakov" Date: Wed, 22 Dec 2010 19:13:03 +0300 Subject: [PATCH] Separate methods of indexable set contributor to test-cacheable (project-independent) and non-cacheable (project) sets of files [r=peter] --- .../ScriptingIndexableSetContributor.java | 15 ++++++------- .../util/indexing/FileBasedIndex.java | 7 +++++- .../indexing/IndexableSetContributor.java | 22 ++++++++++++++----- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/scripting/ScriptingIndexableSetContributor.java b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/scripting/ScriptingIndexableSetContributor.java index 7b1524ae6b78..9fb1b06b21ba 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/libraries/scripting/ScriptingIndexableSetContributor.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/libraries/scripting/ScriptingIndexableSetContributor.java @@ -25,6 +25,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.indexing.IndexableSetContributor; import gnu.trove.THashSet; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -34,15 +35,13 @@ import java.util.Set; */ public abstract class ScriptingIndexableSetContributor extends IndexableSetContributor { + @NotNull @Override - public Set getAdditionalRootsToIndex(@Nullable Project project) { - final Set predefinedFiles = getPredefinedFilesToIndex(); - final THashSet filesToIndex = new THashSet(); - filesToIndex.addAll(predefinedFiles); - filesToIndex.addAll(getLibraryFiles(project)); - return filesToIndex; + public Set getAdditionalProjectRootsToIndex(@Nullable Project project) { + return getLibraryFiles(project); } + @NotNull public Set getLibraryFiles(Project project) { final THashSet libFiles = new THashSet(); LibraryType libType = getLibraryType(); @@ -67,8 +66,8 @@ public abstract class ScriptingIndexableSetContributor extends IndexableSetContr } @Override - public Set getAdditionalRootsToIndex() { - return getAdditionalRootsToIndex(null); + public final Set getAdditionalRootsToIndex() { + return getPredefinedFilesToIndex(); } public abstract Set getPredefinedFilesToIndex(); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index 6b92e08c50ef..1e5663babfa3 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -1912,7 +1912,12 @@ public class FileBasedIndex implements ApplicationComponent { if (project.isDisposed()) { return; } - for (VirtualFile root : IndexableSetContributor.getRootsToIndex(provider, project)) { + for (VirtualFile root : IndexableSetContributor.getRootsToIndex(provider)) { + if (visitedRoots.add(root)) { + iterateRecursively(root, processor, indicator); + } + } + for (VirtualFile root : IndexableSetContributor.getProjectRootsToIndex(provider, project)) { if (visitedRoots.add(root)) { iterateRecursively(root, processor, indicator); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java b/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java index f61b47b52b03..ad053ee92d34 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/IndexableSetContributor.java @@ -5,9 +5,11 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.NotNullFunction; import com.intellij.util.containers.ContainerUtil; +import org.apache.commons.collections.SetUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -15,6 +17,9 @@ import java.util.Set; * @author peter */ public abstract class IndexableSetContributor implements IndexedRootsProvider { + + protected static final Set EMPTY_FILE_SET = Collections.unmodifiableSet(new HashSet()); + @Override public final Set getRootsToIndex() { return ContainerUtil.map2Set(getAdditionalRootsToIndex(), new NotNullFunction() { @@ -26,13 +31,17 @@ public abstract class IndexableSetContributor implements IndexedRootsProvider { }); } - public static Set getRootsToIndex(IndexedRootsProvider provider) { - return getRootsToIndex(provider, null); + @NotNull + public static Set getProjectRootsToIndex(IndexedRootsProvider provider, Project project) { + if (provider instanceof IndexableSetContributor) { + return ((IndexableSetContributor)provider).getAdditionalProjectRootsToIndex(project); + } + return EMPTY_FILE_SET; } - public static Set getRootsToIndex(IndexedRootsProvider provider, @Nullable Project project) { + public static Set getRootsToIndex(IndexedRootsProvider provider) { if (provider instanceof IndexableSetContributor) { - return ((IndexableSetContributor)provider).getAdditionalRootsToIndex(project); + return ((IndexableSetContributor)provider).getAdditionalRootsToIndex(); } final HashSet result = new HashSet(); @@ -43,8 +52,9 @@ public abstract class IndexableSetContributor implements IndexedRootsProvider { return result; } - public Set getAdditionalRootsToIndex(@Nullable Project project) { - return getAdditionalRootsToIndex(); + @NotNull + public Set getAdditionalProjectRootsToIndex(@Nullable Project project) { + return EMPTY_FILE_SET; } public abstract Set getAdditionalRootsToIndex();