add ProjectFileIndex#isInLibrary(fileOrDir)

This commit is contained in:
Sergey Simonchik
2016-08-26 16:22:37 +03:00
parent ff548276b9
commit 142650d8d6
3 changed files with 20 additions and 3 deletions
@@ -858,7 +858,7 @@ public class DirectoryIndexTest extends IdeaTestCase {
private void checkInfo(VirtualFile file,
@Nullable Module module,
boolean isInLibrary,
boolean isInLibraryClasses,
boolean isInLibrarySource,
@Nullable String packageName,
@Nullable final JpsModuleSourceRootType<?> moduleSourceRootType,
@@ -872,8 +872,9 @@ public class DirectoryIndexTest extends IdeaTestCase {
else {
assertFalse("isInModuleSource", info.isInModuleSource());
}
assertEquals(isInLibrary, info.hasLibraryClassRoot());
assertEquals(isInLibraryClasses, info.hasLibraryClassRoot());
assertEquals(isInLibrarySource, info.isInLibrarySource());
assertEquals(isInLibraryClasses || isInLibrarySource, myFileIndex.isInLibrary(file));
if (file.isDirectory()) {
assertEquals(packageName, myFileIndex.getPackageNameByDirectory(file));
@@ -140,6 +140,16 @@ public interface ProjectFileIndex extends FileIndex {
*/
boolean isInLibraryClasses(@NotNull VirtualFile fileOrDir);
/**
* Returns true if <code>fileOrDir</code> is a file which belongs to the classes or sources of some library.
*
* @param fileOrDir the file or directory to check.
* @return true if the file belongs to the classes or sources of some library, false otherwise.
*/
default boolean isInLibrary(@NotNull VirtualFile fileOrDir) {
return isInLibraryClasses(fileOrDir) || isInLibrarySource(fileOrDir);
}
/**
* Returns true if <code>fileOrDir</code> is a file or directory from library source.
*
@@ -173,4 +183,4 @@ public interface ProjectFileIndex extends FileIndex {
* @return true if <code>file</code> is ignored, false otherwise.
*/
boolean isUnderIgnored(@NotNull VirtualFile file);
}
}
@@ -191,6 +191,12 @@ public class ProjectFileIndexImpl extends FileIndexBase implements ProjectFileIn
return getInfoForFileOrDirectory(fileOrDir).isInLibrarySource();
}
// a slightly faster implementation then the default one
public boolean isInLibrary(@NotNull VirtualFile fileOrDir) {
DirectoryInfo info = getInfoForFileOrDirectory(fileOrDir);
return info.isInProject() && info.hasLibraryClassRoot() || info.isInLibrarySource();
}
@Override
public boolean isIgnored(@NotNull VirtualFile file) {
return isExcluded(file);