capture conversion: add upper bound for ? super if corresponding type parameter has upper bounds( IDEA-128328; IDEA-128972)

This commit is contained in:
Anna Kozlova
2014-08-27 20:59:32 +04:00
parent 66b21d3562
commit 624fa25d38
7 changed files with 65 additions and 7 deletions
@@ -28,6 +28,8 @@ public class PsiCapturedWildcardType extends PsiType.Stub {
@NotNull private final PsiElement myContext;
@Nullable private final PsiTypeParameter myParameter;
private PsiType myUpperBound;
@NotNull
public static PsiCapturedWildcardType create(@NotNull PsiWildcardType existential, @NotNull PsiElement context) {
return create(existential, context, null);
@@ -40,11 +42,28 @@ public class PsiCapturedWildcardType extends PsiType.Stub {
return new PsiCapturedWildcardType(existential, context, parameter);
}
private PsiCapturedWildcardType(@NotNull PsiWildcardType existential, @NotNull PsiElement context, @Nullable PsiTypeParameter parameter) {
private PsiCapturedWildcardType(@NotNull PsiWildcardType existential,
@NotNull PsiElement context,
@Nullable PsiTypeParameter parameter) {
super(PsiAnnotation.EMPTY_ARRAY);
myExistential = existential;
myContext = context;
myParameter = parameter;
if (parameter != null) {
final PsiClassType[] boundTypes = parameter.getExtendsListTypes();
if (boundTypes.length > 0) {
PsiType result = null;
for (PsiType type : boundTypes) {
if (result == null) {
result = type;
}
else {
result = GenericsUtil.getGreatestLowerBound(result, type);
}
}
myUpperBound = result;
}
}
}
@Override
@@ -128,10 +147,14 @@ public class PsiCapturedWildcardType extends PsiType.Stub {
return PsiWildcardType.createSuper(myContext.getManager(), ((PsiCapturedWildcardType)bound).getUpperBound());
}
else {
return PsiType.getJavaLangObject(myContext.getManager(), getResolveScope());
return myUpperBound != null ? myUpperBound : PsiType.getJavaLangObject(myContext.getManager(), getResolveScope());
}
}
public void setUpperBound(PsiType upperBound) {
myUpperBound = upperBound;
}
@NotNull
public PsiWildcardType getWildcard() {
return myExistential;
@@ -141,4 +164,8 @@ public class PsiCapturedWildcardType extends PsiType.Stub {
public PsiElement getContext() {
return myContext;
}
public PsiTypeParameter getTypeParameter() {
return myParameter;
}
}