use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.
the class PsiPackageFavoriteNodeProvider method elementContainsFile.
@Override
public boolean elementContainsFile(final Object element, final VirtualFile vFile) {
if (element instanceof PackageElement) {
final Set<Boolean> find = new HashSet<>();
final ContentIterator contentIterator = new ContentIterator() {
@Override
public boolean processFile(VirtualFile fileOrDir) {
if (fileOrDir != null && fileOrDir.getPath().equals(vFile.getPath())) {
find.add(Boolean.TRUE);
}
return true;
}
};
final PackageElement packageElement = (PackageElement) element;
final PsiPackage aPackage = packageElement.getPackage();
final Project project = aPackage.getProject();
final GlobalSearchScope scope = packageElement.getModule() != null ? GlobalSearchScope.moduleScope(packageElement.getModule()) : GlobalSearchScope.projectScope(project);
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final PsiDirectory[] directories = aPackage.getDirectories(scope);
for (PsiDirectory directory : directories) {
projectFileIndex.iterateContentUnderDirectory(directory.getVirtualFile(), contentIterator);
}
return !find.isEmpty();
}
return false;
}
use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.
the class DirectoryIndexRestoreTest method testDeepDeleteAndRecreate.
public void testDeepDeleteAndRecreate() throws IOException {
AtomicInteger counter = new AtomicInteger(0);
ContentIterator iterator = (file) -> {
boolean found = file.getPath().equals(myTestDirPath);
if (found)
counter.incrementAndGet();
return !found;
};
File topFile = new File(myTempVFile.getPath(), "top"), bakFile = new File(myTempVFile.getPath(), "top.bak");
String topPath = myTempVFile.getPath() + "/top";
myFileIndex.iterateContent(iterator);
assertEquals(1, counter.get());
FileUtil.rename(topFile, bakFile);
List<String> events1 = print(getEvents(() -> myTempVFile.refresh(false, true)));
assertEquals(singletonList("D : " + topPath), events1);
myFileIndex.iterateContent(iterator);
assertEquals(1, counter.get());
FileUtil.rename(bakFile, topFile);
List<String> events2 = print(getEvents(() -> myTempVFile.refresh(false, true)));
assertEquals(singletonList("C : " + topPath), events2);
myFileIndex.iterateContent(iterator);
assertEquals(2, counter.get());
}
use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.
the class ExpressionStatisticsAction method collectJavaFiles.
@NotNull
private static List<VirtualFile> collectJavaFiles(VirtualFile dir, Project project) {
final List<VirtualFile> javaFiles = ContainerUtil.newArrayList();
ProjectFileIndex.SERVICE.getInstance(project).iterateContentUnderDirectory(dir, new ContentIterator() {
@Override
public boolean processFile(VirtualFile file) {
if (file.getName().endsWith(".java")) {
javaFiles.add(file);
}
return true;
}
});
return javaFiles;
}
use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.
the class MatcherImpl method findMatches.
private boolean findMatches(MatchOptions options, CompiledPattern compiledPattern) {
SearchScope searchScope = compiledPattern.getScope();
final boolean ourOptimizedScope = searchScope != null;
if (!ourOptimizedScope)
searchScope = options.getScope();
if (searchScope instanceof GlobalSearchScope) {
final GlobalSearchScope scope = (GlobalSearchScope) searchScope;
final ContentIterator ci = new ContentIterator() {
@Override
public boolean processFile(final VirtualFile fileOrDir) {
if (!fileOrDir.isDirectory() && scope.contains(fileOrDir) && fileOrDir.getFileType() != FileTypes.UNKNOWN) {
++totalFilesToScan;
scheduler.addOneTask(new MatchOneVirtualFile(fileOrDir));
}
return true;
}
};
ApplicationManager.getApplication().runReadAction(() -> FileBasedIndex.getInstance().iterateIndexableFiles(ci, project, progress));
progress.setText2("");
} else {
final PsiElement[] elementsToScan = ((LocalSearchScope) searchScope).getScope();
totalFilesToScan = elementsToScan.length;
for (int i = 0; i < elementsToScan.length; ++i) {
final PsiElement psiElement = elementsToScan[i];
if (psiElement == null)
continue;
scheduler.addOneTask(new MatchOnePsiFile(psiElement));
// to prevent long PsiElement reference
if (ourOptimizedScope)
elementsToScan[i] = null;
}
}
return true;
}
use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.
the class LightProjectDescriptor method registerSourceRoot.
protected void registerSourceRoot(Project project, VirtualFile srcRoot) {
IndexableFileSet indexableFileSet = new IndexableFileSet() {
@Override
public boolean isInSet(@NotNull VirtualFile file) {
return file.getFileSystem() == srcRoot.getFileSystem() && project.isOpen();
}
@Override
public void iterateIndexableFilesIn(@NotNull VirtualFile file, @NotNull ContentIterator iterator) {
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
iterator.processFile(file);
return true;
}
});
}
};
FileBasedIndex.getInstance().registerIndexableSet(indexableFileSet, null);
Disposer.register(project, () -> FileBasedIndex.getInstance().removeIndexableSet(indexableFileSet));
}
Aggregations