use of com.intellij.psi.impl.search.PsiSearchHelperImpl in project intellij-community by JetBrains.
the class FormReferencesSearcher method processReferencesInUIForms.
private static boolean processReferencesInUIForms(final Processor<PsiReference> processor, PsiManager psiManager, final Property property, final GlobalSearchScope globalSearchScope, final LocalSearchScope filterScope) {
final Project project = psiManager.getProject();
final GlobalSearchScope scope = GlobalSearchScope.projectScope(project).intersectWith(globalSearchScope);
String name = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return property.getName();
}
});
if (name == null)
return true;
psiManager.startBatchFilesProcessingMode();
try {
CommonProcessors.CollectProcessor<VirtualFile> collector = new CommonProcessors.CollectProcessor<VirtualFile>() {
@Override
protected boolean accept(VirtualFile virtualFile) {
return virtualFile.getFileType() == StdFileTypes.GUI_DESIGNER_FORM;
}
};
((PsiSearchHelperImpl) PsiSearchHelper.SERVICE.getInstance(project)).processFilesWithText(scope, UsageSearchContext.IN_PLAIN_TEXT, true, name, collector);
for (final VirtualFile vfile : collector.getResults()) {
ProgressManager.checkCanceled();
PsiFile file = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
@Override
public PsiFile compute() {
return PsiManager.getInstance(project).findFile(vfile);
}
});
if (!processReferences(processor, file, name, property, filterScope))
return false;
}
} finally {
psiManager.finishBatchFilesProcessingMode();
}
return true;
}
use of com.intellij.psi.impl.search.PsiSearchHelperImpl in project intellij-community by JetBrains.
the class FindInProjectTask method getFilesForFastWordSearch.
@NotNull
private Set<VirtualFile> getFilesForFastWordSearch() {
String stringToFind = myStringToFindInIndices;
if (stringToFind.isEmpty() || DumbService.getInstance(myProject).isDumb()) {
return Collections.emptySet();
}
final Set<VirtualFile> resultFiles = new LinkedHashSet<>();
for (VirtualFile file : myFilesToScanInitially) {
if (myFileMask.value(file)) {
resultFiles.add(file);
}
}
final GlobalSearchScope scope = GlobalSearchScopeUtil.toGlobalSearchScope(FindInProjectUtil.getScopeFromModel(myProject, myFindModel), myProject);
if (TrigramIndex.ENABLED) {
final Set<Integer> keys = ContainerUtil.newTroveSet();
TrigramBuilder.processTrigrams(stringToFind, new TrigramBuilder.TrigramProcessor() {
@Override
public boolean execute(int value) {
keys.add(value);
return true;
}
});
if (!keys.isEmpty()) {
final List<VirtualFile> hits = new ArrayList<>();
ApplicationManager.getApplication().runReadAction(() -> {
FileBasedIndex.getInstance().getFilesWithKey(TrigramIndex.INDEX_ID, keys, Processors.cancelableCollectProcessor(hits), scope);
});
for (VirtualFile hit : hits) {
if (myFileMask.value(hit)) {
resultFiles.add(hit);
}
}
return resultFiles;
}
}
PsiSearchHelperImpl helper = (PsiSearchHelperImpl) PsiSearchHelper.SERVICE.getInstance(myProject);
helper.processFilesWithText(scope, UsageSearchContext.ANY, myFindModel.isCaseSensitive(), stringToFind, file -> {
if (myFileMask.value(file)) {
ContainerUtil.addIfNotNull(resultFiles, file);
}
return true;
});
// in case our word splitting is incorrect
CacheManager cacheManager = CacheManager.SERVICE.getInstance(myProject);
VirtualFile[] filesWithWord = cacheManager.getVirtualFilesWithWord(stringToFind, UsageSearchContext.ANY, scope, myFindModel.isCaseSensitive());
for (VirtualFile file : filesWithWord) {
if (myFileMask.value(file)) {
resultFiles.add(file);
}
}
return resultFiles;
}
Aggregations