Cleanup (warnings; formatting)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Fri, 16 Sep 2016 07:39:39 +0000 (10:39 +0300)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Fri, 16 Sep 2016 07:39:39 +0000 (10:39 +0300)
java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightVisitorImpl.java
java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NewExpressionClass.java

index a9694ca70a7d7cf31b6c83ba26121336cc2c9265..810b710dca70ed00b00310f3d1bac62cca62ca9f 100644 (file)
@@ -1036,13 +1036,16 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
     catch (IndexNotReadyException e) {
       return null;
     }
+
     PsiElement resolved = result.getElement();
     PsiElement parent = ref.getParent();
 
     if (myRefCountHolder != null) {
       myRefCountHolder.registerReference(ref, result);
     }
+
     myHolder.add(HighlightUtil.checkReference(ref, result, myFile, myLanguageLevel));
+
     if (parent instanceof PsiJavaCodeReferenceElement || ref.isQualified()) {
       if (!myHolder.hasErrorResults() && resolved instanceof PsiTypeParameter) {
         boolean cannotSelectFromTypeParameter = !myJavaSdkVersion.isAtLeast(JavaSdkVersion.JDK_1_7);
@@ -1060,13 +1063,14 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
         }
       }
     }
+
     if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkAbstractInstantiation(ref));
     if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkExtendsDuplicate(ref, resolved,myFile));
     if (!myHolder.hasErrorResults()) myHolder.add(HighlightClassUtil.checkClassExtendsForeignInnerClass(ref, resolved));
     if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkSelectStaticClassFromParameterizedType(resolved, ref));
-    if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkParameterizedReferenceTypeArguments(resolved, ref,
-                                                                                                                 result.getSubstitutor(),
-                                                                                                                 myJavaSdkVersion));
+    if (!myHolder.hasErrorResults()) {
+      myHolder.add(GenericsHighlightUtil.checkParameterizedReferenceTypeArguments(resolved, ref, result.getSubstitutor(), myJavaSdkVersion));
+    }
     if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkCannotPassInner(ref));
 
     if (resolved != null && parent instanceof PsiReferenceList) {
@@ -1085,13 +1089,13 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
     if (resolved instanceof PsiVariable) {
       PsiVariable variable = (PsiVariable)resolved;
 
-      final PsiElement containingClass = PsiTreeUtil.getNonStrictParentOfType(ref, PsiClass.class, PsiLambdaExpression.class);
+      PsiElement containingClass = PsiTreeUtil.getNonStrictParentOfType(ref, PsiClass.class, PsiLambdaExpression.class);
       if ((containingClass instanceof PsiAnonymousClass || containingClass instanceof PsiLambdaExpression) &&
           !PsiTreeUtil.isAncestor(containingClass, variable, false) &&
-          !(variable instanceof PsiField)) {
-        if (containingClass instanceof PsiLambdaExpression || !PsiTreeUtil.isAncestor(((PsiAnonymousClass) containingClass).getArgumentList(), ref, false)) {
-          myHolder.add(HighlightInfo.newHighlightInfo(JavaHighlightInfoTypes.IMPLICIT_ANONYMOUS_CLASS_PARAMETER).range(ref).create());
-        }
+          !(variable instanceof PsiField) &&
+          (containingClass instanceof PsiLambdaExpression ||
+           !PsiTreeUtil.isAncestor(((PsiAnonymousClass)containingClass).getArgumentList(), ref, false))) {
+        myHolder.add(HighlightInfo.newHighlightInfo(JavaHighlightInfoTypes.IMPLICIT_ANONYMOUS_CLASS_PARAMETER).range(ref).create());
       }
 
       if (variable instanceof PsiParameter && ref instanceof PsiExpression && PsiUtil.isAccessedForWriting((PsiExpression)ref)) {
@@ -1103,7 +1107,10 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
         myHolder.add(HighlightNamesUtil.highlightReassignedVariable(variable, ref));
       }
       else {
-        myHolder.add(HighlightNamesUtil.highlightVariableName(variable, ref.getReferenceNameElement(), colorsScheme));
+        PsiElement nameElement = ref.getReferenceNameElement();
+        if (nameElement != null) {
+          myHolder.add(HighlightNamesUtil.highlightVariableName(variable, nameElement, colorsScheme));
+        }
       }
       myHolder.add(HighlightNamesUtil.highlightClassNameInQualifier(ref, colorsScheme));
     }
@@ -1111,10 +1118,14 @@ 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 (parent instanceof PsiNewExpression &&
+        !(resolved instanceof PsiClass) &&
+        resolved instanceof PsiNamedElement &&
+        ((PsiNewExpression)parent).getClassOrAnonymousClassReference() == ref) {
+      String text = JavaErrorMessages.message("cannot.resolve.symbol", ((PsiNamedElement)resolved).getName());
+      myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(ref).descriptionAndTooltip(text).create());
     }
+
     if (!myHolder.hasErrorResults() && resolved instanceof PsiClass) {
       final PsiClass aClass = ((PsiClass)resolved).getContainingClass();
       if (aClass != null) {
index 4cfc983f39eb21dc4d29221b76202243b8b6e9fd..4a25d1d9715494b63994c7587e298372cbf7ce4e 100644 (file)
@@ -1,7 +1,7 @@
 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 <error descr="Cannot resolve symbol 'obj'">obj</error>();
+    new <error descr="Cannot resolve symbol 'java'">java</error>();
     new java.lang.Object();
     new Object();
   }