Search in sources :

Example 1 with MostlySingularMultiMap

use of com.intellij.util.containers.MostlySingularMultiMap 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 MostlySingularMultiMap

use of com.intellij.util.containers.MostlySingularMultiMap in project intellij-community by JetBrains.

the class BaseExternalAnnotationsManager method getDataFromFile.

@NotNull
MostlySingularMultiMap<String, AnnotationData> getDataFromFile(@NotNull PsiFile file) {
    Pair<MostlySingularMultiMap<String, AnnotationData>, Long> cached = myAnnotationFileToDataAndModStampCache.get(file);
    long fileModificationStamp = file.getModificationStamp();
    if (cached != null && cached.getSecond() == fileModificationStamp) {
        return cached.getFirst();
    }
    DataParsingSaxHandler handler = new DataParsingSaxHandler(file);
    try {
        SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
        saxParser.parse(new InputSource(new CharSequenceReader(escapeAttributes(file.getViewProvider().getContents()))), handler);
    } catch (IOException e) {
        LOG.error(e);
    } catch (ParserConfigurationException e) {
        LOG.error(e);
    } catch (SAXException e) {
        LOG.error(e);
    }
    MostlySingularMultiMap<String, AnnotationData> result = handler.getResult();
    myAnnotationFileToDataAndModStampCache.put(file, Pair.create(result, fileModificationStamp));
    return result;
}
Also used : InputSource(org.xml.sax.InputSource) MostlySingularMultiMap(com.intellij.util.containers.MostlySingularMultiMap) ConcurrentMostlySingularMultiMap(com.intellij.util.containers.ConcurrentMostlySingularMultiMap) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) CharSequenceReader(com.intellij.util.text.CharSequenceReader) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with MostlySingularMultiMap

use of com.intellij.util.containers.MostlySingularMultiMap in project intellij-community by JetBrains.

the class XmlPropertiesFileImpl method ensurePropertiesLoaded.

private void ensurePropertiesLoaded() {
    while (myFileModificationStamp != myFile.getModificationStamp() || myPropertiesMap == null) {
        myFileModificationStamp = myFile.getModificationStamp();
        MostlySingularMultiMap<String, IProperty> propertiesMap = new MostlySingularMultiMap<>();
        XmlTag rootTag = myFile.getRootTag();
        final List<IProperty> propertiesOrder = new ArrayList<>();
        if (rootTag != null) {
            XmlTag[] entries = rootTag.findSubTags(ENTRY_TAG_NAME);
            for (XmlTag entry : entries) {
                XmlProperty property = new XmlProperty(entry, this);
                propertiesOrder.add(property);
                final String key = property.getKey();
                if (key != null) {
                    propertiesMap.add(key, property);
                }
            }
        }
        myAlphaSorted = PropertiesImplUtil.isAlphaSorted(propertiesOrder);
        myProperties = propertiesOrder;
        myPropertiesMap = propertiesMap;
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) MostlySingularMultiMap(com.intellij.util.containers.MostlySingularMultiMap) XmlTag(com.intellij.psi.xml.XmlTag)

Example 4 with MostlySingularMultiMap

use of com.intellij.util.containers.MostlySingularMultiMap 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

MostlySingularMultiMap (com.intellij.util.containers.MostlySingularMultiMap)4 NotNull (org.jetbrains.annotations.NotNull)3 ResultWithContext (com.intellij.psi.impl.source.resolve.SymbolCollectingProcessor.ResultWithContext)2 BaseScopeProcessor (com.intellij.psi.scope.BaseScopeProcessor)2 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)2 ASTNode (com.intellij.lang.ASTNode)1 IProperty (com.intellij.lang.properties.IProperty)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 XmlTag (com.intellij.psi.xml.XmlTag)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 Processor (com.intellij.util.Processor)1