Search in sources :

Example 16 with ElementClassHint

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

the class GrTraitTypeDefinitionImpl method processDeclarations.

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    if (!super.processDeclarations(processor, state, lastParent, place))
        return false;
    ElementClassHint hint = processor.getHint(ElementClassHint.KEY);
    if (!ResolveUtil.shouldProcessMethods(hint) && !ResolveUtil.shouldProcessProperties(hint))
        return true;
    List<PsiClass> classes = GrTraitUtil.getSelfTypeClasses(this);
    for (PsiClass clazz : classes) {
        if (!clazz.processDeclarations(processor, state, lastParent, place))
            return false;
    }
    return true;
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint) PsiClass(com.intellij.psi.PsiClass)

Example 17 with ElementClassHint

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

the class GrAssignmentExpressionImpl method processDeclarations.

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
    final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    if (!ResolveUtil.shouldProcessProperties(classHint))
        return true;
    final DynamicMembersHint dynamicMembersHint = processor.getHint(DynamicMembersHint.KEY);
    if (dynamicMembersHint != null && !dynamicMembersHint.shouldProcessProperties())
        return true;
    if (!(getParent() instanceof GroovyFileImpl))
        return true;
    final GroovyFileImpl file = (GroovyFileImpl) getParent();
    if (!file.isInScriptBody(lastParent, place))
        return true;
    final GrExpression lValue = getLValue();
    if (!processLValue(processor, state, place, file, lValue))
        return false;
    if (lValue instanceof GrTupleExpression) {
        for (GrExpression expression : ((GrTupleExpression) lValue).getExpressions()) {
            if (!processLValue(processor, state, place, file, expression))
                return false;
        }
    }
    return true;
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint) GroovyFileImpl(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyFileImpl) DynamicMembersHint(org.jetbrains.plugins.groovy.lang.resolve.processors.DynamicMembersHint)

Example 18 with ElementClassHint

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

the class GrClassImplUtil method processDeclarations.

public static boolean processDeclarations(@NotNull GrTypeDefinition grType, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    if (place instanceof GrCodeReferenceElement && lastParent instanceof GrModifierList) {
        final PsiElement possibleAnnotation = PsiTreeUtil.skipParentsOfType(place, GrCodeReferenceElement.class);
        if (possibleAnnotation instanceof GrAnnotation && possibleAnnotation.getParent() == lastParent) {
            //don't process class members while resolving annotation which annotates current class
            return true;
        }
    }
    for (final PsiTypeParameter typeParameter : grType.getTypeParameters()) {
        if (!ResolveUtil.processElement(processor, typeParameter, state))
            return false;
    }
    NameHint nameHint = processor.getHint(NameHint.KEY);
    String name = nameHint == null ? null : nameHint.getName(state);
    ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    final PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
    final PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject());
    boolean processInstanceMethods = (ResolveUtil.shouldProcessMethods(classHint) || ResolveUtil.shouldProcessProperties(classHint)) && shouldProcessInstanceMembers(grType, lastParent);
    LanguageLevel level = PsiUtil.getLanguageLevel(place);
    if (ResolveUtil.shouldProcessProperties(classHint)) {
        Map<String, CandidateInfo> fieldsMap = CollectClassMembersUtil.getAllFields(grType);
        if (name != null) {
            CandidateInfo fieldInfo = fieldsMap.get(name);
            if (fieldInfo != null) {
                if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, fieldInfo)) {
                    return false;
                }
            } else if (grType.isTrait() && lastParent != null) {
                PsiField field = findFieldByName(grType, name, false, true);
                if (field != null && field.hasModifierProperty(PsiModifier.PUBLIC)) {
                    if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
                        return false;
                    }
                }
            }
        } else {
            for (CandidateInfo info : fieldsMap.values()) {
                if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, info)) {
                    return false;
                }
            }
            if (grType.isTrait() && lastParent != null) {
                for (PsiField field : CollectClassMembersUtil.getFields(grType, true)) {
                    if (field.hasModifierProperty(PsiModifier.PUBLIC)) {
                        if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    if (ResolveUtil.shouldProcessMethods(classHint)) {
        Map<String, List<CandidateInfo>> methodsMap = CollectClassMembersUtil.getAllMethods(grType, true);
        boolean isPlaceGroovy = place.getLanguage() == GroovyLanguage.INSTANCE;
        if (name == null) {
            for (List<CandidateInfo> list : methodsMap.values()) {
                for (CandidateInfo info : list) {
                    if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
                        return false;
                    }
                }
            }
        } else {
            List<CandidateInfo> byName = methodsMap.get(name);
            if (byName != null) {
                for (CandidateInfo info : byName) {
                    if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
                        return false;
                    }
                }
            }
        }
    }
    final GrTypeDefinitionBody body = grType.getBody();
    if (body != null) {
        if (ResolveUtil.shouldProcessClasses(classHint)) {
            for (PsiClass innerClass : getInnerClassesForResolve(grType, lastParent, place)) {
                if (name != null && !name.equals(innerClass.getName()))
                    continue;
                if (!processor.execute(innerClass, state))
                    return false;
            }
        }
    }
    return true;
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) ElementClassHint(com.intellij.psi.scope.ElementClassHint) CandidateInfo(com.intellij.psi.infos.CandidateInfo) GrTypeDefinitionBody(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) LanguageLevel(com.intellij.pom.java.LanguageLevel) GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrReferenceList(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList) NameHint(com.intellij.psi.scope.NameHint)

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