Search in sources :

Example 1 with FilterScopeProcessor

use of com.intellij.psi.scope.processor.FilterScopeProcessor in project intellij-community by JetBrains.

the class PsiMethodReferenceExpressionImpl method processVariants.

@Override
public void processVariants(@NotNull final PsiScopeProcessor processor) {
    final FilterScopeProcessor proc = new FilterScopeProcessor(ElementClassFilter.METHOD, processor);
    PsiScopesUtil.resolveAndWalk(proc, this, null, true);
}
Also used : FilterScopeProcessor(com.intellij.psi.scope.processor.FilterScopeProcessor)

Example 2 with FilterScopeProcessor

use of com.intellij.psi.scope.processor.FilterScopeProcessor in project intellij-community by JetBrains.

the class PsiImplUtil method getReferenceVariantsByFilter.

@NotNull
public static Object[] getReferenceVariantsByFilter(@NotNull PsiJavaCodeReferenceElement reference, @NotNull ElementFilter filter) {
    FilterScopeProcessor processor = new FilterScopeProcessor(filter);
    PsiScopesUtil.resolveAndWalk(processor, reference, null, true);
    return processor.getResults().toArray();
}
Also used : FilterScopeProcessor(com.intellij.psi.scope.processor.FilterScopeProcessor) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with FilterScopeProcessor

use of com.intellij.psi.scope.processor.FilterScopeProcessor in project intellij-community by JetBrains.

the class PsiJavaCodeReferenceElementImpl method processVariants.

@Override
public void processVariants(@NotNull final PsiScopeProcessor processor) {
    final OrFilter filter = new OrFilter();
    if (isInCode() && !(getParent() instanceof PsiImportStatement) && !(getParent() instanceof PsiReferenceList)) {
        filter.addFilter(new AndFilter(ElementClassFilter.METHOD, new NotFilter(new ConstructorFilter())));
        filter.addFilter(ElementClassFilter.VARIABLE);
    }
    switch(getKind(getContainingFile())) {
        case CLASS_OR_PACKAGE_NAME_KIND:
            filter.addFilter(ElementClassFilter.CLASS);
            filter.addFilter(ElementClassFilter.PACKAGE_FILTER);
            break;
        case CLASS_NAME_KIND:
            filter.addFilter(ElementClassFilter.CLASS);
            if (isQualified()) {
                filter.addFilter(ElementClassFilter.PACKAGE_FILTER);
            }
            break;
        case PACKAGE_NAME_KIND:
            filter.addFilter(ElementClassFilter.PACKAGE_FILTER);
            break;
        case CLASS_FQ_NAME_KIND:
        case CLASS_FQ_OR_PACKAGE_NAME_KIND:
            filter.addFilter(ElementClassFilter.PACKAGE_FILTER);
            if (isQualified()) {
                filter.addFilter(ElementClassFilter.CLASS);
            }
            break;
        case CLASS_IN_QUALIFIED_NEW_KIND:
            final PsiElement parent = getParent();
            if (parent instanceof PsiNewExpression) {
                PsiExpression qualifier = ((PsiNewExpression) parent).getQualifier();
                assert qualifier != null : parent;
                PsiType type = qualifier.getType();
                PsiClass aClass = PsiUtil.resolveClassInType(type);
                if (aClass != null) {
                    aClass.processDeclarations(new FilterScopeProcessor(new AndFilter(ElementClassFilter.CLASS, new ModifierFilter(PsiModifier.STATIC, false)), processor), ResolveState.initial(), null, this);
                }
            }
            return;
        default:
            throw new RuntimeException("Unknown reference type");
    }
    final FilterScopeProcessor proc = new FilterScopeProcessor(filter, processor);
    PsiScopesUtil.resolveAndWalk(proc, this, null, true);
}
Also used : FilterScopeProcessor(com.intellij.psi.scope.processor.FilterScopeProcessor) ModifierFilter(com.intellij.psi.filters.element.ModifierFilter)

Example 4 with FilterScopeProcessor

use of com.intellij.psi.scope.processor.FilterScopeProcessor in project intellij-community by JetBrains.

the class PsiImportStaticReferenceElementImpl method processVariants.

@Override
public void processVariants(@NotNull PsiScopeProcessor processor) {
    FilterScopeProcessor proc = new FilterScopeProcessor(new ClassFilter(PsiModifierListOwner.class), processor);
    PsiScopesUtil.resolveAndWalk(proc, this, null, true);
}
Also used : ClassFilter(com.intellij.psi.filters.ClassFilter) FilterScopeProcessor(com.intellij.psi.scope.processor.FilterScopeProcessor)

Example 5 with FilterScopeProcessor

use of com.intellij.psi.scope.processor.FilterScopeProcessor in project intellij-community by JetBrains.

the class MembersGetter method processMembers.

public void processMembers(final Consumer<LookupElement> results, @Nullable final PsiClass where, final boolean acceptMethods, final boolean searchInheritors) {
    if (where == null || isPrimitiveClass(where))
        return;
    final boolean searchFactoryMethods = searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName()) && !isPrimitiveClass(where);
    final Project project = myPlace.getProject();
    final GlobalSearchScope scope = myPlace.getResolveScope();
    final PsiClassType baseType = JavaPsiFacade.getElementFactory(project).createType(where);
    Consumer<PsiType> consumer = psiType -> {
        PsiClass psiClass = PsiUtil.resolveClassInType(psiType);
        if (psiClass == null) {
            return;
        }
        psiClass = CompletionUtil.getOriginalOrSelf(psiClass);
        if (mayProcessMembers(psiClass)) {
            final FilterScopeProcessor<PsiElement> declProcessor = new FilterScopeProcessor<>(TrueFilter.INSTANCE);
            psiClass.processDeclarations(declProcessor, ResolveState.initial(), null, myPlace);
            doProcessMembers(acceptMethods, results, psiType == baseType, declProcessor.getResults());
            String name = psiClass.getName();
            if (name != null && searchFactoryMethods) {
                Collection<PsiMember> factoryMethods = JavaStaticMemberTypeIndex.getInstance().getStaticMembers(name, project, scope);
                doProcessMembers(acceptMethods, results, false, factoryMethods);
            }
        }
    };
    consumer.consume(baseType);
    if (searchInheritors && !CommonClassNames.JAVA_LANG_OBJECT.equals(where.getQualifiedName())) {
        CodeInsightUtil.processSubTypes(baseType, myPlace, true, PrefixMatcher.ALWAYS_TRUE, consumer);
    }
}
Also used : JavaStaticMemberTypeIndex(com.intellij.psi.impl.java.stubs.index.JavaStaticMemberTypeIndex) java.util(java.util) LookupElement(com.intellij.codeInsight.lookup.LookupElement) TrueFilter(com.intellij.psi.filters.TrueFilter) Key(com.intellij.openapi.util.Key) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PairConsumer(com.intellij.util.PairConsumer) CodeInsightUtil(com.intellij.codeInsight.CodeInsightUtil) AutoCompletionPolicy(com.intellij.codeInsight.lookup.AutoCompletionPolicy) Nullable(org.jetbrains.annotations.Nullable) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) JavaCompletionUtil(com.intellij.codeInsight.completion.JavaCompletionUtil) InheritanceUtil(com.intellij.psi.util.InheritanceUtil) Project(com.intellij.openapi.project.Project) PsiUtil(com.intellij.psi.util.PsiUtil) PrefixMatcher(com.intellij.codeInsight.completion.PrefixMatcher) com.intellij.psi(com.intellij.psi) FilterScopeProcessor(com.intellij.psi.scope.processor.FilterScopeProcessor) NotNull(org.jetbrains.annotations.NotNull) CompletionUtil(com.intellij.codeInsight.completion.CompletionUtil) Consumer(com.intellij.util.Consumer) StaticMemberProcessor(com.intellij.codeInsight.completion.StaticMemberProcessor) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FilterScopeProcessor(com.intellij.psi.scope.processor.FilterScopeProcessor)

Aggregations

FilterScopeProcessor (com.intellij.psi.scope.processor.FilterScopeProcessor)5 NotNull (org.jetbrains.annotations.NotNull)2 CodeInsightUtil (com.intellij.codeInsight.CodeInsightUtil)1 CompletionUtil (com.intellij.codeInsight.completion.CompletionUtil)1 JavaCompletionUtil (com.intellij.codeInsight.completion.JavaCompletionUtil)1 PrefixMatcher (com.intellij.codeInsight.completion.PrefixMatcher)1 StaticMemberProcessor (com.intellij.codeInsight.completion.StaticMemberProcessor)1 AutoCompletionPolicy (com.intellij.codeInsight.lookup.AutoCompletionPolicy)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 Project (com.intellij.openapi.project.Project)1 Key (com.intellij.openapi.util.Key)1 com.intellij.psi (com.intellij.psi)1 ClassFilter (com.intellij.psi.filters.ClassFilter)1 TrueFilter (com.intellij.psi.filters.TrueFilter)1 ModifierFilter (com.intellij.psi.filters.element.ModifierFilter)1 JavaStaticMemberTypeIndex (com.intellij.psi.impl.java.stubs.index.JavaStaticMemberTypeIndex)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 InheritanceUtil (com.intellij.psi.util.InheritanceUtil)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 PsiUtil (com.intellij.psi.util.PsiUtil)1