allow inspections to report INFORMATION level problems when normal problems are confi...
authorAnna.Kozlova <anna.kozlova@jetbrains.com>
Thu, 29 Sep 2016 16:33:55 +0000 (18:33 +0200)
committerAnna.Kozlova <anna.kozlova@jetbrains.com>
Thu, 29 Sep 2016 16:35:29 +0000 (18:35 +0200)
java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoFilterImpl.java

index 0300a2e1f30cc9e6d5d7752faddb7308c7c71e3a..f1d19afeeafc2d621853eb9c137b7168ac4ea0c3 100644 (file)
@@ -96,12 +96,20 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
         final PsiElement lambdaContext = parent != null ? parent.getParent() : null;
         if (lambdaContext != null && 
             (LambdaUtil.isValidLambdaContext(lambdaContext) || !(lambdaContext instanceof PsiExpressionStatement)) &&
-            canBeConvertedToLambda(aClass, false, reportNotAnnotatedInterfaces, Collections.emptySet())) {
+            canBeConvertedToLambda(aClass, false, isOnTheFly || reportNotAnnotatedInterfaces, Collections.emptySet())) {
           final PsiElement lBrace = aClass.getLBrace();
           LOG.assertTrue(lBrace != null);
           final TextRange rangeInElement = new TextRange(0, aClass.getStartOffsetInParent() + lBrace.getStartOffsetInParent());
+          ProblemHighlightType problemHighlightType = ProblemHighlightType.LIKE_UNUSED_SYMBOL;
+          if (isOnTheFly && !reportNotAnnotatedInterfaces) {
+            final PsiClass baseClass = aClass.getBaseClassType().resolve();
+            LOG.assertTrue(baseClass != null);
+            if (!AnnotationUtil.isAnnotated(baseClass, CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, false, false)) {
+              problemHighlightType = ProblemHighlightType.INFORMATION;
+            }
+          }
           holder.registerProblem(parent, "Anonymous #ref #loc can be replaced with lambda",
-                                 ProblemHighlightType.LIKE_UNUSED_SYMBOL, rangeInElement, new ReplaceWithLambdaFix());
+                                 problemHighlightType, rangeInElement, new ReplaceWithLambdaFix());
         }
       }
     };
index d96f1a8f4cf9c471fc5beb353a3d75a9675852f0..8faeeeb4e3d5ea44398c42a280e82029679212e6 100644 (file)
@@ -29,11 +29,14 @@ public class HighlightInfoFilterImpl implements HighlightInfoFilter {
 
   @Override
   public boolean accept(@NotNull HighlightInfo info, PsiFile file) {
-    if (Holder.ourTestMode) return true; // Tests need to verify highlighting is applied no matter what attributes are defined for this kind of highlighting
+    if (Holder.ourTestMode) {
+      return true; // Tests need to verify highlighting is applied no matter what attributes are defined for this kind of highlighting
+    }
 
     TextAttributes attributes = info.getTextAttributes(file, null);
     // optimization
-     return attributes == TextAttributes.ERASE_MARKER || attributes != null &&
-           !(attributes.isEmpty() && info.getSeverity() == HighlightSeverity.INFORMATION && info.getGutterIconRenderer() == null);
+    return attributes == TextAttributes.ERASE_MARKER ||
+           attributes != null &&
+           !(attributes.isEmpty() && info.getSeverity() == HighlightSeverity.INFORMATION && info.getGutterIconRenderer() == null && info.getToolTip() == null);
   }
 }