assert that types computed via JavaResolveCache on different threads are the same

GitOrigin-RevId: 17e0b308f4c47d963d42806ec7bb8aaced48f02e
This commit is contained in:
peter
2019-05-24 13:47:42 +03:00
committed by intellij-monorepo-bot
parent e7083fa2ff
commit bf5a0f81f4
2 changed files with 24 additions and 1 deletions
@@ -70,4 +70,14 @@ public class PsiLambdaParameterType extends PsiType {
public PsiParameter getParameter() {
return myParameter;
}
@Override
public boolean equals(Object o) {
return this == o || o instanceof PsiLambdaParameterType && myParameter.equals(((PsiLambdaParameterType)o).myParameter);
}
@Override
public int hashCode() {
return myParameter.hashCode();
}
}
@@ -20,6 +20,8 @@
package com.intellij.psi.impl.source.resolve;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Attachment;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.NotNullLazyKey;
@@ -46,6 +48,7 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReference;
public class JavaResolveCache {
private static final Logger LOG = Logger.getInstance(JavaResolveCache.class);
private static final NotNullLazyKey<JavaResolveCache, Project> INSTANCE_KEY = ServiceManager.createLazyKey(JavaResolveCache.class);
public static JavaResolveCache getInstance(Project project) {
@@ -99,7 +102,10 @@ public class JavaResolveCache {
}
if (type == null) type = TypeConversionUtil.NULL_TYPE;
map.put(expr, type);
PsiType alreadyCached = map.put(expr, type);
if (alreadyCached != null && !type.equals(alreadyCached)) {
reportUnstableType(expr, type, alreadyCached);
}
if (type instanceof PsiClassReferenceType) {
// convert reference-based class type to the PsiImmediateClassType, since the reference may become invalid
@@ -115,6 +121,13 @@ public class JavaResolveCache {
return type == TypeConversionUtil.NULL_TYPE ? null : type;
}
private static <T extends PsiExpression> void reportUnstableType(@NotNull PsiExpression expr, @NotNull PsiType type, @NotNull PsiType alreadyCached) {
PsiFile file = expr.getContainingFile();
LOG.error("Different types returned for the same PSI " + expr.getTextRange() + " on different threads: "
+ type + " != " + alreadyCached,
new Attachment(file.getName(), file.getText()));
}
@Nullable
public Object computeConstantValueWithCaching(@NotNull PsiVariable variable, @NotNull ConstValueComputer computer, Set<PsiVariable> visitedVars){
boolean physical = variable.isPhysical();