mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user