public PsiReferenceRegistrarImpl(final Language language) { myBindingCache = new ConcurrentFactoryMap<Class, ProviderBinding[]>() { @Nullable @Override protected ProviderBinding[] create(Class key) { List<ProviderBinding> result = ContainerUtil.newSmartList(); for (Class<?> bindingClass : myBindingsMap.keySet()) { if (bindingClass.isAssignableFrom(key)) { result.add(myBindingsMap.get(bindingClass)); } } for (Class<?> bindingClass : myNamedBindingsMap.keySet()) { if (bindingClass.isAssignableFrom(key)) { result.add(myNamedBindingsMap.get(bindingClass)); } } if (language != Language.ANY) { final PsiReferenceRegistrar anyRegistrar = ReferenceProvidersRegistry.getInstance().getRegistrar(Language.ANY); Collections.addAll(result, ((PsiReferenceRegistrarImpl)anyRegistrar).myBindingCache.get(key)); } //noinspection unchecked return result.toArray(new ProviderBinding[result.size()]); } }; }
public ExternalProjectDataService() { myExternalRootProjects = new ConcurrentFactoryMap<Pair<ProjectSystemId, File>, ExternalProject>() { @Override protected Map<Pair<ProjectSystemId, File>, ExternalProject> createMap() { return ContainerUtil.newConcurrentMap(ExternalSystemUtil.HASHING_STRATEGY); } @Nullable @Override protected ExternalProject create(Pair<ProjectSystemId, File> key) { return new ExternalProjectSerializer().load(key.first, key.second); } @Override public ExternalProject put(Pair<ProjectSystemId, File> key, ExternalProject value) { new ExternalProjectSerializer().save(value); return super.put(key, value); } }; }
public ResolveScopeManagerImpl(Project project, ProjectRootManager projectRootManager, PsiManager psiManager) { myProject = project; myProjectRootManager = projectRootManager; myManager = psiManager; myDefaultResolveScopesCache = ConcurrentFactoryMap.createMap((key) -> { GlobalSearchScope scope = null; for (ResolveScopeProvider resolveScopeProvider : ResolveScopeProvider.EP_NAME.getExtensions()) { scope = resolveScopeProvider.getResolveScope(key, myProject); if (scope != null) break; } if (scope == null) scope = getInherentResolveScope(key); for (ResolveScopeEnlarger enlarger : ResolveScopeEnlarger.EP_NAME.getExtensions()) { final SearchScope extra = enlarger.getAdditionalResolveScope(key, myProject); if (extra != null) { scope = scope.union(extra); } } return scope; }); ((PsiManagerImpl)psiManager).registerRunnableToRunOnChange(myDefaultResolveScopesCache::clear); }
public static Collection<PsiClass> getAnnotationTypesWithChildren(@NotNull Module module, String annotationName, boolean includeTests) { Project project = module.getProject(); Map<Pair<String, Boolean>, Collection<PsiClass>> map = CachedValuesManager.getManager(project).getCachedValue(module, () -> { Map<Pair<String, Boolean>, Collection<PsiClass>> factoryMap = ConcurrentFactoryMap.createMap(key -> { GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, key.getSecond()); PsiClass annotationClass = JavaPsiFacade.getInstance(project).findClass(key.getFirst(), moduleScope); if(annotationClass == null || !annotationClass.isAnnotationType()) { return Collections.emptyList(); } // limit search to files containing annotations GlobalSearchScope effectiveSearchScope = getAllAnnotationFilesScope(project).intersectWith(moduleScope); return getAnnotationTypesWithChildren(annotationClass, effectiveSearchScope); }); return CachedValueProvider.Result.create(factoryMap, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); }); return map.get(pair(annotationName, includeTests)); }
private static PsiAnnotation findOwnAnnotation(final PsiModifierListOwner listOwner, Collection<String> annotationNames) { Map<Collection<String>, PsiAnnotation> map = CachedValuesManager.getCachedValue(listOwner, () -> { Map<Collection<String>, PsiAnnotation> value = ConcurrentFactoryMap.createMap(annotationNames1 -> { final PsiModifierList list = listOwner.getModifierList(); if(list == null) { return null; } for(PsiAnnotation annotation : list.getAnnotations()) { if(annotationNames1.contains(annotation.getQualifiedName())) { return annotation; } } return null; }); return CachedValueProvider.Result.create(value, PsiModificationTracker.MODIFICATION_COUNT); }); return map.get(annotationNames); }
public PsiAnnotation createContractAnnotation(String contractValue) { Map<String, PsiAnnotation> cache = CachedValuesManager.getManager(myProject).getCachedValue(myProject, new CachedValueProvider<Map<String, PsiAnnotation>>() { @Nullable @Override public Result<Map<String, PsiAnnotation>> compute() { Map<String, PsiAnnotation> map = new ConcurrentFactoryMap<String, PsiAnnotation>() { @Nullable @Override protected PsiAnnotation create(String attrs) { return createAnnotationFromText("@org.jetbrains.annotations.Contract(" + attrs + ")"); } }; return CachedValueProvider.Result.create(map, ModificationTracker.NEVER_CHANGED); } }); return cache.get(contractValue); }
public static Collection<PsiClass> getAnnotationTypesWithChildren(@NotNull final Module module, final String annotationName, final boolean includeTests) { final Project project = module.getProject(); Map<Pair<String, Boolean>, Collection<PsiClass>> map = CachedValuesManager.getManager(project).getCachedValue(module, () -> { Map<Pair<String, Boolean>, Collection<PsiClass>> factoryMap = ConcurrentFactoryMap.createMap(key -> { GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, key.getSecond()); PsiClass annotationClass = JavaPsiFacade.getInstance(project).findClass(key.getFirst(), moduleScope); if(annotationClass == null || !annotationClass.isAnnotationType()) { return Collections.emptyList(); } // limit search to files containing annotations GlobalSearchScope effectiveSearchScope = getAllAnnotationFilesScope(project).intersectWith(moduleScope); return getAnnotationTypesWithChildren(annotationClass, effectiveSearchScope); }); return CachedValueProvider.Result.create(factoryMap, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); }); return map.get(Pair.create(annotationName, includeTests)); }
@Override public CachedValueProvider.Result<Map<GlobalSearchScope, MembersMap>> compute(@NotNull final PsiClass myClass) { final Map<GlobalSearchScope, MembersMap> map = new ConcurrentFactoryMap<GlobalSearchScope, MembersMap>() { @Nullable @Override protected MembersMap create(GlobalSearchScope resolveScope) { return new MembersMap(myClass, resolveScope); } }; return CachedValueProvider.Result.create(map, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); }
@Override public FactoryMap<String, Map<MethodSignature, HierarchicalMethodSignature>> fun(final PsiClass psiClass) { return new ConcurrentFactoryMap<String, Map<MethodSignature, HierarchicalMethodSignature>>() { @Nullable @Override protected Map<MethodSignature, HierarchicalMethodSignature> create(String methodName) { return buildMethodHierarchy(psiClass, methodName, PsiSubstitutor.EMPTY, true, new THashSet<PsiClass>(), false, psiClass.getResolveScope()); } }; }
@Override protected ConcurrentFactoryMap<Class, Boolean> create(final Class anc) { return new ConcurrentFactoryMap<Class, Boolean>() { @Override protected Boolean create(Class desc) { return anc.isAssignableFrom(desc); } }; }
@Override protected Map<Class, Object> create(final JavaMethod method) { return new ConcurrentFactoryMap<Class, Object>() { @Override protected Object create(Class annoClass) { return method.getAnnotation(annoClass); } }; }
public Result<FactoryMap<File, String>> compute() { final FactoryMap<File, String> result = new ConcurrentFactoryMap<File, String>() { @Override protected String create(File scriptFile) { return calcClassName(scriptFile); } }; return Result.create(result, ProjectRootManager.getInstance(myModule.getProject())); }
private GdkMethodHolder(final PsiClass categoryClass, final boolean isStatic, final GlobalSearchScope scope) { myStatic = isStatic; myScope = scope; final MultiMap<String, PsiMethod> byName = new MultiMap<String, PsiMethod>(); myPsiManager = categoryClass.getManager(); for (PsiMethod m : categoryClass.getMethods()) { final PsiParameter[] params = m.getParameterList().getParameters(); if (params.length == 0) continue; if (PsiUtil.isDGMMethod(m) && (PsiImplUtil.isDeprecatedByAnnotation(m) || PsiImplUtil.isDeprecatedByDocTag(m))) { continue; } byName.putValue(m.getName(), m); } this.myOriginalMethodByType = new VolatileNotNullLazyValue<MultiMap<String, PsiMethod>>() { @NotNull @Override protected MultiMap<String, PsiMethod> compute() { MultiMap<String, PsiMethod> map = new MultiMap<String, PsiMethod>(); for (PsiMethod method : byName.values()) { if (!method.hasModifierProperty(PsiModifier.PUBLIC)) continue; map.putValue(getCategoryTargetType(method).getCanonicalText(), method); } return map; } }; myOriginalMethodsByNameAndType = new ConcurrentFactoryMap<String, MultiMap<String, PsiMethod>>() { @Override protected MultiMap<String, PsiMethod> create(String name) { MultiMap<String, PsiMethod> map = new MultiMap<String, PsiMethod>(); for (PsiMethod method : byName.get(name)) { map.putValue(getCategoryTargetType(method).getCanonicalText(), method); } return map; } }; }
private GdkMethodHolder(final PsiClass categoryClass, final boolean isStatic, final GlobalSearchScope scope) { myStatic = isStatic; myScope = scope; final MultiMap<String, PsiMethod> byName = new MultiMap<String, PsiMethod>(); myPsiManager = categoryClass.getManager(); for (PsiMethod m : categoryClass.getMethods()) { final PsiParameter[] params = m.getParameterList().getParameters(); if (params.length == 0) continue; byName.putValue(m.getName(), m); } this.myOriginalMethodByType = new VolatileNotNullLazyValue<MultiMap<String, PsiMethod>>() { @NotNull @Override protected MultiMap<String, PsiMethod> compute() { MultiMap<String, PsiMethod> map = new MultiMap<String, PsiMethod>(); for (PsiMethod method : byName.values()) { if (!method.hasModifierProperty(PsiModifier.PUBLIC)) continue; map.putValue(getCategoryTargetType(method).getCanonicalText(), method); } return map; } }; myOriginalMethodsByNameAndType = new ConcurrentFactoryMap<String, MultiMap<String, PsiMethod>>() { @Override protected MultiMap<String, PsiMethod> create(String name) { MultiMap<String, PsiMethod> map = new MultiMap<String, PsiMethod>(); for (PsiMethod method : byName.get(name)) { map.putValue(getCategoryTargetType(method).getCanonicalText(), method); } return map; } }; }
private static OffsetsInFile insertDummyIdentifierWithCache(PsiFile file, int startOffset, int endOffset, String replacement) { ProperTextRange editRange = ProperTextRange.create(startOffset, endOffset); assertRangeWithinDocument(editRange, file.getViewProvider().getDocument()); ConcurrentFactoryMap<Pair<ProperTextRange, String>, OffsetsInFile> map = CachedValuesManager.getCachedValue(file, () -> CachedValueProvider.Result.create( ConcurrentFactoryMap.createConcurrentMap( key -> copyWithDummyIdentifier(new OffsetsInFile(file), key.first.getStartOffset(), key.first.getEndOffset(), key.second)), file, file.getViewProvider().getDocument())); return map.get(Pair.create(editRange, replacement)); }
@Nullable private static PsiAnnotation metaAnnotationCached(PsiClass subjectAnnotation, String annotationToFind) { return CachedValuesManager.getCachedValue(subjectAnnotation, () -> { ConcurrentMap<String, PsiAnnotation> metaAnnotationsMap = ConcurrentFactoryMap.createMap(anno -> findMetaAnnotation(subjectAnnotation, anno, new HashSet<>())); return new CachedValueProvider.Result<>(metaAnnotationsMap, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); }).get(annotationToFind); }
@Nullable public static PsiAnnotation findAnnotationInHierarchy(@NotNull final PsiModifierListOwner listOwner, @NotNull Set<String> annotationNames) { PsiAnnotation directAnnotation = findAnnotation(listOwner, annotationNames); if(directAnnotation != null) { return directAnnotation; } Map<Set<String>, PsiAnnotation> map = CachedValuesManager.getCachedValue(listOwner, () -> { Map<Set<String>, PsiAnnotation> value = ConcurrentFactoryMap.createMap(annotationNames1 -> { for(PsiModifierListOwner superOwner : getSuperAnnotationOwners(listOwner)) { PsiAnnotation annotation = findAnnotation(superOwner, annotationNames1); if(annotation != null) { return annotation; } } return null; }); return CachedValueProvider.Result.create(value, PsiModificationTracker.MODIFICATION_COUNT); }); return map.get(annotationNames); }
@Nullable private static PsiAnnotation metaAnnotationCached(PsiClass subjectAnnotation, String annotationToFind) { ConcurrentMap<String, PsiAnnotation> cachedValue = CachedValuesManager.getCachedValue(subjectAnnotation, () -> { ConcurrentMap<String, PsiAnnotation> metaAnnotationsMap = ConcurrentFactoryMap.createMap(anno -> findMetaAnnotation(subjectAnnotation, anno, new HashSet<>())); return new CachedValueProvider.Result<>(metaAnnotationsMap, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT); }); return cachedValue.get(annotationToFind); }