Search in sources :

Example 1 with ModifierFilter

use of com.intellij.psi.filters.element.ModifierFilter 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)

Aggregations

ModifierFilter (com.intellij.psi.filters.element.ModifierFilter)1 FilterScopeProcessor (com.intellij.psi.scope.processor.FilterScopeProcessor)1