public @Nullable <T extends RefElement> T getFromRefTableOrCache(@NotNull PsiElement element,
                                                                   @NotNull NullableFactory<? extends T> factory,
                                                                   @Nullable Consumer<? super T> whenCached) {
    PsiAnchor psiAnchor = createAnchor(element);
    //noinspection unchecked
    T result = (T)myRefTable.get(psiAnchor);
    if (result != null) return result;

    if (!isValidPointForReference()) {
      //LOG.assertTrue(true, "References may become invalid after process is finished");
      return null;
    }

    T newElement = factory.create();
    if (newElement == null) return null;

    myCachedSortedRefs = null;
    RefElement prev = myRefTable.putIfAbsent(psiAnchor, newElement);
    if (prev != null) {
      //noinspection unchecked
      return (T)prev;
    }
    if (whenCached != null) {
      whenCached.consume(newElement);
    }

    return newElement;
  }
public @Nullable <T extends RefElement> T getFromRefTableOrCache(@NotNull PsiElement element,
                                                                   @NotNull NullableFactory<? extends T> factory,
                                                                   @Nullable Consumer<? super T> whenCached)