Class RecursionGuard

java.lang.Object
com.intellij.openapi.util.RecursionGuard

public abstract class RecursionGuard extends Object
A helper object for
invalid reference
RecursionManager
. Is obtained from
invalid reference
RecursionManager#createGuard(String)
.
  • Constructor Details

    • RecursionGuard

      public RecursionGuard()
  • Method Details

    • doPreventingRecursion

      @Deprecated @Nullable public <T> T doPreventingRecursion(@NotNull Object key, @NotNull Computable<T> computation)
      Deprecated.
    • 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

      @NotNull public abstract RecursionGuard.StackStamp markStack()
      Used in pair with RecursionGuard.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

      @NotNull public abstract List<Object> currentStack()
      Returns:
      the current thread-local stack of keys passed to doPreventingRecursion(Object, Computable)
    • prohibitResultCaching

      public abstract void prohibitResultCaching(@NotNull Object since)
      Makes RecursionGuard.StackStamp.mayCacheNow() return false for all stamps created since a computation with key since began. 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 of doPreventingRecursion(Object, boolean, Computable).
      Parameters:
      since - the id of a computation whose result is safe to cache whilst for more nested ones it's not.