[java-highlighting] IDEA-265125 Do not highlight 'var' in case if there's a constructor of unresolved type on the right

GitOrigin-RevId: 9ac23e0dcf11c2031c7f08ebd5c6d707d4f7bed1
This commit is contained in:
Tagir Valeev
2021-03-25 11:06:40 +07:00
committed by intellij-monorepo-bot
parent b658e7b73b
commit 577f1b722b
3 changed files with 26 additions and 2 deletions

View File

@@ -2406,7 +2406,8 @@ public final class HighlightUtil {
static HighlightInfo checkIllegalType(@NotNull PsiTypeElement typeElement) {
if (typeElement.getParent() instanceof PsiTypeElement) return null;
PsiElement parent = typeElement.getParent();
if (parent instanceof PsiTypeElement) return null;
if (PsiUtil.isInsideJavadocComment(typeElement)) return null;
@@ -2415,7 +2416,14 @@ public final class HighlightUtil {
if (componentType instanceof PsiClassType) {
PsiClass aClass = PsiUtil.resolveClassInType(componentType);
if (aClass == null) {
String canonicalText = type.getCanonicalText();
if (typeElement.isInferredType() && parent instanceof PsiLocalVariable) {
PsiExpression initializer = PsiUtil.skipParenthesizedExprDown(((PsiLocalVariable)parent).getInitializer());
if (initializer instanceof PsiNewExpression) {
// The problem is already reported on the initializer
return null;
}
}
String canonicalText = componentType.getCanonicalText();
String description = JavaErrorBundle.message("unknown.class", canonicalText);
HighlightInfo info =
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create();

View File

@@ -0,0 +1,15 @@
import java.util.*;
class Main {
void test() {
var x = new <error descr="Cannot resolve symbol 'Person'">Person</error>();
var y = (new <error descr="Cannot resolve symbol 'Person'">Person</error>[10]);
<error descr="Unknown class: 'Person'">var</error> z = getPerson();
<error descr="Unknown class: 'Person'">var</error> w = getPeople();
var l = getPeopleList();
}
native <error descr="Cannot resolve symbol 'Person'">Person</error> getPerson();
native <error descr="Cannot resolve symbol 'Person'">Person</error>[] getPeople();
native List<<error descr="Cannot resolve symbol 'Person'">Person</error>> getPeopleList();
}

View File

@@ -48,6 +48,7 @@ public class LightAdvLVTIHighlightingTest extends LightDaemonAnalyzerTestCase {
}
public void testVarClassNameConflicts() { doTest(); }
public void testVarUnknownClass() { doTest(); }
public void testStandaloneInVarContext() { doTest(); }
public void testUpwardProjection() { doTest(); }