Search in sources :

Example 61 with SearchScope

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

the class DfaVariableValue method isCheapEnoughToSearch.

private static boolean isCheapEnoughToSearch(PsiField field, String name) {
    SearchScope scope = field.getUseScope();
    if (!(scope instanceof GlobalSearchScope))
        return true;
    PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(field.getProject());
    PsiSearchHelper.SearchCostResult result = helper.isCheapEnoughToSearch(name, (GlobalSearchScope) scope, field.getContainingFile(), null);
    return result != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
}
Also used : PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope)

Example 62 with SearchScope

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

the class CallerMethodsTreeStructure method buildChildren.

@NotNull
@Override
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
    PsiMember enclosingElement = ((CallHierarchyNodeDescriptor) descriptor).getEnclosingElement();
    HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
    if (enclosingElement instanceof PsiMethod) {
        PsiClass clazz = enclosingElement.getContainingClass();
        if (isLocalOrAnonymousClass(clazz)) {
            PsiElement parent = clazz.getParent();
            PsiElement grandParent = parent instanceof PsiNewExpression ? parent.getParent() : null;
            if (grandParent instanceof PsiExpressionList) {
                // for created anonymous class that immediately passed as argument use instantiation point as next call point (IDEA-73312)
                enclosingElement = CallHierarchyNodeDescriptor.getEnclosingElement(grandParent);
            }
        }
    }
    if (!(enclosingElement instanceof PsiMethod) || nodeDescriptor == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final PsiMethod baseMethod = (PsiMethod) ((CallHierarchyNodeDescriptor) nodeDescriptor).getTargetElement();
    if (baseMethod == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final SearchScope searchScope = getSearchScope(myScopeType, baseMethod.getContainingClass());
    final PsiMethod method = (PsiMethod) enclosingElement;
    final PsiClass originalClass = method.getContainingClass();
    assert originalClass != null;
    final PsiClassType originalType = JavaPsiFacade.getElementFactory(myProject).createType(originalClass);
    final Set<PsiMethod> methodsToFind = new HashSet<>();
    methodsToFind.add(method);
    ContainerUtil.addAll(methodsToFind, method.findDeepestSuperMethods());
    final Map<PsiMember, NodeDescriptor> methodToDescriptorMap = new HashMap<>();
    for (final PsiMethod methodToFind : methodsToFind) {
        final JavaCallHierarchyData data = new JavaCallHierarchyData(originalClass, methodToFind, originalType, method, methodsToFind, descriptor, methodToDescriptorMap, myProject);
        MethodReferencesSearch.search(methodToFind, searchScope, true).forEach(reference -> {
            for (CallReferenceProcessor processor : CallReferenceProcessor.EP_NAME.getExtensions()) {
                if (!processor.process(reference, data))
                    break;
            }
            return true;
        });
    }
    return methodToDescriptorMap.values().toArray(new Object[methodToDescriptorMap.size()]);
}
Also used : HashMap(com.intellij.util.containers.HashMap) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) SearchScope(com.intellij.psi.search.SearchScope) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 63 with SearchScope

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

the class AllClassesSearchExecutor method execute.

@Override
public boolean execute(@NotNull final AllClassesSearch.SearchParameters queryParameters, @NotNull final Processor<PsiClass> consumer) {
    SearchScope scope = queryParameters.getScope();
    if (scope instanceof GlobalSearchScope) {
        return processAllClassesInGlobalScope((GlobalSearchScope) scope, queryParameters, consumer);
    }
    PsiElement[] scopeRoots = ((LocalSearchScope) scope).getScope();
    for (final PsiElement scopeRoot : scopeRoots) {
        if (!processScopeRootForAllClasses(scopeRoot, consumer))
            return false;
    }
    return true;
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) 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 64 with SearchScope

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

the class ClassesWithAnnotatedMembersSearcher method processQuery.

@Override
public void processQuery(@NotNull ClassesWithAnnotatedMembersSearch.Parameters queryParameters, @NotNull final Processor<PsiClass> consumer) {
    SearchScope scope = queryParameters.getScope();
    for (QueryExecutor executor : Extensions.getExtensions(ClassesWithAnnotatedMembersSearch.EP_NAME)) {
        if (executor instanceof ScopedQueryExecutor) {
            scope = scope.intersectWith(GlobalSearchScope.notScope(((ScopedQueryExecutor) executor).getScope(queryParameters)));
        }
    }
    final Set<PsiClass> processed = new HashSet<>();
    AnnotatedElementsSearch.searchPsiMembers(queryParameters.getAnnotationClass(), scope).forEach(member -> {
        PsiClass psiClass;
        AccessToken token = ReadAction.start();
        try {
            psiClass = member instanceof PsiClass ? (PsiClass) member : member.getContainingClass();
        } finally {
            token.finish();
        }
        if (psiClass != null && processed.add(psiClass)) {
            consumer.process(psiClass);
        }
        return true;
    });
}
Also used : QueryExecutor(com.intellij.util.QueryExecutor) ScopedQueryExecutor(com.intellij.psi.search.searches.ScopedQueryExecutor) AccessToken(com.intellij.openapi.application.AccessToken) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiClass(com.intellij.psi.PsiClass) ScopedQueryExecutor(com.intellij.psi.search.searches.ScopedQueryExecutor) HashSet(com.intellij.util.containers.hash.HashSet)

Example 65 with SearchScope

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

the class ConstructorReferencesSearcher method processQuery.

@Override
public void processQuery(@NotNull final ReferencesSearch.SearchParameters p, @NotNull Processor<PsiReference> consumer) {
    final PsiElement element = p.getElementToSearch();
    if (!(element instanceof PsiMethod)) {
        return;
    }
    final PsiMethod method = (PsiMethod) element;
    final PsiManager[] manager = new PsiManager[1];
    PsiClass aClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {

        @Override
        public PsiClass compute() {
            if (!method.isConstructor())
                return null;
            PsiClass aClass = method.getContainingClass();
            manager[0] = aClass == null ? null : aClass.getManager();
            return aClass;
        }
    });
    if (manager[0] == null) {
        return;
    }
    SearchScope scope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {

        @Override
        public SearchScope compute() {
            return p.getEffectiveSearchScope();
        }
    });
    new ConstructorReferencesSearchHelper(manager[0]).processConstructorReferences(consumer, method, aClass, scope, p.getProject(), p.isIgnoreAccessScope(), true, p.getOptimizer());
}
Also used : SearchScope(com.intellij.psi.search.SearchScope)

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