From 3bfc153ee9d3f10b7e1801aa6a4c7d6f2d30f286 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 9 Feb 2017 13:14:54 +0100 Subject: [PATCH] =?UTF-8?q?IDEA-CR-17158=20do=20not=20introduce=20unclear?= =?UTF-8?q?=20API=20=E2=80=94=20getCachedValue=20in=20java=20now=20just=20?= =?UTF-8?q?delegates=20to=20getCachedValue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Java doesn't support default param values, so, yet another getCachedValue method is required (in case of Kotlin it will be default value) --- .../intellij/psi/util/CachedValuesManager.java | 16 ++++++++-------- .../src/com/intellij/psi/util/cachedValue.kt | 3 +-- 2 files changed, 9 insertions(+), 10 deletions(-) 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