diff --git a/platform/core-api/src/com/intellij/psi/util/CachedValuesManager.java b/platform/core-api/src/com/intellij/psi/util/CachedValuesManager.java index e0879d381d40..5d0b78266442 100644 --- a/platform/core-api/src/com/intellij/psi/util/CachedValuesManager.java +++ b/platform/core-api/src/com/intellij/psi/util/CachedValuesManager.java @@ -124,19 +124,19 @@ public abstract class CachedValuesManager { * @return The cached value */ public static T getCachedValue(@NotNull final PsiElement psi, @NotNull final CachedValueProvider provider) { - Key> key = getKeyForClass(provider.getClass(), globalKeyForProvider); - CachedValue value = psi.getUserData(key); - return value == null ? computeCachedValue(psi, key, provider) : value.getValue(); + return getCachedValue(psi, CachedValuesManager.getKeyForClass(provider.getClass(), globalKeyForProvider), provider); } /** - * Create a cached value with the given provider and non-tracked return value, store it in PSI element's user data. - * - * Consider to use high-level {@link #getCachedValue} or, in Kotlin code, PsiElement.getCachedValue. - * + * Create a cached value with the given provider and non-tracked return value, store it in PSI element's user data. If it's already stored, reuse it. * @return The cached value */ - public static T computeCachedValue(@NotNull final PsiElement psi, @NotNull Key> key, @NotNull final CachedValueProvider provider) { + public static T getCachedValue(@NotNull final PsiElement psi, @NotNull Key> key, @NotNull final CachedValueProvider provider) { + CachedValue value = psi.getUserData(key); + if (value != null) { + return value.getValue(); + } + return getManager(psi.getProject()).getCachedValue(psi, key, new CachedValueProvider() { @Nullable @Override diff --git a/platform/lang-impl/src/com/intellij/psi/util/cachedValue.kt b/platform/lang-impl/src/com/intellij/psi/util/cachedValue.kt index b35733005f2d..23b59f1359d0 100644 --- a/platform/lang-impl/src/com/intellij/psi/util/cachedValue.kt +++ b/platform/lang-impl/src/com/intellij/psi/util/cachedValue.kt @@ -23,6 +23,5 @@ import com.intellij.psi.PsiElement * @return The cached value */ inline fun PsiElement.getCachedValue(key: Key>, provider: () -> CachedValueProvider): T { - val value = getUserData(key) - return if (value == null) CachedValuesManager.computeCachedValue(this, key, provider()) else value.value + return (getUserData(key) ?: return CachedValuesManager.getCachedValue(this, key, provider())).value } \ No newline at end of file