use thread local to store modified upper bounds instead of non-physical type parameters as methods could come from foreign languages (IDEA-151194)

This commit is contained in:
Anna Kozlova
2016-02-03 16:10:26 +03:00
parent 1190715024
commit c0055bc52c
2 changed files with 6 additions and 15 deletions
@@ -1032,6 +1032,9 @@ public class PsiClassImplUtil {
return new PsiClassType[]{getAnnotationSuperType(psiClass, JavaPsiFacade.getInstance(psiClass.getProject()).getElementFactory())};
}
PsiType upperBound = psiClass.getUserData(InferenceSession.UPPER_BOUND);
if (upperBound == null && psiClass instanceof PsiTypeParameter) {
upperBound = LambdaUtil.getFunctionalTypeMap().get(psiClass);
}
if (upperBound instanceof PsiIntersectionType) {
final PsiType[] conjuncts = ((PsiIntersectionType)upperBound).getConjuncts();
final List<PsiClassType> result = new ArrayList<PsiClassType>();
@@ -1501,18 +1501,6 @@ public class InferenceSession {
final PsiElement context,
final boolean varargs) {
try {
//push site substitutor to parameter bounds
final String text;
if (m1 instanceof ClsMethodImpl) {
final StringBuilder builder = new StringBuilder();
((ClsMethodImpl)m1).appendMirrorText(0, builder);
text = builder.toString();
}
else {
text = m1.getText();
}
m1 = JavaPsiFacade.getElementFactory(m1.getProject()).createMethodFromText(text, m1);
for (PsiTypeParameter parameter : m1.getTypeParameters()) {
final PsiClassType[] types = parameter.getExtendsListTypes();
if (types.length > 0) {
@@ -1525,14 +1513,14 @@ public class InferenceSession {
//don't glb to avoid flattening = Object&Interface would be preserved
//otherwise methods with different signatures could get same erasure
final PsiType upperBound = PsiIntersectionType.createIntersection(false, conjuncts.toArray(new PsiType[conjuncts.size()]));
parameter.putUserData(UPPER_BOUND, upperBound);
LambdaUtil.getFunctionalTypeMap().put(parameter, upperBound);
}
}
return isMoreSpecificInternal(m1, m2, siteSubstitutor1, args, context, varargs);
}
finally {
for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable(m1)) {
parameter.putUserData(UPPER_BOUND, null);
for (PsiTypeParameter parameter : m1.getTypeParameters()) {
LambdaUtil.getFunctionalTypeMap().remove(parameter);
}
}
}