Search in sources :

Example 6 with PsiScopeProcessor

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

the class GrUnresolvedAccessChecker method doCheckContainer.

private static boolean doCheckContainer(final PsiMethod patternMethod, PsiElement container, final String name) {
    final Ref<Boolean> result = new Ref<>(false);
    PsiScopeProcessor processor = new GrScopeProcessorWithHints(name, ClassHint.RESOLVE_KINDS_METHOD) {

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            if (element instanceof PsiMethod && name.equals(((PsiMethod) element).getName()) && patternMethod.getParameterList().getParametersCount() == ((PsiMethod) element).getParameterList().getParametersCount() && isNotFromGroovyObject((PsiMethod) element)) {
                result.set(true);
                return false;
            }
            return true;
        }
    };
    ResolveUtil.treeWalkUp(container, processor, true);
    return result.get();
}
Also used : Ref(com.intellij.openapi.util.Ref) GrScopeProcessorWithHints(org.jetbrains.plugins.groovy.lang.resolve.processors.GrScopeProcessorWithHints) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) NotNull(org.jetbrains.annotations.NotNull) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement)

Example 7 with PsiScopeProcessor

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

the class GroovyFileImpl method processCachedDeclarations.

private static boolean processCachedDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, MostlySingularMultiMap<String, ResultWithContext> cache) {
    for (PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
        String name = ResolveUtil.getNameHint(each);
        Processor<ResultWithContext> cacheProcessor = res -> each.execute(res.getElement(), state.put(ClassHint.RESOLVE_CONTEXT, res.getFileContext()));
        boolean result = name != null ? cache.processForKey(name, cacheProcessor) : cache.processAllValues(cacheProcessor);
        if (!result)
            return false;
    }
    return true;
}
Also used : ResultWithContext(com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor.ResultWithContext) GrFileStub(org.jetbrains.plugins.groovy.lang.psi.stubs.GrFileStub) ImportKind(org.jetbrains.plugins.groovy.lang.psi.impl.GroovyImportHelper.ImportKind) ElementClassHint(com.intellij.psi.scope.ElementClassHint) GrPackageDefinition(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition) GrPackageDefinitionStub(org.jetbrains.plugins.groovy.lang.psi.stubs.GrPackageDefinitionStub) GroovyLanguage(org.jetbrains.plugins.groovy.GroovyLanguage) PackageSkippingProcessor(org.jetbrains.plugins.groovy.lang.resolve.PackageSkippingProcessor) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) ResolveUtil(org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil) ContainerUtil(com.intellij.util.containers.ContainerUtil) GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrTopStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.GrTopStatement) ConcurrentMap(java.util.concurrent.ConcurrentMap) MostlySingularMultiMap(com.intellij.util.containers.MostlySingularMultiMap) Logger(com.intellij.openapi.diagnostic.Logger) NameHint(com.intellij.psi.scope.NameHint) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GroovyTokenTypes(org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes) GroovyElementTypes(org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) GroovyResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.GroovyResolverProcessor) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GrLightParameter(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightParameter) PsiFileEx(com.intellij.psi.impl.PsiFileEx) IncorrectOperationException(com.intellij.util.IncorrectOperationException) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.psi.util(com.intellij.psi.util) BaseScopeProcessor(com.intellij.psi.scope.BaseScopeProcessor) GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) ClassHint(org.jetbrains.plugins.groovy.lang.resolve.processors.ClassHint) MethodTypeInferencer(org.jetbrains.plugins.groovy.lang.resolve.MethodTypeInferencer) GrBindingVariable(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrBindingVariable) ImplicitImportsKt(org.jetbrains.plugins.groovy.lang.resolve.ImplicitImportsKt) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) com.intellij.psi(com.intellij.psi) StubElement(com.intellij.psi.stubs.StubElement) NotNull(org.jetbrains.annotations.NotNull) ResultWithContext(com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor.ResultWithContext) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor)

Example 8 with PsiScopeProcessor

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

the class GrImportStatementImpl method processSingleStaticImport.

private boolean processSingleStaticImport(@NotNull final PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull String importedName, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    final GrCodeReferenceElement ref = getImportReference();
    if (ref == null)
        return true;
    PsiClass clazz = resolveQualifier();
    if (clazz == null)
        return true;
    state = state.put(ClassHint.RESOLVE_CONTEXT, this);
    final String refName = ref.getReferenceName();
    for (PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
        if (!doProcessSingleStaticImport(each, state, importedName, lastParent, place, clazz, refName))
            return false;
    }
    return true;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor)

Example 9 with PsiScopeProcessor

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

the class GrImportStatementImpl method processDeclarationsForMultipleElements.

private boolean processDeclarationsForMultipleElements(@NotNull final PsiScopeProcessor processor, @Nullable PsiElement lastParent, @NotNull PsiElement place, @NotNull ResolveState state) {
    GrCodeReferenceElement ref = getImportReference();
    if (ref == null)
        return true;
    if (isStatic()) {
        final PsiElement resolved = ref.resolve();
        if (resolved instanceof PsiClass) {
            state = state.put(ClassHint.RESOLVE_CONTEXT, this);
            final PsiClass clazz = (PsiClass) resolved;
            for (final PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
                if (!clazz.processDeclarations(new DelegatingScopeProcessor(each) {

                    @Override
                    public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
                        if (element instanceof PsiMember && ((PsiMember) element).hasModifierProperty(PsiModifier.STATIC)) {
                            return super.execute(element, state);
                        }
                        return true;
                    }
                }, state, lastParent, place))
                    return false;
            }
        }
    } else {
        if (ResolveUtil.shouldProcessClasses(processor.getHint(ElementClassHint.KEY))) {
            String qName = PsiUtil.getQualifiedReferenceText(ref);
            if (qName != null) {
                PsiPackage aPackage = JavaPsiFacade.getInstance(getProject()).findPackage(qName);
                if (aPackage != null && !((GroovyFile) getContainingFile()).getPackageName().equals(aPackage.getQualifiedName())) {
                    state = state.put(ClassHint.RESOLVE_CONTEXT, this);
                    if (!aPackage.processDeclarations(processor, state, lastParent, place))
                        return false;
                }
            }
        }
    }
    return true;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) DelegatingScopeProcessor(com.intellij.psi.scope.DelegatingScopeProcessor) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with PsiScopeProcessor

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

the class PatternEditorContextMembersProvider method processDynamicElements.

@Override
public void processDynamicElements(@NotNull PsiType qualifierType, @NotNull final PsiScopeProcessor scopeProcessor, @NotNull final PsiElement place, @NotNull final ResolveState state) {
    final PsiFile file = place.getContainingFile().getOriginalFile();
    final BaseInjection injection = file.getUserData(BaseInjection.INJECTION_KEY);
    Processor<PsiElement> processor = element -> element.processDeclarations(scopeProcessor, state, null, place);
    if (injection == null) {
        processDevContext(file, processor);
    } else {
        processPatternContext(injection, file, processor);
    }
}
Also used : ArrayUtil(com.intellij.util.ArrayUtil) PatternClassBean(com.intellij.patterns.compiler.PatternClassBean) ContainerUtil(com.intellij.util.containers.ContainerUtil) LowLevelSearchUtil(com.intellij.psi.impl.search.LowLevelSearchUtil) FileContextUtil(com.intellij.psi.impl.source.resolve.FileContextUtil) StringSearcher(com.intellij.util.text.StringSearcher) NonCodeMembersContributor(org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) PatternCompilerFactory(com.intellij.patterns.compiler.PatternCompilerFactory) CacheManager(com.intellij.psi.impl.cache.CacheManager) Project(com.intellij.openapi.project.Project) TextOccurenceProcessor(com.intellij.psi.search.TextOccurenceProcessor) XmlTag(com.intellij.psi.xml.XmlTag) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) InjectorUtils(org.intellij.plugins.intelliLang.inject.InjectorUtils) GroovyFileType(org.jetbrains.plugins.groovy.GroovyFileType) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.psi.util(com.intellij.psi.util) Key(com.intellij.openapi.util.Key) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) XmlText(com.intellij.psi.xml.XmlText) UsageSearchContext(com.intellij.psi.search.UsageSearchContext) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Processor(com.intellij.util.Processor) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) SoftFactoryMap(com.intellij.util.containers.SoftFactoryMap) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Aggregations

PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)17 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)5 ASTNode (com.intellij.lang.ASTNode)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 com.intellij.psi (com.intellij.psi)3 DelegatingScopeProcessor (com.intellij.psi.scope.DelegatingScopeProcessor)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 Processor (com.intellij.util.Processor)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)3 JavaCompletionProcessor (com.intellij.codeInsight.completion.scope.JavaCompletionProcessor)2 Project (com.intellij.openapi.project.Project)2 Key (com.intellij.openapi.util.Key)2 Ref (com.intellij.openapi.util.Ref)2 ResolveState (com.intellij.psi.ResolveState)2 com.intellij.psi.util (com.intellij.psi.util)2 XmlTag (com.intellij.psi.xml.XmlTag)2 ArrayList (java.util.ArrayList)2 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)2