mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
introduce CachedValuesManager.getProjectPsiDependentCache, convert a couple of usages
GitOrigin-RevId: 4943fce8b6bd685f80b90e21389509fd5683974d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f703a5aec6
commit
995e376cbe
@@ -157,8 +157,7 @@ public class LambdaUtil {
|
||||
@Contract("null -> null")
|
||||
public static @Nullable MethodSignature getFunction(final PsiClass psiClass) {
|
||||
if (isPlainInterface(psiClass)) {
|
||||
return CachedValuesManager.getCachedValue(psiClass, () -> CachedValueProvider.Result
|
||||
.create(calcFunction(psiClass), PsiModificationTracker.MODIFICATION_COUNT));
|
||||
return CachedValuesManager.getProjectPsiDependentCache(psiClass, () -> calcFunction(psiClass));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -71,8 +71,7 @@ public class PsiTypeElementImpl extends CompositePsiElement implements PsiTypeEl
|
||||
}
|
||||
|
||||
private TypeInfo getTypeInfo() {
|
||||
return CachedValuesManager.getCachedValue(
|
||||
this, () -> CachedValueProvider.Result.create(calculateTypeInfo(), PsiModificationTracker.MODIFICATION_COUNT));
|
||||
return CachedValuesManager.getProjectPsiDependentCache(this, this::calculateTypeInfo);
|
||||
}
|
||||
|
||||
private @NotNull TypeInfo calculateTypeInfo() {
|
||||
|
||||
@@ -16,9 +16,7 @@ import com.intellij.psi.impl.AnyPsiChangeListener;
|
||||
import com.intellij.psi.impl.PsiManagerImpl;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.util.ConcurrencyUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -64,8 +62,7 @@ public class JavaResolveCache {
|
||||
return f.fun(expr);
|
||||
}
|
||||
|
||||
return CachedValuesManager.getCachedValue(expr, () ->
|
||||
CachedValueProvider.Result.create(f.fun(expr), PsiModificationTracker.MODIFICATION_COUNT));
|
||||
return CachedValuesManager.getProjectPsiDependentCache(expr, () -> f.fun(expr));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* A service used to create and store {@link CachedValue} objects.<p/>
|
||||
@@ -119,6 +120,16 @@ public abstract class CachedValuesManager {
|
||||
return getCachedValue(psi, getKeyForClass(provider.getClass(), globalKeyForProvider), provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a cached value computed via the given provider,
|
||||
* associated with the given PSI element,
|
||||
* recalculated after any PSI change in the project.
|
||||
*/
|
||||
public static <T> T getProjectPsiDependentCache(@NotNull PsiElement psi, @NotNull Supplier<T> provider) {
|
||||
return getCachedValue(psi, getKeyForClass(provider.getClass(), globalKeyForProvider), () ->
|
||||
CachedValueProvider.Result.create(provider.get(), PsiModificationTracker.MODIFICATION_COUNT));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* The passed cached value provider may only depend on the passed PSI element and project/application components/services,
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.util.containers.ConcurrentFactoryMap;
|
||||
@@ -20,6 +19,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* This class checks the contract described in {@link com.intellij.psi.util.CachedValue} documentation, that its
|
||||
@@ -171,7 +171,7 @@ final class CachedValueStabilityChecker {
|
||||
Class<?> superclass = clazz.getSuperclass();
|
||||
if (superclass == null) return false;
|
||||
|
||||
if ((o instanceof Computable || o instanceof Function || o instanceof java.util.function.Function) &&
|
||||
if ((o instanceof Supplier || o instanceof Function || o instanceof java.util.function.Function) &&
|
||||
Object.class.equals(clazz.getSuperclass())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user