mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
retrieve inference errors from containing calls as they themselves won't be highlighted as there are errors in arguments (IDEA-150123)
This commit is contained in:
@@ -807,7 +807,7 @@ public class HighlightMethodUtil {
|
||||
|
||||
@Language("HTML")
|
||||
@NonNls String parensizedName = methodName + (parameters.length == 0 ? "( ) " : "");
|
||||
final String errorMessage = info != null ? info.getInferenceErrorMessage() : null;
|
||||
String errorMessage = getErrorMessage(list, info);
|
||||
return JavaErrorMessages.message(
|
||||
"argument.mismatch.html.tooltip",
|
||||
Integer.valueOf(cols - parameters.length + 1), parensizedName,
|
||||
@@ -818,6 +818,25 @@ public class HighlightMethodUtil {
|
||||
);
|
||||
}
|
||||
|
||||
private static String getErrorMessage(PsiExpressionList list, @Nullable MethodCandidateInfo info) {
|
||||
String errorMessage = info != null ? info.getInferenceErrorMessage() : null;
|
||||
while (errorMessage == null) {
|
||||
list = PsiTreeUtil.getParentOfType(list, PsiExpressionList.class, true);
|
||||
if (list == null) {
|
||||
break;
|
||||
}
|
||||
final PsiElement parent = list.getParent();
|
||||
if (!(parent instanceof PsiCallExpression)) {
|
||||
break;
|
||||
}
|
||||
final JavaResolveResult resolveResult = ((PsiCallExpression)parent).resolveMethodGenerics();
|
||||
if (resolveResult instanceof MethodCandidateInfo) {
|
||||
errorMessage = ((MethodCandidateInfo)resolveResult).getInferenceErrorMessage();
|
||||
}
|
||||
}
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
private static String esctrim(@NotNull String s) {
|
||||
return XmlStringUtil.escapeString(trimNicely(s));
|
||||
}
|
||||
@@ -919,7 +938,7 @@ public class HighlightMethodUtil {
|
||||
}
|
||||
|
||||
s+= "</table>";
|
||||
final String errorMessage = info != null ? info.getInferenceErrorMessage() : null;
|
||||
final String errorMessage = getErrorMessage(list, info);
|
||||
if (errorMessage != null) {
|
||||
s+= "reason: ";
|
||||
s += XmlStringUtil.escapeString(errorMessage).replaceAll("\n", "<br/>");
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
class Test {
|
||||
boolean foo(String string) {
|
||||
return true;
|
||||
}
|
||||
|
||||
<K> List<K> bar(Function<K, Boolean> f) {
|
||||
return null;
|
||||
}
|
||||
|
||||
{
|
||||
List<Integer> l = bar(k -> foo<error descr="'foo(java.lang.String)' in 'Test' cannot be applied to '(java.lang.Integer)'">(k)</error>);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -954,4 +954,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testCheckUncheckedAssignmentDuringVariablesResaolution() throws Exception {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testRetrieveInferenceErrorsFromContainingCallsIfCurrentDoesNotProvideAny() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user