@Override public PsiPackage findPackage(@NotNull String qualifiedName) { SoftReference<ConcurrentMap<String, PsiPackage>> ref = myPackageCache; ConcurrentMap<String, PsiPackage> cache = ref == null ? null : ref.get(); if (cache == null) { myPackageCache = new SoftReference<ConcurrentMap<String, PsiPackage>>(cache = new ConcurrentHashMap<String, PsiPackage>()); } PsiPackage aPackage = cache.get(qualifiedName); if (aPackage != null) { return aPackage; } for (PsiElementFinder finder : filteredFinders()) { aPackage = finder.findPackage(qualifiedName); if (aPackage != null) { return ConcurrencyUtil.cacheOrGet(cache, qualifiedName, aPackage); } } return null; }
@Nullable public PsiClass findClassWithCache(@NotNull String fqName, @NotNull GlobalSearchScope resolveScope) { SoftReference<Map<GlobalSearchScope, PsiClass>> reference = myClassCache.get(fqName); Map<GlobalSearchScope, PsiClass> map = reference == null ? null : reference.get(); if (map == null) { map = new ConcurrentHashMap<GlobalSearchScope, PsiClass>(); myClassCache.put(fqName, new SoftReference<Map<GlobalSearchScope, PsiClass>>(map)); } PsiClass cached = map.get(resolveScope); if (cached != null) { return cached; } PsiClass result = JavaPsiFacade.getInstance(myProject).findClass(fqName, resolveScope); if (result != null) { map.put(resolveScope, result); } return result; }
public BuildTargetTypeState(BuildTargetType<?> targetType, BuildTargetsState state) { myTargetType = targetType; myTargetsState = state; myTargetsFile = new File(state.getDataPaths().getTargetTypeDataRoot(targetType), "targets.dat"); myConfigurations = new ConcurrentHashMap<BuildTarget<?>, BuildTargetConfiguration>(); myTargetIds = new HashMap<BuildTarget<?>, Integer>(); load(); }
public BuildRootIndexImpl(BuildTargetIndex targetIndex, JpsModel model, ModuleExcludeIndex index, BuildDataPaths dataPaths, final IgnoredFileIndex ignoredFileIndex) { myIgnoredFileIndex = ignoredFileIndex; myRootsByTarget = new HashMap<BuildTarget<?>, List<? extends BuildRootDescriptor>>(); myRootToDescriptors = new THashMap<File, List<BuildRootDescriptor>>(FileUtil.FILE_HASHING_STRATEGY); myFileFilters = new ConcurrentHashMap<BuildRootDescriptor, FileFilter>(); final Iterable<AdditionalRootsProviderService> rootsProviders = JpsServiceManager.getInstance().getExtensions(AdditionalRootsProviderService.class); for (BuildTargetType<?> targetType : TargetTypeRegistry.getInstance().getTargetTypes()) { for (BuildTarget<?> target : targetIndex.getAllTargets(targetType)) { addRoots(dataPaths, rootsProviders, target, model, index, ignoredFileIndex); } } }
public static Map<SliceNode, Collection<PsiElement>> createMap() { return new FactoryMap<SliceNode, Collection<PsiElement>>() { @Override protected Map<SliceNode, Collection<PsiElement>> createMap() { return new ConcurrentHashMap<SliceNode, Collection<PsiElement>>(ContainerUtil.<SliceNode>identityStrategy()); } @Override protected Collection<PsiElement> create(SliceNode key) { return new ConcurrentHashSet<PsiElement>(SliceLeafAnalyzer.LEAF_ELEMENT_EQUALITY); } }; }
private static ConcurrentMap<Project, MarkupModelImpl> getMarkupModelMap(@NotNull Document document) { ConcurrentMap<Project, MarkupModelImpl> markupModelMap = document.getUserData(MARKUP_MODEL_MAP_KEY); if (markupModelMap == null) { synchronized (lock) { markupModelMap = document.getUserData(MARKUP_MODEL_MAP_KEY); if (markupModelMap == null) { markupModelMap = new ConcurrentHashMap<Project, MarkupModelImpl>(); document.putUserData(MARKUP_MODEL_MAP_KEY, markupModelMap); } } } return markupModelMap; }
public static ResourceBundle getResourceBundle(@NotNull String pathToBundle, @NotNull ClassLoader loader) { ConcurrentHashMap<String, SoftReference<ResourceBundle>> map = ourCache.get(loader); SoftReference<ResourceBundle> reference = map.get(pathToBundle); ResourceBundle result = reference == null ? null : reference.get(); if (result == null) { map.put(pathToBundle, new SoftReference<ResourceBundle>(result = ResourceBundle.getBundle(pathToBundle, Locale.getDefault(), loader))); } return result; }
public V getCachedValue(T key) { SofterReference<ConcurrentMap<T, V>> ref = myCache; ConcurrentMap<T, V> map = ref == null ? null : ref.get(); if (map == null) { myCache = new SofterReference<ConcurrentMap<T, V>>(map = new ConcurrentHashMap<T, V>()); } V value = map.get(key); if (value == null) { map.put(key, value = myValueProvider.fun(key)); } return value; }
private static <T extends DomChildDescriptionImpl> ChildrenDescriptionsHolder<T> internChildrenHolder(XmlFile file, ChildrenDescriptionsHolder<T> holder) { SoftReference<ConcurrentHashMap<ChildrenDescriptionsHolder, ChildrenDescriptionsHolder>> ref = file.getUserData(HOLDERS_CACHE); ConcurrentHashMap<ChildrenDescriptionsHolder, ChildrenDescriptionsHolder> cache = ref == null ? null : ref.get(); if (cache == null) { cache = new ConcurrentHashMap<ChildrenDescriptionsHolder, ChildrenDescriptionsHolder>(); file.putUserData(HOLDERS_CACHE, new SoftReference<ConcurrentHashMap<ChildrenDescriptionsHolder, ChildrenDescriptionsHolder>>(cache)); } ChildrenDescriptionsHolder existing = cache.get(holder); if (existing != null) { //noinspection unchecked return existing; } cache.put(holder, holder); return holder; }
public XmlNSDescriptor getDefaultNSDescriptor(final String namespace, final boolean strict) { long curExtResourcesModCount = ExternalResourceManagerEx.getInstanceEx().getModificationCount(getProject()); if (myExtResourcesModCount != curExtResourcesModCount) { myDefaultDescriptorsCacheNotStrict.clear(); myDefaultDescriptorsCacheStrict.clear(); myExtResourcesModCount = curExtResourcesModCount; } final ConcurrentHashMap<String, CachedValue<XmlNSDescriptor>> defaultDescriptorsCache; if (strict) { defaultDescriptorsCache = myDefaultDescriptorsCacheStrict; } else { defaultDescriptorsCache = myDefaultDescriptorsCacheNotStrict; } CachedValue<XmlNSDescriptor> cachedValue = defaultDescriptorsCache.get(namespace); if (cachedValue == null) { defaultDescriptorsCache.put(namespace, cachedValue = new PsiCachedValueImpl<XmlNSDescriptor>(getManager(), new CachedValueProvider<XmlNSDescriptor>() { public Result<XmlNSDescriptor> compute() { final XmlNSDescriptor defaultNSDescriptorInner = getDefaultNSDescriptorInner(namespace, strict); if (isGeneratedFromDtd(defaultNSDescriptorInner)) { return new Result<XmlNSDescriptor>(defaultNSDescriptorInner, XmlDocumentImpl.this, ExternalResourceManager.getInstance()); } return new Result<XmlNSDescriptor>(defaultNSDescriptorInner, defaultNSDescriptorInner != null ? defaultNSDescriptorInner.getDependences() : ExternalResourceManager.getInstance()); } })); } return cachedValue.getValue(); }
public FactorTree(final Project project, GroovyDslExecutor executor) { myExecutor = executor; myProvider = new CachedValueProvider<Map>() { @Nullable @Override public Result<Map> compute() { return new Result<Map>(new ConcurrentHashMap(), PsiModificationTracker.MODIFICATION_COUNT, ProjectRootManager.getInstance(project)); } }; myTopLevelCache = CachedValuesManager.getManager(project).createCachedValue(myProvider, false); }
public void cache(GroovyClassDescriptor descriptor, CustomMembersHolder holder) { Map current = null; for (Factor factor : descriptor.affectingFactors) { Object key; switch (factor) { case placeElement: key = descriptor.getPlace(); break; case placeFile: key = descriptor.getPlaceFile(); break; case qualifierType: key = descriptor.getTypeText(); break; default: throw new IllegalStateException("Unknown variant: "+ factor); } if (current == null) { if (key instanceof UserDataHolder) { final Project project = descriptor.getProject(); current = CachedValuesManager.getManager(project).getCachedValue((UserDataHolder)key, GDSL_MEMBER_CACHE, myProvider, false); continue; } current = myTopLevelCache.getValue(); } Map next = (Map)current.get(key); if (next == null) { //noinspection unchecked current.put(key, next = new ConcurrentHashMap()); } current = next; } if (current == null) current = myTopLevelCache.getValue(); //noinspection unchecked current.put(myExecutor, holder); }
public static PsiType getCachedType(String typeText, PsiFile context) { Map<String, PsiType> map = context.getUserData(CACHED_TYPES); if (map == null) { map = new ConcurrentHashMap<String, PsiType>(); context.putUserData(CACHED_TYPES, map); } PsiType type = map.get(typeText); if (type == null || !type.isValid()) { type = JavaPsiFacade.getElementFactory(context.getProject()).createTypeFromText(typeText, context); map.put(typeText, type); } return type; }
@Override protected CachedValue<Map<String, JSImportedElementResolveResult>> compute(final PsiElement psiElement, final Object p) { return CachedValuesManager.getManager(psiElement.getProject()).createCachedValue(new CachedValueProvider<Map<String, JSImportedElementResolveResult>>() { @Override public Result<Map<String, JSImportedElementResolveResult>> compute() { return new Result<Map<String, JSImportedElementResolveResult>>(new ConcurrentHashMap<String, JSImportedElementResolveResult>(), PsiModificationTracker.MODIFICATION_COUNT); } }, false); }
@Override protected ConcurrentHashMap<String, SoftReference<ResourceBundle>> create(ClassLoader key) { return new ConcurrentHashMap<String, SoftReference<ResourceBundle>>(); }
public CachesHolder(final Project project, final RepositoryLocationCache locationCache) { myProject = project; myLocationCache = locationCache; myPlManager = ProjectLevelVcsManager.getInstance(myProject); myCacheFiles = new ConcurrentHashMap<String, ChangesCacheFile>(); }
public CachesHolder(final Project project, final RepositoryLocationCache locationCache, final ProjectLevelVcsManager manager) { myProject = project; myPlManager = manager; myLocationCache = locationCache; myCacheFiles = new ConcurrentHashMap<String, ChangesCacheFile>(); }
public CommittedChangesCache(final Project project, final MessageBus bus, final ProjectLevelVcsManager vcsManager) { myProject = project; myBus = bus; myConnection = myBus.connect(); final VcsListener vcsListener = new VcsListener() { @Override public void directoryMappingChanged() { myLocationCache.reset(); refreshAllCachesAsync(false, true); refreshIncomingChangesAsync(); myTaskQueue.run(new Runnable() { @Override public void run() { final List<ChangesCacheFile> files = myCachesHolder.getAllCaches(); for (ChangesCacheFile file : files) { final RepositoryLocation location = file.getLocation(); fireChangesLoaded(location, Collections.<CommittedChangeList>emptyList()); } fireIncomingReloaded(); } }); } }; myLocationCache = new RepositoryLocationCache(project); myCachesHolder = new CachesHolder(project, myLocationCache); myTaskQueue = new ProgressManagerQueue(project, VcsBundle.message("committed.changes.refresh.progress")); ((ProjectLevelVcsManagerImpl) vcsManager).addInitializationRequest(VcsInitObject.COMMITTED_CHANGES_CACHE, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override public void run() { if (myProject.isDisposed()) return; myTaskQueue.start(); myConnection.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, vcsListener); myConnection.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED_IN_PLUGIN, vcsListener); } }); } }); myVcsManager = vcsManager; Disposer.register(project, new Disposable() { @Override public void dispose() { cancelRefreshTimer(); myConnection.disconnect(); } }); myExternallyLoadedChangeLists = new ConcurrentHashMap<String, Pair<Long, List<CommittedChangeList>>>(); }
public Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> create() { return new ConcurrentHashMap<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>>(); }