use of com.intellij.psi.impl.cache.impl.id.IdIndexEntry in project intellij-community by JetBrains.
the class PsiSearchHelperImpl method isCheapEnoughToSearch.
@NotNull
@Override
public SearchCostResult isCheapEnoughToSearch(@NotNull String name, @NotNull final GlobalSearchScope scope, @Nullable final PsiFile fileToIgnoreOccurrencesIn, @Nullable final ProgressIndicator progress) {
final AtomicInteger count = new AtomicInteger();
final ProgressIndicator indicator = progress == null ? new EmptyProgressIndicator() : progress;
final Processor<VirtualFile> processor = new Processor<VirtualFile>() {
private final VirtualFile virtualFileToIgnoreOccurrencesIn = fileToIgnoreOccurrencesIn == null ? null : fileToIgnoreOccurrencesIn.getVirtualFile();
@Override
public boolean process(VirtualFile file) {
indicator.checkCanceled();
if (Comparing.equal(file, virtualFileToIgnoreOccurrencesIn))
return true;
final int value = count.incrementAndGet();
return value < 10;
}
};
List<IdIndexEntry> keys = getWordEntries(name, true);
boolean cheap = keys.isEmpty() || processFilesContainingAllKeys(myManager.getProject(), scope, null, keys, processor);
if (!cheap) {
return SearchCostResult.TOO_MANY_OCCURRENCES;
}
return count.get() == 0 ? SearchCostResult.ZERO_OCCURRENCES : SearchCostResult.FEW_OCCURRENCES;
}
use of com.intellij.psi.impl.cache.impl.id.IdIndexEntry in project intellij-community by JetBrains.
the class PsiSearchHelperImpl method distributePrimitives.
private static void distributePrimitives(@NotNull Map<SearchRequestCollector, Processor<PsiReference>> collectors, @NotNull Set<RequestWithProcessor> locals, @NotNull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> globals, @NotNull List<Computable<Boolean>> customs, @NotNull Map<RequestWithProcessor, Processor<PsiElement>> localProcessors, @NotNull ProgressIndicator progress) {
for (final Map.Entry<SearchRequestCollector, Processor<PsiReference>> entry : collectors.entrySet()) {
final Processor<PsiReference> processor = entry.getValue();
SearchRequestCollector collector = entry.getKey();
for (final PsiSearchRequest primitive : collector.takeSearchRequests()) {
final SearchScope scope = primitive.searchScope;
if (scope instanceof LocalSearchScope) {
registerRequest(locals, primitive, processor);
} else {
Set<IdIndexEntry> key = new HashSet<>(getWordEntries(primitive.word, primitive.caseSensitive));
registerRequest(globals.getModifiable(key), primitive, processor);
}
}
for (final Processor<Processor<PsiReference>> customAction : collector.takeCustomSearchActions()) {
customs.add(() -> customAction.process(processor));
}
}
for (Map.Entry<Set<IdIndexEntry>, Collection<RequestWithProcessor>> entry : globals.entrySet()) {
for (RequestWithProcessor singleRequest : entry.getValue()) {
PsiSearchRequest primitive = singleRequest.request;
StringSearcher searcher = new StringSearcher(primitive.word, primitive.caseSensitive, true, false);
BulkOccurrenceProcessor adapted = adaptProcessor(primitive, singleRequest.refProcessor);
Processor<PsiElement> localProcessor = localProcessor(adapted, progress, searcher);
assert !localProcessors.containsKey(singleRequest) || localProcessors.get(singleRequest) == localProcessor;
localProcessors.put(singleRequest, localProcessor);
}
}
}
use of com.intellij.psi.impl.cache.impl.id.IdIndexEntry 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();
}
}
use of com.intellij.psi.impl.cache.impl.id.IdIndexEntry in project intellij-community by JetBrains.
the class PsiSearchHelperImpl method collectFiles.
private void collectFiles(@NotNull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> singles, @NotNull ProgressIndicator progress, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> intersectionResult, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> restResult) {
for (Map.Entry<Set<IdIndexEntry>, Collection<RequestWithProcessor>> entry : singles.entrySet()) {
final Set<IdIndexEntry> keys = entry.getKey();
if (keys.isEmpty()) {
continue;
}
final Collection<RequestWithProcessor> processors = entry.getValue();
final GlobalSearchScope commonScope = uniteScopes(processors);
final Set<VirtualFile> intersectionWithContainerNameFiles = intersectionWithContainerNameFiles(commonScope, processors, keys);
List<VirtualFile> result = new ArrayList<>();
Processor<VirtualFile> processor = Processors.cancelableCollectProcessor(result);
processFilesContainingAllKeys(myManager.getProject(), commonScope, null, keys, processor);
for (final VirtualFile file : result) {
progress.checkCanceled();
for (final IdIndexEntry indexEntry : keys) {
DumbService.getInstance(myManager.getProject()).runReadActionInSmartMode(() -> FileBasedIndex.getInstance().processValues(IdIndex.NAME, indexEntry, file, (file1, value) -> {
int mask = value.intValue();
for (RequestWithProcessor single : processors) {
final PsiSearchRequest request = single.request;
if ((mask & request.searchContext) != 0 && request.searchScope.contains(file1)) {
MultiMap<VirtualFile, RequestWithProcessor> result1 = intersectionWithContainerNameFiles == null || !intersectionWithContainerNameFiles.contains(file1) ? restResult : intersectionResult;
result1.putValue(file1, single);
}
}
return true;
}, commonScope));
}
}
}
}
use of com.intellij.psi.impl.cache.impl.id.IdIndexEntry in project intellij-community by JetBrains.
the class IdDataConsumer method getResult.
public Map<IdIndexEntry, Integer> getResult() {
final Map<IdIndexEntry, Integer> result = new THashMap<>(myResult.size());
myResult.forEachEntry((key, value) -> {
result.put(new IdIndexEntry(key), value);
return true;
});
return result;
}
Aggregations