Search in sources :

Example 1 with ConcurrentFactoryMap

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

the class CompilerReferenceServiceImpl method getHierarchyInfo.

@Nullable
private CompilerHierarchyInfoImpl getHierarchyInfo(@NotNull PsiNamedElement aClass, @NotNull GlobalSearchScope useScope, @NotNull GlobalSearchScope searchScope, @NotNull FileType searchFileType, @NotNull CompilerHierarchySearchType searchType) {
    if (!isServiceEnabledFor(aClass) || searchScope == LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope())
        return null;
    try {
        Map<VirtualFile, Object[]> candidatesPerFile = ReadAction.compute(() -> {
            if (myProject.isDisposed())
                throw new ProcessCanceledException();
            return CachedValuesManager.getCachedValue(aClass, () -> CachedValueProvider.Result.create(new ConcurrentFactoryMap<HierarchySearchKey, Map<VirtualFile, Object[]>>() {

                @Nullable
                @Override
                protected Map<VirtualFile, Object[]> create(HierarchySearchKey key) {
                    return calculateDirectInheritors(aClass, useScope, key.mySearchFileType, key.mySearchType);
                }
            }, PsiModificationTracker.MODIFICATION_COUNT, this)).get(new HierarchySearchKey(searchType, searchFileType));
        });
        if (candidatesPerFile == null)
            return null;
        GlobalSearchScope dirtyScope = myDirtyScopeHolder.getDirtyScope();
        if (ElementPlace.LIB == ReadAction.compute(() -> ElementPlace.get(aClass.getContainingFile().getVirtualFile(), myProjectFileIndex))) {
            dirtyScope = dirtyScope.union(LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope());
        }
        return new CompilerHierarchyInfoImpl(candidatesPerFile, aClass, dirtyScope, searchScope, myProject, searchFileType, searchType);
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (RuntimeException e) {
        return onException(e, "hierarchy");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ConcurrentFactoryMap(com.intellij.util.containers.ConcurrentFactoryMap) Nullable(org.jetbrains.annotations.Nullable) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ConcurrentFactoryMap

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

the class AnnotationUtil method findNonCodeAnnotation.

private static PsiAnnotation findNonCodeAnnotation(final PsiModifierListOwner listOwner, Collection<String> annotationNames) {
    ConcurrentFactoryMap<Collection<String>, PsiAnnotation> map = CachedValuesManager.getCachedValue(listOwner, () -> {
        ConcurrentFactoryMap<Collection<String>, PsiAnnotation> value = new ConcurrentFactoryMap<Collection<String>, PsiAnnotation>() {

            @Nullable
            @Override
            protected PsiAnnotation create(Collection<String> annotationNames1) {
                final Project project = listOwner.getProject();
                final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project);
                for (String annotationName : annotationNames1) {
                    final PsiAnnotation annotation = annotationsManager.findExternalAnnotation(listOwner, annotationName);
                    if (annotation != null) {
                        return annotation;
                    }
                }
                final InferredAnnotationsManager inferredAnnotationsManager = InferredAnnotationsManager.getInstance(project);
                for (String annotationName : annotationNames1) {
                    final PsiAnnotation annotation = inferredAnnotationsManager.findInferredAnnotation(listOwner, annotationName);
                    if (annotation != null) {
                        return annotation;
                    }
                }
                return null;
            }
        };
        return CachedValueProvider.Result.create(value, PsiModificationTracker.MODIFICATION_COUNT);
    });
    return map.get(annotationNames);
}
Also used : ConcurrentFactoryMap(com.intellij.util.containers.ConcurrentFactoryMap) Project(com.intellij.openapi.project.Project)

Aggregations

ConcurrentFactoryMap (com.intellij.util.containers.ConcurrentFactoryMap)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 Nullable (org.jetbrains.annotations.Nullable)1