Search in sources :

Example 1 with ResultWithContext

use of com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor.ResultWithContext 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 2 with ResultWithContext

use of com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor.ResultWithContext in project intellij-community by JetBrains.

the class GroovyFileImpl method buildDeclarationCache.

@NotNull
private MostlySingularMultiMap<String, ResultWithContext> buildDeclarationCache() {
    MostlySingularMultiMap<String, ResultWithContext> results = new MostlySingularMultiMap<>();
    processDeclarationsNoGuess(new BaseScopeProcessor() {

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            if (element instanceof PsiNamedElement) {
                PsiElement context = state.get(ClassHint.RESOLVE_CONTEXT);
                String name = getDeclarationName((PsiNamedElement) element, context);
                if (name != null) {
                    results.add(name, new ResultWithContext((PsiNamedElement) element, context));
                }
            }
            return true;
        }

        private String getDeclarationName(@NotNull PsiNamedElement element, @Nullable PsiElement context) {
            String name = context instanceof GrImportStatement ? ((GrImportStatement) context).getImportedName() : null;
            return name != null ? name : element.getName();
        }
    }, ResolveState.initial(), null, this);
    return results;
}
Also used : ResultWithContext(com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor.ResultWithContext) MostlySingularMultiMap(com.intellij.util.containers.MostlySingularMultiMap) BaseScopeProcessor(com.intellij.psi.scope.BaseScopeProcessor) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResultWithContext (com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor.ResultWithContext)2 BaseScopeProcessor (com.intellij.psi.scope.BaseScopeProcessor)2 MostlySingularMultiMap (com.intellij.util.containers.MostlySingularMultiMap)2 NotNull (org.jetbrains.annotations.NotNull)2 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)2 ASTNode (com.intellij.lang.ASTNode)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 com.intellij.psi (com.intellij.psi)1 PsiFileEx (com.intellij.psi.impl.PsiFileEx)1 ElementClassHint (com.intellij.psi.scope.ElementClassHint)1 NameHint (com.intellij.psi.scope.NameHint)1 PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)1 StubElement (com.intellij.psi.stubs.StubElement)1 com.intellij.psi.util (com.intellij.psi.util)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 Processor (com.intellij.util.Processor)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1