Search in sources :

Example 1 with NameHint

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

the class GroovyShellCodeFragment method processVariables.

private boolean processVariables(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
    ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    if (!ResolveUtil.shouldProcessMethods(classHint) && !ResolveUtil.shouldProcessProperties(classHint)) {
        return true;
    }
    NameHint nameHint = processor.getHint(NameHint.KEY);
    String name = nameHint != null ? nameHint.getName(state) : null;
    if (name != null) {
        final PsiVariable var = myVariables.get(name);
        if (var != null) {
            if (processor.execute(var, state)) {
                return false;
            }
        }
    } else {
        for (PsiVariable var : myVariables.values()) {
            if (!processor.execute(var, state)) {
                return false;
            }
        }
    }
    return true;
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint)

Example 2 with NameHint

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

the class GroovyShellCodeFragment method processTypeDefinitions.

private boolean processTypeDefinitions(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
    ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    if (!ResolveUtil.shouldProcessClasses(classHint)) {
        return true;
    }
    NameHint nameHint = processor.getHint(NameHint.KEY);
    String name = nameHint != null ? nameHint.getName(state) : null;
    if (name != null) {
        final GrTypeDefinition definition = myTypeDefinitions.get(name);
        if (definition != null) {
            if (processor.execute(definition, state)) {
                return false;
            }
        }
    } else {
        for (GrTypeDefinition definition : myTypeDefinitions.values()) {
            if (!processor.execute(definition, state)) {
                return false;
            }
        }
    }
    return true;
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) ElementClassHint(com.intellij.psi.scope.ElementClassHint) NameHint(com.intellij.psi.scope.NameHint)

Example 3 with NameHint

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

the class PsiClassImplUtil method processDeclarationsInClass.

private static boolean processDeclarationsInClass(@NotNull PsiClass aClass, @NotNull final PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable Set<PsiClass> visited, PsiElement last, @NotNull PsiElement place, @NotNull LanguageLevel languageLevel, boolean isRaw, @NotNull GlobalSearchScope resolveScope) {
    if (last instanceof PsiTypeParameterList || last instanceof PsiModifierList && aClass.getModifierList() == last) {
        return true;
    }
    if (visited != null && visited.contains(aClass))
        return true;
    PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
    isRaw = isRaw || PsiUtil.isRawSubstitutor(aClass, substitutor);
    final NameHint nameHint = processor.getHint(NameHint.KEY);
    if (nameHint != null) {
        String name = nameHint.getName(state);
        return processCachedMembersByName(aClass, processor, state, visited, last, place, isRaw, substitutor, getValues(aClass).getValue(aClass).get(resolveScope), name, languageLevel);
    }
    return processDeclarationsInClassNotCached(aClass, processor, state, visited, last, place, isRaw, languageLevel, resolveScope);
}
Also used : NameHint(com.intellij.psi.scope.NameHint)

Example 4 with NameHint

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

the class PsiClassImplUtil method processDeclarationsInClassNotCached.

private static boolean processDeclarationsInClassNotCached(@NotNull PsiClass aClass, @NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, @Nullable Set<PsiClass> visited, final PsiElement last, @NotNull final PsiElement place, final boolean isRaw, @NotNull final LanguageLevel languageLevel, @NotNull final GlobalSearchScope resolveScope) {
    if (visited == null)
        visited = new THashSet<>();
    if (!visited.add(aClass))
        return true;
    processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, aClass);
    final ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
    final NameHint nameHint = processor.getHint(NameHint.KEY);
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.FIELD)) {
        if (nameHint != null) {
            final PsiField fieldByName = aClass.findFieldByName(nameHint.getName(state), false);
            if (fieldByName != null && !processor.execute(fieldByName, state))
                return false;
        } else {
            final PsiField[] fields = aClass.getFields();
            for (final PsiField field : fields) {
                if (!processor.execute(field, state))
                    return false;
            }
        }
    }
    PsiElementFactory factory = JavaPsiFacade.getInstance(aClass.getProject()).getElementFactory();
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.METHOD)) {
        PsiSubstitutor baseSubstitutor = state.get(PsiSubstitutor.KEY);
        final PsiMethod[] methods = nameHint != null ? aClass.findMethodsByName(nameHint.getName(state), false) : aClass.getMethods();
        for (final PsiMethod method : methods) {
            PsiSubstitutor finalSubstitutor = checkRaw(isRaw, factory, method, baseSubstitutor);
            ResolveState methodState = finalSubstitutor == baseSubstitutor ? state : state.put(PsiSubstitutor.KEY, finalSubstitutor);
            if (!processor.execute(method, methodState))
                return false;
        }
    }
    if (classHint == null || classHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
        if (last != null && last.getContext() == aClass) {
            // Parameters
            final PsiTypeParameterList list = aClass.getTypeParameterList();
            if (list != null && !list.processDeclarations(processor, ResolveState.initial(), last, place))
                return false;
        }
        if (!(last instanceof PsiReferenceList) && !(last instanceof PsiModifierList)) {
            // Inners
            if (nameHint != null) {
                final PsiClass inner = aClass.findInnerClassByName(nameHint.getName(state), false);
                if (inner != null) {
                    if (!processor.execute(inner, state))
                        return false;
                }
            } else {
                final PsiClass[] inners = aClass.getInnerClasses();
                for (final PsiClass inner : inners) {
                    if (!processor.execute(inner, state))
                        return false;
                }
            }
        }
    }
    if (last instanceof PsiReferenceList)
        return true;
    final Set<PsiClass> visited1 = visited;
    return processSuperTypes(aClass, state.get(PsiSubstitutor.KEY), factory, languageLevel, resolveScope, (superClass, finalSubstitutor) -> processDeclarationsInClass(superClass, processor, state.put(PsiSubstitutor.KEY, finalSubstitutor), visited1, last, place, languageLevel, isRaw, resolveScope));
}
Also used : ElementClassHint(com.intellij.psi.scope.ElementClassHint) THashSet(gnu.trove.THashSet) NameHint(com.intellij.psi.scope.NameHint)

Example 5 with NameHint

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

the class GroovyCodeFragment method processSingleImports.

private boolean processSingleImports(PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, PsiElement place, Boolean processStatic) {
    if (processStatic == null)
        return processSingleImports(processor, state, lastParent, place, false) && processSingleImports(processor, state, lastParent, place, true);
    NameHint nameHint = processor.getHint(NameHint.KEY);
    String name = nameHint != null ? nameHint.getName(state) : null;
    if (name != null) {
        final GrImportStatement anImport = myPseudoImports.get(name);
        if (anImport != null && processStatic == anImport.isStatic()) {
            if (!anImport.processDeclarations(processor, state, lastParent, place)) {
                return false;
            }
        }
    } else {
        for (GrImportStatement anImport : myPseudoImports.values()) {
            if (processStatic != anImport.isStatic())
                continue;
            if (!anImport.processDeclarations(processor, state, lastParent, place)) {
                return false;
            }
        }
    }
    return true;
}
Also used : NameHint(com.intellij.psi.scope.NameHint) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)

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