2 * Copyright 2000-2009 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.
17 package com.intellij.openapi.roots.impl;
19 import com.intellij.openapi.module.Module;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.openapi.roots.FileIndexFacade;
22 import com.intellij.openapi.roots.JdkOrderEntry;
23 import com.intellij.openapi.roots.ProjectFileIndex;
24 import com.intellij.openapi.roots.ProjectRootManager;
25 import com.intellij.openapi.vfs.VirtualFile;
26 import com.intellij.util.containers.ContainerUtil;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
33 public class ProjectFileIndexFacade extends FileIndexFacade {
34 private final DirectoryIndex myDirectoryIndex;
35 private final ProjectFileIndex myFileIndex;
37 public ProjectFileIndexFacade(final Project project, final ProjectRootManager rootManager, final DirectoryIndex directoryIndex) {
39 myDirectoryIndex = directoryIndex;
40 myFileIndex = rootManager.getFileIndex();
43 public boolean isInContent(@NotNull final VirtualFile file) {
44 return myFileIndex.isInContent(file);
48 public boolean isInSource(@NotNull VirtualFile file) {
49 return myFileIndex.isInSource(file);
53 public boolean isInSourceContent(@NotNull VirtualFile file) {
54 return myFileIndex.isInSourceContent(file);
58 public boolean isInLibraryClasses(@NotNull VirtualFile file) {
59 return myFileIndex.isInLibraryClasses(file);
63 public boolean isInSdkClasses(@NotNull VirtualFile file) {
64 return ContainerUtil.findInstance(myFileIndex.getOrderEntriesForFile(file), JdkOrderEntry.class) != null;
68 public boolean isInLibrarySource(@NotNull VirtualFile file) {
69 return myFileIndex.isInLibrarySource(file);
72 public boolean isExcludedFile(@NotNull final VirtualFile file) {
73 return myFileIndex.isIgnored(file);
78 public Module getModuleForFile(VirtualFile file) {
79 return myFileIndex.getModuleForFile(file);
82 public boolean isValidAncestor(final VirtualFile baseDir, VirtualFile childDir) {
83 if (!childDir.isDirectory()) {
84 childDir = childDir.getParent();
87 if (childDir == null) return false;
88 if (childDir.equals(baseDir)) return true;
89 if (myDirectoryIndex.getInfoForDirectory(childDir) == null) return false;
90 childDir = childDir.getParent();