extract the scope implementing ProjectScopeBuilder.getProjectScope() to a top-level...
authorDmitry Jemerov <yole@jetbrains.com>
Mon, 3 Oct 2011 19:37:28 +0000 (21:37 +0200)
committerDmitry Jemerov <yole@jetbrains.com>
Tue, 4 Oct 2011 14:05:06 +0000 (16:05 +0200)
platform/core-api/src/com/intellij/openapi/roots/FileIndexFacade.java
platform/core-api/src/com/intellij/psi/search/EverythingGlobalScope.java [moved from platform/lang-api/src/com/intellij/psi/search/EverythingGlobalScope.java with 100% similarity]
platform/core-impl/src/com/intellij/mock/MockFileIndexFacade.java
platform/core-impl/src/com/intellij/psi/search/ProjectScopeImpl.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/openapi/vcs/impl/ProjectFileIndexFacade.java
platform/lang-impl/src/com/intellij/psi/search/ProjectScopeBuilderImpl.java
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/DefaultFileIndexFacade.java

index 598954811b6abe60eda94f40093bf42c329fcf41..d9f052f8b0de3ef27e0c896404abdc72b7ffac5b 100644 (file)
@@ -37,6 +37,7 @@ public abstract class FileIndexFacade {
 
   public abstract boolean isInContent(VirtualFile file);
   public abstract boolean isInSource(VirtualFile file);
+  public abstract boolean isInSourceContent(VirtualFile file);
   public abstract boolean isInLibraryClasses(VirtualFile file);
   public abstract boolean isInLibrarySource(VirtualFile file);
   public abstract boolean isExcludedFile(VirtualFile file);
index 77885bd9c962857a376f165c4519f3bd6f0d7c56..ba7b83d04f590198f3ae01deaa4abd9d671b5ca5 100644 (file)
@@ -43,6 +43,11 @@ public class MockFileIndexFacade extends FileIndexFacade {
   }
 
   @Override
+  public boolean isInSourceContent(VirtualFile file) {
+    return true;
+  }
+
+  @Override
   public boolean isInLibraryClasses(VirtualFile file) {
     return false;
   }
diff --git a/platform/core-impl/src/com/intellij/psi/search/ProjectScopeImpl.java b/platform/core-impl/src/com/intellij/psi/search/ProjectScopeImpl.java
new file mode 100644 (file)
index 0000000..efe17e0
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.psi.search;
+
+import com.intellij.injected.editor.VirtualFileWindow;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.roots.FileIndexFacade;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.psi.PsiBundle;
+import org.jetbrains.annotations.NotNull;
+
+public class ProjectScopeImpl extends GlobalSearchScope {
+  private final FileIndexFacade myFileIndex;
+
+  public ProjectScopeImpl(Project project, FileIndexFacade fileIndex) {
+    super(project);
+    myFileIndex = fileIndex;
+  }
+
+  public boolean contains(VirtualFile file) {
+    if (file instanceof VirtualFileWindow) return true;
+
+    if (myFileIndex.isInLibraryClasses(file) && !myFileIndex.isInSourceContent(file)) return false;
+
+    return myFileIndex.isInContent(file);
+  }
+
+  public int compare(VirtualFile file1, VirtualFile file2) {
+    return 0;
+  }
+
+  public boolean isSearchInModuleContent(@NotNull Module aModule) {
+    return true;
+  }
+
+  public boolean isSearchInLibraries() {
+    return false;
+  }
+
+  public String getDisplayName() {
+    return PsiBundle.message("psi.search.scope.project");
+  }
+
+  public String toString() {
+    return getDisplayName();
+  }
+
+  @Override
+  public GlobalSearchScope uniteWith(@NotNull GlobalSearchScope scope) {
+    if (scope == this || !scope.isSearchInLibraries() || !scope.isSearchOutsideRootModel()) return this;
+    return super.uniteWith(scope);
+  }
+
+  @NotNull
+  @Override
+  public GlobalSearchScope intersectWith(@NotNull GlobalSearchScope scope) {
+    if (scope == this) return this;
+    if (!scope.isSearchInLibraries()) return scope;
+    return super.intersectWith(scope);
+  }
+}
index bef825a4f88e4949e5d0ff237e9102ad3b0683cb..e6b26ee5025b367e507c179d691f4c4dfe43495b 100644 (file)
@@ -47,6 +47,11 @@ public class ProjectFileIndexFacade extends FileIndexFacade {
   }
 
   @Override
+  public boolean isInSourceContent(VirtualFile file) {
+    return myRootManager.getFileIndex().isInSourceContent(file);
+  }
+
+  @Override
   public boolean isInLibraryClasses(VirtualFile file) {
     return myRootManager.getFileIndex().isInLibraryClasses(file);
   }
index 6d4c557e9fc3776b33f7246a2422b9fe56f095fe..54fe964e40fa83919719b815ad9e0beaf1af6d97 100644 (file)
  */
 package com.intellij.psi.search;
 
-import com.intellij.injected.editor.VirtualFileWindow;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ProjectFileIndex;
+import com.intellij.openapi.roots.FileIndexFacade;
 import com.intellij.openapi.roots.ProjectRootManager;
 import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.PsiBundle;
 import org.jetbrains.annotations.NotNull;
 
 /**
@@ -66,51 +64,7 @@ public class ProjectScopeBuilderImpl extends ProjectScopeBuilder {
       };
     }
     else {
-      return new GlobalSearchScope(myProject) {
-        private final ProjectFileIndex myFileIndex = projectRootManager.getFileIndex();
-
-        public boolean contains(VirtualFile file) {
-          if (file instanceof VirtualFileWindow) return true;
-
-          if (myFileIndex.isInLibraryClasses(file) && !myFileIndex.isInSourceContent(file)) return false;
-
-          return myFileIndex.isInContent(file);
-        }
-
-        public int compare(VirtualFile file1, VirtualFile file2) {
-          return 0;
-        }
-
-        public boolean isSearchInModuleContent(@NotNull Module aModule) {
-          return true;
-        }
-
-        public boolean isSearchInLibraries() {
-          return false;
-        }
-
-        public String getDisplayName() {
-          return PsiBundle.message("psi.search.scope.project");
-        }
-
-        public String toString() {
-          return getDisplayName();
-        }
-
-        @Override
-        public GlobalSearchScope uniteWith(@NotNull GlobalSearchScope scope) {
-          if (scope == this || !scope.isSearchInLibraries() || !scope.isSearchOutsideRootModel()) return this;
-          return super.uniteWith(scope);
-        }
-
-        @NotNull
-        @Override
-        public GlobalSearchScope intersectWith(@NotNull GlobalSearchScope scope) {
-          if (scope == this) return this;
-          if (!scope.isSearchInLibraries()) return scope;
-          return super.intersectWith(scope);
-        }
-      };
+      return new ProjectScopeImpl(myProject, FileIndexFacade.getInstance(myProject));
     }
   }
 }
index e5b40d5e0cf2281298cd83dafe99eda6bc420ae2..8e6bd1d2453e57ca46649816bba8c0c96bda9087 100644 (file)
@@ -45,6 +45,11 @@ public class DefaultFileIndexFacade extends FileIndexFacade {
   }
 
   @Override
+  public boolean isInSourceContent(VirtualFile file) {
+    return isInContent(file);
+  }
+
+  @Override
   public boolean isInLibraryClasses(VirtualFile file) {
     return false;
   }