summaryrefslogtreecommitdiff
path: root/platform/projectModel-api/src/com/intellij/openapi/roots/ProjectFileIndex.java
blob: b06cf065fd9518f7a7118e2a692e0eb057792a2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * Copyright 2000-2012 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.openapi.roots;

import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * Provides information about files contained in a project.
 *
 * @see ProjectRootManager#getFileIndex()
 */
public interface ProjectFileIndex extends FileIndex {
  class SERVICE {
    private SERVICE() {
    }

    public static ProjectFileIndex getInstance(Project project) {
      return ServiceManager.getService(project, ProjectFileIndex.class);
    }
  }

  /**
   * Returns module to which the specified file belongs.
   *
   * @param file the file for which the module is requested.
   * @return the module instance or null if the file does not belong to content of any module.
   */
  @Nullable
  Module getModuleForFile(@NotNull VirtualFile file);

  /**
   * Returns the order entries which contain the specified file (either in CLASSES or SOURCES).
   *
   * @param file the file for which the order entries are requested.
   * @return the array of order entries containing the file.
   */
  @NotNull
  List<OrderEntry> getOrderEntriesForFile(@NotNull VirtualFile file);

  /**
   * Returns a classpath entry to which the specified file or directory belongs.
   *
   * @param file the file or directory for which the information is requested.
   * @return the file for the classpath entry, or null if the file is not a compiled
   *         class file or directory belonging to a library.
   */
  @Nullable
  VirtualFile getClassRootForFile(@NotNull VirtualFile file);

  /**
   * Returns the module source root or library source root to which the specified file
   * or directory belongs.
   *
   * @param file the file or directory for which the information is requested.
   * @return the file for the source root, or null if the file is not located under any
   *         of the source roots for the module.
   */
  @Nullable
  VirtualFile getSourceRootForFile(@NotNull VirtualFile file);

  /**
   * Returns the module content root to which the specified file or directory belongs.
   *
   * @param file the file or directory for which the information is requested.
   * @return the file for the content root, or null if the file does not belong to this project.
   */
  @Nullable
  VirtualFile getContentRootForFile(@NotNull VirtualFile file);

  /**
   * Returns the name of the package corresponding to the specified directory.
   *
   * @param dir the directory for which the package name is requested.
   * @return the package name, or null if the directory does not correspond to any package.
   */
  @Nullable
  String getPackageNameByDirectory(@NotNull VirtualFile dir); //Q: move to FileIndex?

  /**
   * Returns true if <code>file</code> is a file which belongs to the classes (not sources) of some library.
   *
   * @param file the file to check.
   * @return true if the file belongs to library classes, false otherwise.
   */
  boolean isLibraryClassFile(@NotNull VirtualFile file);

  /**
   * Returns true if <code>fileOrDir</code> is a file or directory from the content source or library sources.
   *
   * @param fileOrDir the file or directory to check.
   * @return true if the file or directory belongs to project or library sources, false otherwise.
   */
  boolean isInSource(@NotNull VirtualFile fileOrDir);

  /**
   * Returns true if <code>fileOrDir</code> is a file or directory from library classes.
   *
   * @param fileOrDir the file or directory to check.
   * @return true if the file belongs to library classes, false otherwise.
   */
  boolean isInLibraryClasses(@NotNull VirtualFile fileOrDir);

  /**
   * Returns true if <code>fileOrDir</code> is a file or directory from library source.
   *
   * @param fileOrDir the file or directory to check.
   * @return true if the file belongs to library sources, false otherwise.
   */
  boolean isInLibrarySource(@NotNull VirtualFile fileOrDir);

  /**
   * @deprecated name of this method may be confusing. If you want to check if the file is excluded or ignored use {@link #isExcluded(com.intellij.openapi.vfs.VirtualFile)}.
   * If you want to check if the file is ignored use {@link com.intellij.openapi.fileTypes.FileTypeRegistry#isFileIgnored(com.intellij.openapi.vfs.VirtualFile)}.
   */
  @Deprecated
  boolean isIgnored(@NotNull VirtualFile file);

  /**
   * Checks if the specified file or directory is located under project roots but the file itself or one of its parent directories is
   * either excluded from the project or ignored by {@link com.intellij.openapi.fileTypes.FileTypeRegistry#isFileIgnored(com.intellij.openapi.vfs.VirtualFile)}).
   *
   * @param file the file to check.
   * @return true if <code>file</code> is excluded or ignored, false otherwise.
   */
  boolean isExcluded(@NotNull VirtualFile file);
}