Search in sources :

Example 26 with SearchScope

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

the class SimpleAccessorReferenceSearcher method addPropertyAccessUsages.

static void addPropertyAccessUsages(@NotNull PsiMethod method, @NotNull SearchScope scope, @NotNull SearchRequestCollector collector) {
    final String propertyName = PropertyUtil.getPropertyName(method);
    if (StringUtil.isNotEmpty(propertyName)) {
        SearchScope additional = GlobalSearchScope.EMPTY_SCOPE;
        for (CustomPropertyScopeProvider provider : Extensions.getExtensions(CustomPropertyScopeProvider.EP_NAME)) {
            additional = additional.union(provider.getScope(method.getProject()));
        }
        SearchScope propScope = scope.intersectWith(method.getUseScope()).intersectWith(additional);
        collector.searchWord(propertyName, propScope, UsageSearchContext.IN_FOREIGN_LANGUAGES, true, method);
    }
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope)

Example 27 with SearchScope

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

the class VariableInIncompleteCodeSearcher method processQuery.

@Override
public void processQuery(@NotNull final ReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
    final PsiElement refElement = p.getElementToSearch();
    if (!refElement.isValid() || !(refElement instanceof PsiVariable))
        return;
    final String name = ((PsiVariable) refElement).getName();
    if (StringUtil.isEmptyOrSpaces(name))
        return;
    SearchScope scope = p.getEffectiveSearchScope();
    if (!(scope instanceof LocalSearchScope)) {
        final PsiFile file = refElement.getContainingFile();
        if (file == null || file instanceof PsiCompiledElement)
            return;
        //process incomplete references to the 'field' in the same file only
        scope = new LocalSearchScope(new PsiElement[] { file }, null, !PsiSearchHelperImpl.shouldProcessInjectedPsi(p.getScopeDeterminedByUser()));
    } else {
        PsiElement[] elements = ((LocalSearchScope) scope).getScope();
        PsiElement[] sourceElements = ContainerUtil.findAllAsArray(elements, e -> !(e instanceof PsiCompiledElement));
        if (sourceElements.length != elements.length) {
            if (sourceElements.length == 0)
                return;
            scope = new LocalSearchScope(sourceElements);
        }
    }
    PsiElement[] elements = ((LocalSearchScope) scope).getScope();
    if (elements.length == 0)
        return;
    PsiSearchHelper.SERVICE.getInstance(p.getProject()).processElementsWithWord((element, offsetInElement) -> {
        for (PsiElement child = element.findElementAt(offsetInElement); child != null; child = child.getParent()) {
            if (!child.textMatches(name)) {
                break;
            }
            if (child instanceof PsiJavaCodeReferenceElement) {
                final PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement) child;
                if (!ref.isQualified() && !(ref.getParent() instanceof PsiMethodCallExpression) && ref.resolve() == null && ref.advancedResolve(true).getElement() == refElement) {
                    consumer.process(ref);
                }
            }
        }
        return true;
    }, scope, name, UsageSearchContext.ANY, true);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope)

Example 28 with SearchScope

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

the class ResolveVariable15Test method testNavigateToEnumFunction.

public void testNavigateToEnumFunction() throws Exception {
    PsiElement element = resolveTarget();
    assertTrue(element instanceof PsiMethod);
    PsiClass aClass = ((PsiMethod) element).getContainingClass();
    assertTrue(aClass instanceof PsiEnumConstantInitializer);
    SearchScope scope = element.getUseScope();
    assertFalse(scope instanceof LocalSearchScope);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope)

Example 29 with SearchScope

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

the class SubtypesHierarchyTreeStructure method buildChildren.

@NotNull
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
    final Object element = ((TypeHierarchyNodeDescriptor) descriptor).getPsiClass();
    if (!(element instanceof PsiClass))
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    final PsiClass psiClass = (PsiClass) element;
    if (CommonClassNames.JAVA_LANG_OBJECT.equals(psiClass.getQualifiedName())) {
        return new Object[] { IdeBundle.message("node.hierarchy.java.lang.object") };
    }
    if (psiClass instanceof PsiAnonymousClass)
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    if (psiClass.hasModifierProperty(PsiModifier.FINAL))
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    final SearchScope searchScope = psiClass.getUseScope().intersectWith(getSearchScope(myCurrentScopeType, psiClass));
    final List<PsiClass> classes = new ArrayList<>(searchInheritors(psiClass, searchScope));
    final List<HierarchyNodeDescriptor> descriptors = new ArrayList<>(classes.size());
    for (PsiClass aClass : classes) {
        descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, aClass, false));
    }
    FunctionalExpressionSearch.search(psiClass, searchScope).forEach(expression -> {
        descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, expression, false));
        return true;
    });
    return descriptors.toArray(new HierarchyNodeDescriptor[descriptors.size()]);
}
Also used : PsiClass(com.intellij.psi.PsiClass) SearchScope(com.intellij.psi.search.SearchScope) ArrayList(java.util.ArrayList) PsiAnonymousClass(com.intellij.psi.PsiAnonymousClass) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with SearchScope

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

the class PsiClassImplUtil method getClassUseScope.

@NotNull
public static SearchScope getClassUseScope(@NotNull PsiClass aClass) {
    if (aClass instanceof PsiAnonymousClass) {
        return new LocalSearchScope(aClass);
    }
    final GlobalSearchScope maximalUseScope = ResolveScopeManager.getElementUseScope(aClass);
    PsiFile file = aClass.getContainingFile();
    if (PsiImplUtil.isInServerPage(file))
        return maximalUseScope;
    final PsiClass containingClass = aClass.getContainingClass();
    if (aClass.hasModifierProperty(PsiModifier.PUBLIC) || aClass.hasModifierProperty(PsiModifier.PROTECTED)) {
        return containingClass == null ? maximalUseScope : containingClass.getUseScope();
    } else if (aClass.hasModifierProperty(PsiModifier.PRIVATE) || aClass instanceof PsiTypeParameter) {
        PsiClass topClass = PsiUtil.getTopLevelClass(aClass);
        return new LocalSearchScope(topClass == null ? aClass.getContainingFile() : topClass);
    } else {
        PsiPackage aPackage = null;
        if (file instanceof PsiJavaFile) {
            aPackage = JavaPsiFacade.getInstance(aClass.getProject()).findPackage(((PsiJavaFile) file).getPackageName());
        }
        if (aPackage == null) {
            PsiDirectory dir = file.getContainingDirectory();
            if (dir != null) {
                aPackage = JavaDirectoryService.getInstance().getPackage(dir);
            }
        }
        if (aPackage != null) {
            SearchScope scope = PackageScope.packageScope(aPackage, false);
            scope = scope.intersectWith(maximalUseScope);
            return scope;
        }
        return new LocalSearchScope(file);
    }
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull)

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