mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[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:
committed by
intellij-monorepo-bot
parent
b658e7b73b
commit
577f1b722b
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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(); }
|
||||
|
||||
Reference in New Issue
Block a user