Package com.intellij.openapi.util
Class RecursionGuard
java.lang.Object
com.intellij.openapi.util.RecursionGuard
A helper object for
. Is obtained from
.
invalid reference
RecursionManager
invalid reference
RecursionManager#createGuard(String)
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract <T> TdoPreventingRecursion(Object key, boolean memoize, Computable<T> computation) <T> TdoPreventingRecursion(Object key, Computable<T> computation) Deprecated.abstract RecursionGuard.StackStampUsed in pair withRecursionGuard.StackStamp.mayCacheNow()to ensure that cached are only the reliable values, not depending on anything incomplete due to recursive prevention policies.abstract voidprohibitResultCaching(Object since) MakesRecursionGuard.StackStamp.mayCacheNow()return false for all stamps created since a computation with keysincebegan.
-
Constructor Details
-
RecursionGuard
public RecursionGuard()
-
-
Method Details
-
doPreventingRecursion
@Deprecated @Nullable public <T> T doPreventingRecursion(@NotNull Object key, @NotNull Computable<T> computation) Deprecated.SeedoPreventingRecursion(Object, boolean, Computable)with memoization disabled -
doPreventingRecursion
@Nullable public abstract <T> T doPreventingRecursion(@NotNull Object key, boolean memoize, @NotNull Computable<T> computation) - Parameters:
key- an id of the computation. Is stored internally to ensure that a recursive calls with the same key won't lead to endless recursion.memoize- whether the result of the computation may me cached thread-locally until the last currently active doPreventingRecursion call completes. May be used to speedup things when recursion re-entrance happens: otherwise nothing would be cached at all and in some cases exponential performance may be observed.computation- a piece of code to compute.- Returns:
- the result of the computation or null if we're entering a computation with this key on this thread recursively,
-
markStack
Used in pair withRecursionGuard.StackStamp.mayCacheNow()to ensure that cached are only the reliable values, not depending on anything incomplete due to recursive prevention policies. A typical usage is this:RecursionGuard.StackStamp stamp = RecursionManager.createGuard("id").markStack(); Result result = doComputation(); if (stamp.mayCacheNow()) { cache(result); } return result;- Returns:
- an object representing the current stack state, managed by
invalid reference
RecursionManager
-
currentStack
- Returns:
- the current thread-local stack of keys passed to
doPreventingRecursion(Object, Computable)
-
prohibitResultCaching
MakesRecursionGuard.StackStamp.mayCacheNow()return false for all stamps created since a computation with keysincebegan. Used to prevent caching of results that are non-reliable NOT due to recursion prevention: for example, too deep recursion (currentStack()may help in determining the recursion depth) Also disables thread-local memoization (see the second parameter ofdoPreventingRecursion(Object, boolean, Computable).- Parameters:
since- the id of a computation whose result is safe to cache whilst for more nested ones it's not.
-