[java][highlight] IDEA-274531 errors shown incorrectly when a method name is the same as a nested class name

IDEA added a fix to remove the "new" keyword when a callsite looks like a call to a method or a field. It caused the mentioned regression, because sometimes the callsite might simply instantiate a class that has the same name as a method which was mistakenly highlighted as an error. This patch simply adds a check if the resolved element is of a PsiClass and if so then the mentioned highlighting doesn't get added to such callsites.

GitOrigin-RevId: a34e6e1715d93ac21a2ba93cf5f57c54436bc11b
This commit is contained in:
Nikita Eshkeev
2021-07-28 19:15:35 +00:00
committed by intellij-monorepo-bot
parent 5657d92469
commit 383d5a0aab
2 changed files with 15 additions and 1 deletions
@@ -2958,7 +2958,7 @@ public final class HighlightUtil {
PsiElement refParent = ref.getParent();
if (isCallToStaticMember(refParent)) {
if (!(resolved instanceof PsiClass) && isCallToStaticMember(refParent)) {
final String text = JavaErrorBundle.message("cannot.resolve.symbol", refName.getText());
final HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(ref).descriptionAndTooltip(text).create();
QuickFixAction.registerQuickFixAction(info, new RemoveNewKeywordFix(refParent));
@@ -3000,6 +3000,12 @@ public final class HighlightUtil {
}
else {
description = JavaErrorBundle.message("cannot.resolve.symbol", refName.getText());
if (isCallToStaticMember(refParent)) {
final String text = JavaErrorBundle.message("cannot.resolve.symbol", refName.getText());
final HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(ref).descriptionAndTooltip(text).create();
QuickFixAction.registerQuickFixAction(info, new RemoveNewKeywordFix(refParent));
return info;
}
}
HighlightInfo info =
@@ -0,0 +1,8 @@
// "Remove 'new'" "false"
class A {
class B {}
B B() {
return new A.<caret>B();
}
}