java incompatible types tooltip: include capture in short presentation (IDEA-230232)

GitOrigin-RevId: 22cc104f18f62e0b55738c5c8a72fcb4b8fe828c
This commit is contained in:
Anna.Kozlova
2020-01-28 09:53:31 +01:00
committed by intellij-monorepo-bot
parent 2d86d02e1a
commit dd40888635
3 changed files with 33 additions and 1 deletions

View File

@@ -2898,7 +2898,7 @@ public class HighlightUtil extends HighlightUtilBase {
static String redIfNotMatch(@Nullable PsiType type, boolean matches, boolean shortType) {
if (type == null) return "";
String color = ColorUtil.toHtmlColor(matches ? UIUtil.getToolTipForeground() : DialogWrapper.ERROR_FOREGROUND_COLOR);
return "<font color='" + color + "'>" + XmlStringUtil.escapeString(shortType ? type.getPresentableText() : type.getCanonicalText()) + "</font>";
return "<font color='" + color + "'>" + XmlStringUtil.escapeString(shortType || type instanceof PsiCapturedWildcardType ? type.getPresentableText() : type.getCanonicalText()) + "</font>";
}

View File

@@ -0,0 +1,9 @@
class A<T>{
public void setClazz(Class<T> clazz) {
}
public void m(final A<?> a, Class<?> clazz) {
a.setClazz<error descr="'setClazz(java.lang.Class<capture<?>>)' in 'A' cannot be applied to '(java.lang.Class<capture<?>>)'">(clazz)</error>;
}
}

View File

@@ -1137,6 +1137,29 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
.forEach(info -> Assert.assertEquals(expected, info.getToolTip()));
}
public void testTooltipWithCapture() {
doTest();
String toolTipForeground = ColorUtil.toHtmlColor(UIUtil.getToolTipForeground());
String greyed = ColorUtil.toHtmlColor(UIUtil.getContextHelpForeground());
String red = ColorUtil.toHtmlColor(DialogWrapper.ERROR_FOREGROUND_COLOR);
String expected = "<html><body><table>" +
"<tr>" +
"<td style='padding: 0px 16px 8px 4px;color: " + greyed + "'>Required type:</td>" +
"<td style='padding: 0px 4px 8px 0px;'><font color='" + toolTipForeground + "'>Class</font></td>" +
"<td style='padding: 0px 0px 8px 0px;'>&lt;<font color='" + toolTipForeground + "'>capture of ?</font>&gt;</td>" +
"</tr>" +
"<tr>" +
"<td style='padding: 0px 16px 0px 4px;color: " + greyed + "'>Provided:</td>" +
"<td style='padding: 0px 4px 0px 0px;'><font color='" + toolTipForeground + "'>Class</font></td>" +
"<td style='padding: 0px 0px 0px 0px;'>&lt;<font color='" + red + "'>capture of ?</font>&gt;</td></tr>" +
"</table></body></html>";
doHighlighting()
.stream()
.filter(info -> info.type == HighlightInfoType.ERROR)
.forEach(info -> Assert.assertEquals(expected, info.getToolTip()));
}
public void testTooltipComponents() {
doTest();
String toolTipForeground = ColorUtil.toHtmlColor(UIUtil.getToolTipForeground());