Search in sources :

Example 11 with NameHint

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

the class PsiCodeFragmentImpl 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 (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
        final NameHint nameHint = processor.getHint(NameHint.KEY);
        final String name = nameHint != null ? nameHint.getName(state) : null;
        if (name != null) {
            String qNameImported = myPseudoImports.get(name);
            if (qNameImported != null) {
                PsiClass imported = JavaPsiFacade.getInstance(myManager.getProject()).findClass(qNameImported, getResolveScope());
                if (imported != null) {
                    if (!processor.execute(imported, state))
                        return false;
                }
            }
        } else {
            for (String qNameImported : myPseudoImports.values()) {
                PsiClass aClass = JavaPsiFacade.getInstance(myManager.getProject()).findClass(qNameImported, getResolveScope());
                if (aClass != null) {
                    if (!processor.execute(aClass, state))
                        return false;
                }
            }
        }
        if (myContext == null) {
            return JavaResolveUtil.processImplicitlyImportedPackages(processor, state, place, getManager());
        }
    }
    IElementType i = myContentElementType;
    if (i == JavaElementType.TYPE_WITH_CONJUNCTIONS_TEXT || i == JavaElementType.TYPE_WITH_DISJUNCTIONS_TEXT || i == JavaElementType.EXPRESSION_STATEMENT || i == JavaElementType.REFERENCE_TEXT) {
        return true;
    } else {
        processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
        if (lastParent == null) {
            // Parent element should not see our vars
            return true;
        }
        return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint)

Example 12 with NameHint

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

the class PsiCodeBlockImpl 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);
    if (lastParent == null) {
        // Parent element should not see our vars
        return true;
    }
    Couple<Set<String>> pair = buildMaps();
    boolean conflict = pair == null;
    final Set<String> classesSet = conflict ? null : pair.getFirst();
    final Set<String> variablesSet = conflict ? null : pair.getSecond();
    final NameHint hint = processor.getHint(NameHint.KEY);
    if (hint != null && !conflict) {
        final ElementClassHint elementClassHint = processor.getHint(ElementClassHint.KEY);
        final String name = hint.getName(state);
        if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) && classesSet.contains(name)) {
            return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
        }
        if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.VARIABLE)) && variablesSet.contains(name)) {
            return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
        }
    } else {
        return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    }
    return true;
}
Also used : Set(java.util.Set) THashSet(gnu.trove.THashSet) ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint)

Example 13 with NameHint

use of com.intellij.psi.scope.NameHint in project android by JetBrains.

the class LightBindingClass method processDeclarations.

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
    boolean continueProcessing = super.processDeclarations(processor, state, lastParent, place);
    if (!continueProcessing) {
        return false;
    }
    List<PsiDataBindingResourceItem> imports = myInfo.getItems(DataBindingResourceType.IMPORT);
    if (imports.isEmpty()) {
        return true;
    }
    final 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;
        for (PsiDataBindingResourceItem imp : imports) {
            String alias = imp.getExtra(SdkConstants.ATTR_ALIAS);
            if (alias != null) {
                // aliases are pre-resolved in {@linkplain #replaceImportAliases}
                continue;
            }
            String qName = imp.getExtra(SdkConstants.ATTR_TYPE);
            if (qName == null) {
                continue;
            }
            if (name != null && !qName.endsWith("." + name)) {
                continue;
            }
            Module module = myInfo.getModule();
            if (module == null) {
                // this should not really happen but just to be safe
                return true;
            }
            PsiClass aClass = JavaPsiFacade.getInstance(myManager.getProject()).findClass(qName, module.getModuleWithDependenciesAndLibrariesScope(true));
            if (aClass != null) {
                if (!processor.execute(aClass, state)) {
                    // found it!
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : PsiDataBindingResourceItem(com.android.tools.idea.res.PsiDataBindingResourceItem) ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint) Module(com.intellij.openapi.module.Module)

Example 14 with NameHint

use of com.intellij.psi.scope.NameHint 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)

Example 15 with NameHint

use of com.intellij.psi.scope.NameHint 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)

Aggregations

NameHint (com.intellij.psi.scope.NameHint)16 ElementClassHint (com.intellij.psi.scope.ElementClassHint)10 THashSet (gnu.trove.THashSet)2 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)2 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)2 PsiDataBindingResourceItem (com.android.tools.idea.res.PsiDataBindingResourceItem)1 Module (com.intellij.openapi.module.Module)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 CandidateInfo (com.intellij.psi.infos.CandidateInfo)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 IElementType (com.intellij.psi.tree.IElementType)1 Set (java.util.Set)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 GrReferenceList (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList)1 GrTypeDefinitionBody (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody)1 GrGdkMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod)1 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)1 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)1