Search in sources :

Example 1 with PsiSearchHelperImpl

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) CommonProcessors(com.intellij.util.CommonProcessors) PsiSearchHelperImpl(com.intellij.psi.impl.search.PsiSearchHelperImpl)

Example 2 with PsiSearchHelperImpl

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TrigramBuilder(com.intellij.openapi.util.text.TrigramBuilder) PsiSearchHelperImpl(com.intellij.psi.impl.search.PsiSearchHelperImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(com.intellij.psi.impl.cache.CacheManager) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiSearchHelperImpl (com.intellij.psi.impl.search.PsiSearchHelperImpl)2 Project (com.intellij.openapi.project.Project)1 TrigramBuilder (com.intellij.openapi.util.text.TrigramBuilder)1 CacheManager (com.intellij.psi.impl.cache.CacheManager)1 CommonProcessors (com.intellij.util.CommonProcessors)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 NotNull (org.jetbrains.annotations.NotNull)1