[java] better error message for type parameter outside bounds when the type parameter is not a concrete class (IDEA-353386)

GitOrigin-RevId: 6fcb1f8c2180ed319cdf7030de9c38b302e8e2d4
This commit is contained in:
Bas Leijdekkers
2024-05-13 15:37:14 +02:00
committed by intellij-monorepo-bot
parent 7b074a10b1
commit 0a8f0ae1c8
2 changed files with 13 additions and 7 deletions

View File

@@ -269,12 +269,16 @@ public final class GenericsHighlightUtil {
if (!bound.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) && GenericsUtil.checkNotInBounds(type, bound, referenceParameterList)) {
PsiClass boundClass = bound instanceof PsiClassType ? ((PsiClassType)bound).resolve() : null;
@NonNls String messageKey = boundClass == null || referenceClass == null || referenceClass.isInterface() == boundClass.isInterface()
? "generics.type.parameter.is.not.within.its.bound.extend"
: "generics.type.parameter.is.not.within.its.bound.implement";
String description = JavaErrorBundle.message(messageKey,
referenceClass != null ? HighlightUtil.formatClass(referenceClass) : type.getPresentableText(),
boolean extend = boundClass == null ||
referenceClass == null ||
referenceClass.isInterface() == boundClass.isInterface() ||
referenceClass instanceof PsiTypeParameter;
String description = JavaErrorBundle.message(extend
? "generics.type.parameter.is.not.within.its.bound.extend"
: "generics.type.parameter.is.not.within.its.bound.implement",
referenceClass != null
? HighlightUtil.formatClass(referenceClass)
: type.getPresentableText(),
JavaHighlightUtil.formatType(bound));
HighlightInfo.Builder builder =

View File

@@ -16,5 +16,7 @@ class Foo {
this.<String>xyz<error descr="'xyz(java.lang.String)' in 'Foo' cannot be applied to '(java.lang.Integer)'">(Integer.valueOf("27"))</error>;
ArrayList list = new <error descr="Method 'ArrayList()' does not have type parameters"><String></error>ArrayList<String>();
}
}
public <E> void doo(Bar<<error descr="Type parameter 'E' is not within its bound; should extend 'java.util.List'">E</error>> foo) {}
}
interface Bar<T extends List> {}