use of com.intellij.util.indexing.IndexableFileSet 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));
}
use of com.intellij.util.indexing.IndexableFileSet in project intellij-plugins by JetBrains.
the class DesignerTests method configureByFiles.
public static VirtualFile[] configureByFiles(@Nullable VirtualFile rawProjectRoot, VirtualFile[] files, @Nullable VirtualFile[] auxiliaryFiles, Module module, @Nullable TripleFunction<ModifiableRootModel, VirtualFile, List<String>, Void> moduleInitializer) throws Exception {
return WriteAction.compute(() -> {
VirtualFile dummyRoot = VirtualFileManager.getInstance().findFileByUrl("temp:///");
//noinspection ConstantConditions
dummyRoot.refresh(false, false);
final VirtualFile sourceDir = dummyRoot.createChildDirectory(DesignerTests.class, "s");
assert sourceDir != null;
final IndexableFileSet indexableFileSet = new IndexableFileSet() {
@Override
public boolean isInSet(@NotNull final VirtualFile file) {
return file.getFileSystem() == sourceDir.getFileSystem();
}
@Override
public void iterateIndexableFilesIn(@NotNull final VirtualFile file, @NotNull final ContentIterator iterator) {
if (file.isDirectory()) {
for (VirtualFile child : file.getChildren()) {
iterateIndexableFilesIn(child, iterator);
}
} else {
iterator.processFile(file);
}
}
};
FileBasedIndex.getInstance().registerIndexableSet(indexableFileSet, module.getProject());
Disposer.register(module, new Disposable() {
@Override
public void dispose() {
FileBasedIndex.getInstance().removeIndexableSet(indexableFileSet);
ApplicationManager.getApplication().runWriteAction(() -> {
try {
sourceDir.delete(null);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
});
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
VirtualFile[] toFiles = copyFiles(files, sourceDir, rawProjectRoot);
if (auxiliaryFiles != null) {
copyFiles(auxiliaryFiles, sourceDir, rawProjectRoot);
}
rootModel.addContentEntry(sourceDir).addSourceFolder(sourceDir, false);
final List<String> libs = new ArrayList<>();
if (moduleInitializer != null) {
moduleInitializer.fun(rootModel, sourceDir, libs);
}
rootModel.commit();
for (String path : libs) {
VirtualFile virtualFile = path.charAt(0) != '/' ? getFile("lib", path) : getFile(path);
FlexTestUtils.addLibrary(module, path, virtualFile.getParent().getPath(), virtualFile.getName(), null, null);
}
return toFiles;
});
}
Aggregations