mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
capture conversion: add upper bound for ? super if corresponding type parameter has upper bounds( IDEA-128328; IDEA-128972)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user