use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class SvnCheckoutProvider method doImport.
public static void doImport(final Project project, final File target, final SVNURL url, final Depth depth, final boolean includeIgnored, final String message) {
final Ref<String> errorMessage = new Ref<>();
final SvnVcs vcs = SvnVcs.getInstance(project);
final String targetPath = FileUtil.toSystemIndependentName(target.getAbsolutePath());
ExclusiveBackgroundVcsAction.run(project, () -> ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(project, FileIndexFacade.class);
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
try {
progressIndicator.setText(message("progress.text.import", target.getAbsolutePath()));
final VirtualFile targetVf = SvnUtil.getVirtualFile(targetPath);
if (targetVf == null) {
errorMessage.set("Can not find file: " + targetPath);
} else {
final boolean isInContent = getApplication().runReadAction((Computable<Boolean>) () -> facade.isInContent(targetVf));
CommitEventHandler handler = new IdeaCommitHandler(progressIndicator);
boolean useFileFilter = !project.isDefault() && isInContent;
ISVNCommitHandler commitHandler = useFileFilter ? new MyFilter(LocalFileSystem.getInstance(), new SvnExcludingIgnoredOperation.Filter(project)) : null;
long revision = vcs.getFactoryFromSettings().createImportClient().doImport(target, url, depth, message, includeIgnored, handler, commitHandler);
if (revision > 0) {
StatusBar.Info.set(message("status.text.comitted.revision", revision), project);
}
}
} catch (VcsException e) {
errorMessage.set(e.getMessage());
}
}, message("message.title.import"), true, project));
if (!errorMessage.isNull()) {
showErrorDialog(message("message.text.cannot.import", errorMessage.get()), message("message.title.import"));
}
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class PsiElementFinderImpl method getClassNames.
@NotNull
@Override
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
Set<String> names = null;
FileIndexFacade facade = FileIndexFacade.getInstance(myProject);
for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
for (PsiFile file : dir.getFiles()) {
if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
VirtualFile vFile = file.getVirtualFile();
if (vFile != null && !(file instanceof PsiCompiledElement) && !facade.isInSourceContent(vFile) && (!scope.isForceSearchingInLibrarySources() || !StubTreeLoader.getInstance().canHaveStub(vFile))) {
continue;
}
Set<String> inFile = file instanceof PsiClassOwnerEx ? ((PsiClassOwnerEx) file).getClassNames() : getClassNames(((PsiClassOwner) file).getClasses());
if (inFile.isEmpty())
continue;
if (names == null)
names = new HashSet<>();
names.addAll(inFile);
}
}
}
return names == null ? Collections.<String>emptySet() : names;
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class SingleRootFileViewProvider method createFile.
private PsiFile createFile() {
try {
final VirtualFile vFile = getVirtualFile();
if (vFile.isDirectory())
return null;
if (isIgnored())
return null;
final Project project = myManager.getProject();
if (isPhysical() && vFile.isInLocalFileSystem()) {
// check directories consistency
final VirtualFile parent = vFile.getParent();
if (parent == null)
return null;
final PsiDirectory psiDir = getManager().findDirectory(parent);
if (psiDir == null) {
FileIndexFacade indexFacade = FileIndexFacade.getInstance(project);
if (!indexFacade.isInLibrarySource(vFile) && !indexFacade.isInLibraryClasses(vFile)) {
return null;
}
}
}
return createFile(project, vFile, myFileType);
} catch (ProcessCanceledException e) {
throw e;
} catch (Throwable e) {
LOG.error(e);
return null;
}
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class MappingsToRoots method getRootsUnderVcs.
@NotNull
public VirtualFile[] getRootsUnderVcs(@NotNull AbstractVcs vcs) {
List<VirtualFile> result = myMappings.getMappingsAsFilesUnderVcs(vcs);
final AbstractVcs.RootsConvertor convertor = vcs.getCustomConvertor();
if (convertor != null) {
result = convertor.convertRoots(result);
}
Collections.sort(result, FilePathComparator.getInstance());
if (!vcs.allowsNestedRoots()) {
final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(myProject, FileIndexFacade.class);
final List<VirtualFile> finalResult = result;
ApplicationManager.getApplication().runReadAction(() -> {
int i = 1;
while (i < finalResult.size()) {
final VirtualFile previous = finalResult.get(i - 1);
final VirtualFile current = finalResult.get(i);
if (facade.isValidAncestor(previous, current)) {
finalResult.remove(i);
} else {
i++;
}
}
});
}
result.removeIf(file -> !file.isDirectory());
return VfsUtilCore.toVirtualFileArray(result);
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class IndexCacheManagerImpl method collectVirtualFilesWithWord.
// IMPORTANT!!!
// Since implementation of virtualFileProcessor.process() may call indices directly or indirectly,
// we cannot call it inside FileBasedIndex.processValues() method except in collecting form
// If we do, deadlocks are possible (IDEADEV-42137). Process the files without not holding indices' read lock.
private boolean collectVirtualFilesWithWord(@NotNull final String word, final short occurrenceMask, @NotNull final GlobalSearchScope scope, final boolean caseSensitively, @NotNull final Processor<VirtualFile> fileProcessor) {
if (myProject.isDefault()) {
return true;
}
try {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return FileBasedIndex.getInstance().processValues(IdIndex.NAME, new IdIndexEntry(word, caseSensitively), null, new FileBasedIndex.ValueProcessor<Integer>() {
final FileIndexFacade index = FileIndexFacade.getInstance(myProject);
@Override
public boolean process(final VirtualFile file, final Integer value) {
ProgressIndicatorProvider.checkCanceled();
final int mask = value.intValue();
if ((mask & occurrenceMask) != 0 && index.shouldBeFound(scope, file)) {
if (!fileProcessor.process(file))
return false;
}
return true;
}
}, scope);
}
});
} catch (IndexNotReadyException e) {
throw new ProcessCanceledException();
}
}
Aggregations