check that new expression reference resolves to class (IDEA-36082; IDEA-72934)

This commit is contained in:
anna
2013-05-07 10:33:57 +02:00
parent 46f5e570a0
commit 02e4c3acdc
3 changed files with 13 additions and 0 deletions

View File

@@ -951,6 +951,10 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
highlightReferencedMethodOrClassName(ref, resolved);
}
if (parent instanceof PsiNewExpression && !(resolved instanceof PsiClass) && resolved instanceof PsiNamedElement && ((PsiNewExpression)parent).getClassOrAnonymousClassReference() == ref) {
myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(ref)
.descriptionAndTooltip("Cannot find symbol " + ((PsiNamedElement)resolved).getName()).create());
}
if (!myHolder.hasErrorResults() && resolved instanceof PsiClass) {
final PsiClass aClass = ((PsiClass)resolved).getContainingClass();
if (aClass != null) {

View File

@@ -0,0 +1,8 @@
class Test {
void foo(Object obj) {
new <error descr="Cannot find symbol obj">obj</error>();
new <error descr="Cannot find symbol java">java</error>();
new java.lang.Object();
new Object();
}
}

View File

@@ -375,6 +375,7 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testInnerClassConstantReference() { doTest(false, false); }
public void testIDEA60875() { doTest(false, false); }
public void testIDEA71645() { doTest(false, false); }
public void testNewExpressionClass() { doTest(false, false); }
public void testNoEnclosingInstanceWhenStaticNestedInheritsFromContainingClass() throws Exception {
doTest(false, false);