mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
generics: bounds check should stop expanding nested wildcards up to 2nd level
This commit is contained in:
@@ -270,16 +270,13 @@ public class GenericsUtil {
|
||||
continue;
|
||||
}
|
||||
final PsiType extendsBound = ((PsiWildcardType)substituted).getExtendsBound();
|
||||
if (Comparing.equal(TypeConversionUtil.erasure(extendsType), TypeConversionUtil.erasure(extendsBound))) {
|
||||
if (extendsBound instanceof PsiClassType) {
|
||||
if (acceptExtendsBound((PsiClassType)extendsBound, 0)) continue;
|
||||
} else if (extendsBound instanceof PsiIntersectionType) {
|
||||
for (PsiType psiType : ((PsiIntersectionType)extendsBound).getConjuncts()) {
|
||||
if (psiType instanceof PsiClassType) {
|
||||
if (acceptExtendsBound((PsiClassType)psiType, 0)) continue nextTypeParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (acceptExtendsBound(extendsType, extendsBound)) {
|
||||
continue nextTypeParam;
|
||||
}
|
||||
}
|
||||
else if (substituted instanceof PsiIntersectionType) {
|
||||
for (PsiType extendsBound : ((PsiIntersectionType)substituted).getConjuncts()) {
|
||||
if (acceptExtendsBound(extendsType, extendsBound)) continue nextTypeParam;
|
||||
}
|
||||
}
|
||||
if (extendsType != null && !TypeConversionUtil.isAssignable(extendsType, substituted, allowUncheckedConversion)) {
|
||||
@@ -290,6 +287,22 @@ public class GenericsUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean acceptExtendsBound(PsiType extendsType, PsiType extendsBound) {
|
||||
if (Comparing.equal(TypeConversionUtil.erasure(extendsType), TypeConversionUtil.erasure(extendsBound))) {
|
||||
if (extendsBound instanceof PsiClassType) {
|
||||
if (acceptExtendsBound((PsiClassType)extendsBound, 0)) return true;
|
||||
}
|
||||
else if (extendsBound instanceof PsiIntersectionType) {
|
||||
for (PsiType psiType : ((PsiIntersectionType)extendsBound).getConjuncts()) {
|
||||
if (psiType instanceof PsiClassType) {
|
||||
if (acceptExtendsBound((PsiClassType)psiType, 0)) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean acceptExtendsBound(PsiClassType extendsBound, int depth) {
|
||||
PsiType[] parameters = extendsBound.getParameters();
|
||||
if (parameters.length == 1) {
|
||||
@@ -303,6 +316,13 @@ public class GenericsUtil {
|
||||
if (bound instanceof PsiClassType && TypeConversionUtil.erasure(bound).equals(TypeConversionUtil.erasure(extendsBound))) {
|
||||
return acceptExtendsBound((PsiClassType)bound, depth + 1);
|
||||
}
|
||||
if (bound instanceof PsiIntersectionType) {
|
||||
for (PsiType extendsType : ((PsiIntersectionType)bound).getConjuncts()) {
|
||||
if (acceptExtendsBound(extendsBound, extendsType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user