1 // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.openapi.roots;
4 import com.intellij.openapi.module.Module;
5 import com.intellij.openapi.module.UnloadedModuleDescription;
6 import com.intellij.openapi.project.Project;
7 import com.intellij.openapi.util.ModificationTracker;
8 import com.intellij.openapi.vfs.VirtualFile;
9 import com.intellij.psi.search.GlobalSearchScope;
10 import org.jetbrains.annotations.NotNull;
11 import org.jetbrains.annotations.Nullable;
13 import java.util.Collection;
18 public abstract class FileIndexFacade {
19 protected final Project myProject;
21 protected FileIndexFacade(@NotNull Project project) {
25 public static FileIndexFacade getInstance(Project project) {
26 return project.getService(FileIndexFacade.class);
29 public abstract boolean isInContent(@NotNull VirtualFile file);
30 public abstract boolean isInSource(@NotNull VirtualFile file);
31 public abstract boolean isInSourceContent(@NotNull VirtualFile file);
32 public abstract boolean isInLibraryClasses(@NotNull VirtualFile file);
34 public abstract boolean isInLibrarySource(@NotNull VirtualFile file);
35 public abstract boolean isExcludedFile(@NotNull VirtualFile file);
36 public abstract boolean isUnderIgnored(@NotNull VirtualFile file);
38 public abstract @Nullable Module getModuleForFile(@NotNull VirtualFile file);
41 * Checks if {@code file} is an ancestor of {@code baseDir} and none of the files
42 * between them are excluded from the project.
44 * @param baseDir the parent directory to check for ancestry.
45 * @param child the child directory or file to check for ancestry.
46 * @return true if it's a valid ancestor, false otherwise.
48 public abstract boolean isValidAncestor(@NotNull VirtualFile baseDir, @NotNull VirtualFile child);
51 * @deprecated always returns true, just remove the calls
53 @SuppressWarnings("unused")
55 public boolean shouldBeFound(@NotNull GlobalSearchScope scope, @NotNull VirtualFile virtualFile) {
59 public abstract @NotNull ModificationTracker getRootModificationTracker();
62 * @return descriptions of all modules which are unloaded from the project
63 * @see UnloadedModuleDescription
65 public abstract @NotNull Collection<UnloadedModuleDescription> getUnloadedModuleDescriptions();
68 * @return true if the {@code file} is {@link #isInContent} except when it's in {@link #isInLibraryClasses} and not in {@link #isInLibrarySource}
70 public boolean isInProjectScope(@NotNull VirtualFile file) {
71 if (isInLibraryClasses(file) && !isInSourceContent(file)) return false;
73 return isInContent(file);