Search in sources :

Example 76 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class ScopeBasedTodosTreeStructure method accept.

@Override
public boolean accept(final PsiFile psiFile) {
    if (!psiFile.isValid())
        return false;
    SearchScope scope = myScopes.getSelectedScope();
    VirtualFile file = psiFile.getVirtualFile();
    boolean isAffected = scope != null && file != null && scope.contains(file);
    return isAffected && (myTodoFilter != null && myTodoFilter.accept(mySearchHelper, psiFile) || (myTodoFilter == null && mySearchHelper.getTodoItemsCount(psiFile) > 0));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SearchScope(com.intellij.psi.search.SearchScope)

Example 77 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class GroovyScopeUtil method getEffectiveScope.

public static SearchScope getEffectiveScope(PsiMethod... methods) {
    SearchScope accessScope = methods[0].getUseScope();
    for (int i = 1; i < methods.length; i++) {
        PsiMethod method1 = methods[i];
        accessScope = accessScope.union(method1.getUseScope());
    }
    return accessScope;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) SearchScope(com.intellij.psi.search.SearchScope)

Example 78 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class AccessorMethodReferencesSearcher method processQuery.

@Override
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
    final PsiMethod method = queryParameters.getMethod();
    final String propertyName;
    if (GdkMethodUtil.isCategoryMethod(method, null, null, PsiSubstitutor.EMPTY)) {
        final GrGdkMethod cat = GrGdkMethodImpl.createGdkMethod(method, false, null);
        propertyName = GroovyPropertyUtils.getPropertyName((PsiMethod) cat);
    } else {
        propertyName = GroovyPropertyUtils.getPropertyName(method);
    }
    if (propertyName == null)
        return;
    final SearchScope onlyGroovyFiles = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope(), GroovyScopeUtil.getEffectiveScope(method));
    queryParameters.getOptimizer().searchWord(propertyName, onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method);
    if (!GroovyPropertyUtils.isPropertyName(propertyName)) {
        queryParameters.getOptimizer().searchWord(StringUtil.decapitalize(propertyName), onlyGroovyFiles, UsageSearchContext.IN_CODE, true, method);
    }
}
Also used : GrGdkMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod) PsiMethod(com.intellij.psi.PsiMethod) SearchScope(com.intellij.psi.search.SearchScope)

Example 79 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class JavaFxMethodSearcher method searchMethod.

private static void searchMethod(@NotNull PsiMethod psiMethod, @NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
    final Project project = PsiUtilCore.getProjectInReadAction(psiMethod);
    final SearchScope scope = ReadAction.compute(queryParameters::getEffectiveSearchScope);
    if (scope instanceof LocalSearchScope) {
        final VirtualFile[] vFiles = ((LocalSearchScope) scope).getVirtualFiles();
        for (VirtualFile vFile : vFiles) {
            if (JavaFxFileTypeFactory.isFxml(vFile)) {
                final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
                if (psiFile != null) {
                    final Boolean goOn = ReadAction.compute(() -> searchMethodInFile(psiMethod, psiFile, consumer));
                    if (!goOn)
                        break;
                }
            }
        }
    } else if (scope instanceof GlobalSearchScope) {
        final String propertyName = ReadAction.compute(() -> PropertyUtil.getPropertyName(psiMethod.getName()));
        if (propertyName == null)
            return;
        final String className = ReadAction.compute(() -> {
            final PsiClass psiClass = psiMethod.getContainingClass();
            return psiClass != null ? psiClass.getName() : null;
        });
        if (className == null)
            return;
        final GlobalSearchScope fxmlScope = new JavaFxScopeEnlarger.GlobalFxmlSearchScope((GlobalSearchScope) scope);
        final VirtualFile[] filteredFiles = ReadAction.compute(() -> CacheManager.SERVICE.getInstance(project).getVirtualFilesWithWord(className, UsageSearchContext.IN_PLAIN_TEXT, fxmlScope, true));
        if (ArrayUtil.isEmpty(filteredFiles))
            return;
        final GlobalSearchScope filteredScope = GlobalSearchScope.filesScope(project, ContainerUtil.newHashSet(filteredFiles));
        ApplicationManager.getApplication().runReadAction((Runnable) () -> CacheManager.SERVICE.getInstance(project).processFilesWithWord(file -> searchMethodInFile(psiMethod, file, consumer), propertyName, UsageSearchContext.IN_PLAIN_TEXT, filteredScope, true));
    }
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) JavaFxFileTypeFactory(org.jetbrains.plugins.javaFX.fxml.JavaFxFileTypeFactory) ArrayUtil(com.intellij.util.ArrayUtil) JavaFxPropertyElement(org.jetbrains.plugins.javaFX.refactoring.JavaFxPropertyElement) XmlAttribute(com.intellij.psi.xml.XmlAttribute) VirtualFile(com.intellij.openapi.vfs.VirtualFile) QueryExecutor(com.intellij.util.QueryExecutor) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) ContainerUtil(com.intellij.util.containers.ContainerUtil) ReadAction(com.intellij.openapi.application.ReadAction) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) UsageSearchContext(com.intellij.psi.search.UsageSearchContext) PropertyUtil(com.intellij.psi.util.PropertyUtil) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) CacheManager(com.intellij.psi.impl.cache.CacheManager) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) XmlElement(com.intellij.psi.xml.XmlElement) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope)

Example 80 with SearchScope

use of com.intellij.psi.search.SearchScope in project intellij-community by JetBrains.

the class ExtractMethodProcessor method doRefactoring.

/**
   * Invoked in command and in atomic action
   */
public void doRefactoring() throws IncorrectOperationException {
    initDuplicates();
    chooseAnchor();
    LogicalPosition pos1;
    if (myEditor != null) {
        int col = myEditor.getCaretModel().getLogicalPosition().column;
        int line = myEditor.getCaretModel().getLogicalPosition().line;
        pos1 = new LogicalPosition(line, col);
        LogicalPosition pos = new LogicalPosition(0, 0);
        myEditor.getCaretModel().moveToLogicalPosition(pos);
    } else {
        pos1 = null;
    }
    final SearchScope processConflictsScope = myMethodVisibility.equals(PsiModifier.PRIVATE) ? new LocalSearchScope(myTargetClass) : GlobalSearchScope.projectScope(myProject);
    final Map<PsiMethodCallExpression, PsiMethod> overloadsResolveMap = new HashMap<>();
    final Runnable collectOverloads = () -> ApplicationManager.getApplication().runReadAction(() -> {
        Map<PsiMethodCallExpression, PsiMethod> overloads = ExtractMethodUtil.encodeOverloadTargets(myTargetClass, processConflictsScope, myMethodName, myCodeFragmentMember);
        overloadsResolveMap.putAll(overloads);
    });
    final Runnable extract = () -> {
        doExtract();
        ExtractMethodUtil.decodeOverloadTargets(overloadsResolveMap, myExtractedMethod, myCodeFragmentMember);
    };
    if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
        collectOverloads.run();
        extract.run();
    } else {
        if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(collectOverloads, "Collect overloads...", true, myProject))
            return;
        ApplicationManager.getApplication().runWriteAction(extract);
    }
    if (myEditor != null) {
        myEditor.getCaretModel().moveToLogicalPosition(pos1);
        int offset = myMethodCall.getMethodExpression().getTextRange().getStartOffset();
        myEditor.getCaretModel().moveToOffset(offset);
        myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
        myEditor.getSelectionModel().removeSelection();
    }
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope)

Aggregations

SearchScope (com.intellij.psi.search.SearchScope)90 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)39 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)36 Project (com.intellij.openapi.project.Project)21 NotNull (org.jetbrains.annotations.NotNull)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 PsiElement (com.intellij.psi.PsiElement)16 PsiClass (com.intellij.psi.PsiClass)8 Processor (com.intellij.util.Processor)8 com.intellij.psi (com.intellij.psi)6 PsiMethod (com.intellij.psi.PsiMethod)6 HashMap (com.intellij.util.containers.HashMap)6 ClassInheritorsSearch (com.intellij.psi.search.searches.ClassInheritorsSearch)5 Nullable (org.jetbrains.annotations.Nullable)5 AnalysisScope (com.intellij.analysis.AnalysisScope)4 ProgressManager (com.intellij.openapi.progress.ProgressManager)4 TextRange (com.intellij.openapi.util.TextRange)4 PsiFile (com.intellij.psi.PsiFile)4 PsiSearchHelper (com.intellij.psi.search.PsiSearchHelper)4 QueryExecutor (com.intellij.util.QueryExecutor)4