do not create another capture when not necessary; capture should be the same when substitutor define such dependency (IDEA-57340; IDEA-5731)

This commit is contained in:
anna
2012-05-03 09:19:02 +02:00
parent cf8ab78b59
commit 7c3f532d9c
4 changed files with 51 additions and 1 deletions
@@ -283,6 +283,14 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
if (original == null) {
substMap.put(param, null);
} else {
/*boolean alreadyFound = false;
for (Map.Entry<PsiTypeParameter, PsiType> entry : substMap.entrySet()) {
if (original.equals(originalSubstitutor.substitute(entry.getKey()))) {
substMap.put(param, entry.getValue());
alreadyFound = true;
}
}
if (alreadyFound) continue;*/
final PsiType substituted = substituteInternal(original);
if (substituted == null) return false;
substMap.put(param, substituted);
@@ -297,6 +305,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
}
private PsiType addBounds(PsiType substituted, final PsiTypeParameter typeParameter) {
PsiType oldSubstituted = substituted;
PsiElement captureContext = null;
if (substituted instanceof PsiCapturedWildcardType) {
final PsiCapturedWildcardType captured = (PsiCapturedWildcardType)substituted;
@@ -331,7 +340,8 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
if (captureContext != null) {
LOG.assertTrue(substituted instanceof PsiWildcardType);
substituted = PsiCapturedWildcardType.create((PsiWildcardType)substituted, captureContext);
substituted = oldSubstituted instanceof PsiCapturedWildcardType && substituted == ((PsiCapturedWildcardType)oldSubstituted).getWildcard()
? oldSubstituted : PsiCapturedWildcardType.create((PsiWildcardType)substituted, captureContext);
}
return substituted;
}
@@ -606,6 +606,19 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
PsiType paramType = paramResult.getSubstitutor().substitute(typeParameter);
PsiType argType = argResult.getSubstitutor().substituteWithBoundsPromotion(typeParameter);
if (wildcardCaptured != null) {
boolean alreadyFound = false;
for (PsiTypeParameter typeParam : PsiUtil.typeParametersIterable(paramClass)) {
if (typeParam != typeParameter &&
paramType != null &&
argResult.getSubstitutor().substituteWithBoundsPromotion(typeParam) == argType &&
paramType.equals(paramResult.getSubstitutor().substitute(typeParam))) {
alreadyFound = true;
}
}
if (alreadyFound) continue;
}
Pair<PsiType,ConstraintType> res = getSubstitutionForTypeParameterInner(paramType, argType, patternType, ConstraintType.EQUALS, depth + 1);
if (res != null) {