com.intellij.openapi.util.RecursionGuard Java Examples
The following examples show how to use
com.intellij.openapi.util.RecursionGuard.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConcurrentFactoryMap.java From consulo with Apache License 2.0 | 6 votes |
@Override public V get(Object key) { ConcurrentMap<K, V> map = myMap; K k = notNull(key); V value = map.get(k); if (value == null) { RecursionGuard.StackStamp stamp = RecursionManager.markStack(); //noinspection unchecked value = create((K)key); if (stamp.mayCacheNow()) { V v = notNull(value); value = ConcurrencyUtil.cacheOrGet(map, k, v); } } return nullize(value); }
Example #2
Source File: FactoryMap.java From consulo with Apache License 2.0 | 6 votes |
@Override public V get(Object key) { Map<K, V> map = getMap(); K k = notNull(key); V value = map.get(k); if (value == null) { RecursionGuard.StackStamp stamp = RecursionManager.markStack(); //noinspection unchecked value = create((K)key); if (stamp.mayCacheNow()) { V v = notNull(value); map.put(k, v); } } return nullize(value); }
Example #3
Source File: ResolveCache.java From consulo with Apache License 2.0 | 5 votes |
@Nullable private <TRef extends PsiReference, TResult> TResult resolve(@Nonnull final TRef ref, @Nonnull final AbstractResolver<? super TRef, TResult> resolver, boolean needToPreventRecursion, final boolean incompleteCode, boolean isPoly, boolean isPhysical) { ProgressIndicatorProvider.checkCanceled(); if (isPhysical) { ApplicationManager.getApplication().assertReadAccessAllowed(); } int index = getIndex(incompleteCode, isPoly); Map<TRef, TResult> map = getMap(isPhysical, index); TResult result = map.get(ref); if (result != null) { return result; } RecursionGuard.StackStamp stamp = RecursionManager.markStack(); result = needToPreventRecursion ? RecursionManager.doPreventingRecursion(Trinity.create(ref, incompleteCode, isPoly), true, () -> resolver.resolve(ref, incompleteCode)) : resolver.resolve(ref, incompleteCode); if (result instanceof ResolveResult) { ensureValidPsi((ResolveResult)result); } else if (result instanceof ResolveResult[]) { ensureValidResults((ResolveResult[])result); } else if (result instanceof PsiElement) { PsiUtilCore.ensureValid((PsiElement)result); } if (stamp.mayCacheNow()) { cache(ref, map, result); } return result; }
Example #4
Source File: ResolveCache.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public <T extends PsiPolyVariantReference> ResolveResult[] resolveWithCaching(@Nonnull final T ref, @Nonnull final PolyVariantContextResolver<T> resolver, boolean needToPreventRecursion, final boolean incompleteCode, @Nonnull final PsiFile containingFile) { ProgressIndicatorProvider.checkCanceled(); ApplicationManager.getApplication().assertReadAccessAllowed(); boolean physical = containingFile.isPhysical(); int index = getIndex(incompleteCode, true); Map<T, ResolveResult[]> map = getMap(physical, index); ResolveResult[] result = map.get(ref); if (result != null) { return result; } RecursionGuard.StackStamp stamp = RecursionManager.markStack(); result = needToPreventRecursion ? RecursionManager.doPreventingRecursion(Pair.create(ref, incompleteCode), true, () -> resolver.resolve(ref, containingFile, incompleteCode)) : resolver.resolve(ref, containingFile, incompleteCode); if (result != null) { ensureValidResults(result); } if (stamp.mayCacheNow()) { cache(ref, map, result); } return result == null ? ResolveResult.EMPTY_ARRAY : result; }
Example #5
Source File: SemServiceImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nullable public <T extends SemElement> List<T> getSemElements(final SemKey<T> key, @Nonnull final PsiElement psi) { List<T> cached = _getCachedSemElements(key, true, psi); if (cached != null) { return cached; } ensureInitialized(); RecursionGuard.StackStamp stamp = RecursionManager.createGuard("semService").markStack(); LinkedHashSet<T> result = new LinkedHashSet<>(); final Map<SemKey, List<SemElement>> map = new THashMap<>(); for (final SemKey each : key.getInheritors()) { List<SemElement> list = createSemElements(each, psi); map.put(each, list); result.addAll((List<T>)list); } if (stamp.mayCacheNow()) { final SemCacheChunk persistent = getOrCreateChunk(psi); for (SemKey semKey : map.keySet()) { persistent.putSemElements(semKey, map.get(semKey)); } } return new ArrayList<>(result); }
Example #6
Source File: LombokAugmentProvider.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
LombokCachedValueProvider(Class<Psi> type, PsiClass psiClass, RecursionGuard<PsiClass> recursionGuard) { this.type = type; this.psiClass = psiClass; this.recursionGuard = recursionGuard; }