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.vcs.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.ProjectRootManager;
23 import com.intellij.openapi.roots.impl.DirectoryIndex;
24 import com.intellij.openapi.vfs.VirtualFile;
25 import org.jetbrains.annotations.Nullable;
30 public class ProjectFileIndexFacade extends FileIndexFacade {
31 private final ProjectRootManager myRootManager;
32 private final DirectoryIndex myDirectoryIndex;
34 public ProjectFileIndexFacade(final Project project, final ProjectRootManager rootManager, final DirectoryIndex directoryIndex) {
36 myRootManager = rootManager;
37 myDirectoryIndex = directoryIndex;
40 public boolean isInContent(final VirtualFile file) {
41 return myRootManager.getFileIndex().isInContent(file);
45 public boolean isInSource(VirtualFile file) {
46 return myRootManager.getFileIndex().isInSource(file);
50 public boolean isInLibraryClasses(VirtualFile file) {
51 return myRootManager.getFileIndex().isInLibraryClasses(file);
55 public boolean isInLibrarySource(VirtualFile file) {
56 return myRootManager.getFileIndex().isInLibrarySource(file);
59 public boolean isExcludedFile(final VirtualFile file) {
60 return myRootManager.getFileIndex().isIgnored(file);
65 public Module getModuleForFile(VirtualFile file) {
66 return myRootManager.getFileIndex().getModuleForFile(file);
69 public boolean isValidAncestor(final VirtualFile baseDir, VirtualFile childDir) {
70 if (!childDir.isDirectory()) {
71 childDir = childDir.getParent();
74 if (childDir == null) return false;
75 if (childDir.equals(baseDir)) return true;
76 if (myDirectoryIndex.getInfoForDirectory(childDir) == null) return false;
77 childDir = childDir.getParent();