Search in sources :

Example 11 with ElementClassHint

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

the class ClsFileImpl method processDeclarations.

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
    processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
    final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
        final PsiClass[] classes = getClasses();
        for (PsiClass aClass : classes) {
            if (!processor.execute(aClass, state))
                return false;
        }
    }
    return true;
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint)

Example 12 with ElementClassHint

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

the class PsiPackageImpl method processDeclarations.

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
    GlobalSearchScope scope = place.getResolveScope();
    processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
    ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    final Condition<String> nameCondition = processor.getHint(JavaCompletionHints.NAME_FILTER);
    NameHint providedNameHint = processor.getHint(NameHint.KEY);
    final String providedName = providedNameHint == null ? null : providedNameHint.getName(state);
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
        if (providedName != null) {
            final PsiClass[] classes = findClassByShortName(providedName, scope);
            if (!processClasses(processor, state, classes, Conditions.alwaysTrue()))
                return false;
        } else {
            PsiClass[] classes = getClasses(scope);
            if (!processClasses(processor, state, classes, nameCondition != null ? nameCondition : Conditions.alwaysTrue()))
                return false;
        }
    }
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.PACKAGE)) {
        if (providedName != null) {
            PsiPackage aPackage = findSubPackageByName(providedName);
            if (aPackage != null) {
                if (!processor.execute(aPackage, state))
                    return false;
            }
        } else {
            PsiPackage[] packs = getSubPackages(scope);
            for (PsiPackage pack : packs) {
                final String packageName = pack.getName();
                if (packageName == null)
                    continue;
                if (!PsiNameHelper.getInstance(myManager.getProject()).isIdentifier(packageName, PsiUtil.getLanguageLevel(this))) {
                    continue;
                }
                if (!processor.execute(pack, state)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint)

Example 13 with ElementClassHint

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

the class JavaDummyHolder method processDeclarations.

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
    ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
        final NameHint nameHint = processor.getHint(NameHint.KEY);
        final String name = nameHint != null ? nameHint.getName(state) : null;
        //"pseudo-imports"
        if (name != null) {
            PsiClass imported = myPseudoImports.get(name);
            if (imported != null) {
                if (!processor.execute(imported, state))
                    return false;
            }
        } else {
            for (PsiClass aClass : myPseudoImports.values()) {
                if (!processor.execute(aClass, state))
                    return false;
            }
        }
        if (getContext() == null) {
            if (!JavaResolveUtil.processImplicitlyImportedPackages(processor, state, place, getManager()))
                return false;
        }
    }
    return true;
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint)

Example 14 with ElementClassHint

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

the class PsiClassImplUtil method processCachedMembersByName.

private static boolean processCachedMembersByName(@NotNull final PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable Set<PsiClass> visited, PsiElement last, @NotNull final PsiElement place, final boolean isRaw, @NotNull final PsiSubstitutor substitutor, @NotNull MembersMap value, String name, @NotNull final LanguageLevel languageLevel) {
    Function<PsiMember, PsiSubstitutor> finalSubstitutor = new Function<PsiMember, PsiSubstitutor>() {

        final ScopedClassHierarchy hierarchy = ScopedClassHierarchy.getHierarchy(aClass, place.getResolveScope());

        final PsiElementFactory factory = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory();

        @Override
        public PsiSubstitutor fun(PsiMember member) {
            PsiClass containingClass = ObjectUtils.assertNotNull(member.getContainingClass());
            PsiSubstitutor superSubstitutor = hierarchy.getSuperMembersSubstitutor(containingClass, languageLevel);
            PsiSubstitutor finalSubstitutor = obtainFinalSubstitutor(containingClass, superSubstitutor == null ? PsiSubstitutor.EMPTY : superSubstitutor, aClass, substitutor, factory, languageLevel);
            return member instanceof PsiMethod ? checkRaw(isRaw, factory, (PsiMethod) member, finalSubstitutor) : finalSubstitutor;
        }
    };
    final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.FIELD)) {
        final PsiField fieldByName = aClass.findFieldByName(name, false);
        if (fieldByName != null) {
            processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, aClass);
            if (!processor.execute(fieldByName, state))
                return false;
        } else {
            final Map<String, PsiMember[]> allFieldsMap = value.get(MemberType.FIELD);
            final PsiMember[] list = allFieldsMap.get(name);
            if (list != null) {
                boolean resolved = false;
                for (final PsiMember candidateField : list) {
                    PsiClass containingClass = candidateField.getContainingClass();
                    if (containingClass == null) {
                        LOG.error("No class for field " + candidateField.getName() + " of " + candidateField.getClass());
                        continue;
                    }
                    processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, containingClass);
                    if (!processor.execute(candidateField, state.put(PsiSubstitutor.KEY, finalSubstitutor.fun(candidateField)))) {
                        resolved = true;
                    }
                }
                if (resolved)
                    return false;
            }
        }
    }
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
        if (last != null && last.getContext() == aClass) {
            if (last instanceof PsiClass) {
                if (!processor.execute(last, state))
                    return false;
            }
            // Parameters
            final PsiTypeParameterList list = aClass.getTypeParameterList();
            if (list != null && !list.processDeclarations(processor, state, last, place))
                return false;
        }
        if (!(last instanceof PsiReferenceList)) {
            final PsiClass classByName = aClass.findInnerClassByName(name, false);
            if (classByName != null) {
                processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, aClass);
                if (!processor.execute(classByName, state))
                    return false;
            } else {
                Map<String, PsiMember[]> allClassesMap = value.get(MemberType.CLASS);
                PsiMember[] list = allClassesMap.get(name);
                if (list != null) {
                    boolean resolved = false;
                    for (final PsiMember inner : list) {
                        PsiClass containingClass = inner.getContainingClass();
                        if (containingClass != null) {
                            processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, containingClass);
                            if (!processor.execute(inner, state.put(PsiSubstitutor.KEY, finalSubstitutor.fun(inner)))) {
                                resolved = true;
                            }
                        }
                    }
                    if (resolved)
                        return false;
                }
            }
        }
    }
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.METHOD)) {
        if (processor instanceof MethodResolverProcessor) {
            final MethodResolverProcessor methodResolverProcessor = (MethodResolverProcessor) processor;
            if (methodResolverProcessor.isConstructor()) {
                final PsiMethod[] constructors = aClass.getConstructors();
                methodResolverProcessor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, aClass);
                for (PsiMethod constructor : constructors) {
                    if (!methodResolverProcessor.execute(constructor, state))
                        return false;
                }
                return true;
            }
        }
        Map<String, PsiMember[]> allMethodsMap = value.get(MemberType.METHOD);
        PsiMember[] list = allMethodsMap.get(name);
        if (list != null) {
            boolean resolved = false;
            for (final PsiMember candidate : list) {
                ProgressIndicatorProvider.checkCanceled();
                PsiMethod candidateMethod = (PsiMethod) candidate;
                if (processor instanceof MethodResolverProcessor) {
                    if (candidateMethod.isConstructor() != ((MethodResolverProcessor) processor).isConstructor())
                        continue;
                }
                final PsiClass containingClass = candidateMethod.getContainingClass();
                if (containingClass == null || visited != null && visited.contains(containingClass)) {
                    continue;
                }
                processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, containingClass);
                if (!processor.execute(candidateMethod, state.put(PsiSubstitutor.KEY, finalSubstitutor.fun(candidateMethod)))) {
                    resolved = true;
                }
            }
            if (resolved)
                return false;
            if (visited != null) {
                for (PsiMember aList : list) {
                    visited.add(aList.getContainingClass());
                }
            }
        }
    }
    return true;
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint) MethodResolverProcessor(com.intellij.psi.scope.processor.MethodResolverProcessor)

Example 15 with ElementClassHint

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

the class DynamicMemberUtils method process.

public static boolean process(PsiScopeProcessor processor, boolean isInStaticContext, PsiElement place, String classSource) {
    ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    String name = ResolveUtil.getNameHint(processor);
    ClassMemberHolder memberHolder = getMembers(place.getProject(), classSource);
    if (ResolveUtil.shouldProcessMethods(classHint)) {
        PsiMethod[] methods = isInStaticContext ? memberHolder.getStaticMethods(name) : memberHolder.getMethods(name);
        for (PsiMethod method : methods) {
            if (!processor.execute(method, ResolveState.initial()))
                return false;
        }
    }
    if (ResolveUtil.shouldProcessProperties(classHint)) {
        PsiField[] fields = isInStaticContext ? memberHolder.getStaticFields(name) : memberHolder.getFields(name);
        for (PsiField field : fields) {
            if (!processor.execute(field, ResolveState.initial()))
                return false;
        }
    }
    return true;
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint)

Aggregations

ElementClassHint (com.intellij.psi.scope.ElementClassHint)18 NameHint (com.intellij.psi.scope.NameHint)10 THashSet (gnu.trove.THashSet)2 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)2 PsiDataBindingResourceItem (com.android.tools.idea.res.PsiDataBindingResourceItem)1 Module (com.intellij.openapi.module.Module)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 PsiClass (com.intellij.psi.PsiClass)1 CandidateInfo (com.intellij.psi.infos.CandidateInfo)1 MethodResolverProcessor (com.intellij.psi.scope.processor.MethodResolverProcessor)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 IElementType (com.intellij.psi.tree.IElementType)1 Set (java.util.Set)1 CanonicallyNamed (org.elixir_lang.psi.call.CanonicallyNamed)1 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)1 GrAnnotation (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrReferenceList (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList)1 GrTypeDefinitionBody (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1