IDEA-CR-17158 do not introduce unclear API — getCachedValue in java now just delegates to getCachedValue

Java doesn't support default param values, so, yet another getCachedValue method is required (in case of Kotlin it will be default value)
This commit is contained in:
Vladimir Krivosheev
2017-02-09 13:14:54 +01:00
parent a0b2549d11
commit 3bfc153ee9
2 changed files with 9 additions and 10 deletions
@@ -124,19 +124,19 @@ public abstract class CachedValuesManager {
* @return The cached value
*/
public static <T> T getCachedValue(@NotNull final PsiElement psi, @NotNull final CachedValueProvider<T> provider) {
Key<CachedValue<T>> key = getKeyForClass(provider.getClass(), globalKeyForProvider);
CachedValue<T> value = psi.getUserData(key);
return value == null ? computeCachedValue(psi, key, provider) : value.getValue();
return getCachedValue(psi, CachedValuesManager.<T>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> T computeCachedValue(@NotNull final PsiElement psi, @NotNull Key<CachedValue<T>> key, @NotNull final CachedValueProvider<T> provider) {
public static <T> T getCachedValue(@NotNull final PsiElement psi, @NotNull Key<CachedValue<T>> key, @NotNull final CachedValueProvider<T> provider) {
CachedValue<T> value = psi.getUserData(key);
if (value != null) {
return value.getValue();
}
return getManager(psi.getProject()).getCachedValue(psi, key, new CachedValueProvider<T>() {
@Nullable
@Override
@@ -23,6 +23,5 @@ import com.intellij.psi.PsiElement
* @return The cached value
*/
inline fun <T> PsiElement.getCachedValue(key: Key<CachedValue<T>>, provider: () -> CachedValueProvider<T>): 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
}