2 * Copyright 2000-2011 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.roots;
18 import com.intellij.openapi.components.ServiceManager;
19 import com.intellij.openapi.module.Module;
20 import com.intellij.openapi.module.UnloadedModuleDescription;
21 import com.intellij.openapi.project.Project;
22 import com.intellij.openapi.util.ModificationTracker;
23 import com.intellij.openapi.vfs.VirtualFile;
24 import com.intellij.psi.search.GlobalSearchScope;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
28 import java.util.Collection;
33 public abstract class FileIndexFacade {
34 protected final Project myProject;
36 protected FileIndexFacade(final Project project) {
40 public static FileIndexFacade getInstance(Project project) {
41 return ServiceManager.getService(project, FileIndexFacade.class);
44 public abstract boolean isInContent(@NotNull VirtualFile file);
45 public abstract boolean isInSource(@NotNull VirtualFile file);
46 public abstract boolean isInSourceContent(@NotNull VirtualFile file);
47 public abstract boolean isInLibraryClasses(@NotNull VirtualFile file);
49 public abstract boolean isInLibrarySource(@NotNull VirtualFile file);
50 public abstract boolean isExcludedFile(@NotNull VirtualFile file);
51 public abstract boolean isUnderIgnored(@NotNull VirtualFile file);
54 public abstract Module getModuleForFile(@NotNull VirtualFile file);
57 * Checks if {@code file} is an ancestor of {@code baseDir} and none of the files
58 * between them are excluded from the project.
60 * @param baseDir the parent directory to check for ancestry.
61 * @param child the child directory or file to check for ancestry.
62 * @return true if it's a valid ancestor, false otherwise.
64 public abstract boolean isValidAncestor(@NotNull VirtualFile baseDir, @NotNull VirtualFile child);
66 public boolean shouldBeFound(GlobalSearchScope scope, VirtualFile virtualFile) {
67 return scope.isSearchOutsideRootModel() || isInContent(virtualFile) || isInLibrarySource(virtualFile);
70 @NotNull public abstract ModificationTracker getRootModificationTracker();
73 * @return descriptions of all modules which are unloaded from the project
74 * @see UnloadedModuleDescription
77 public abstract Collection<UnloadedModuleDescription> getUnloadedModuleDescriptions();