From b4703a61d342d2301066987bb7a22d7098c17759 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Thu, 29 Sep 2016 18:33:55 +0200 Subject: [PATCH] allow inspections to report INFORMATION level problems when normal problems are configured, e.g. for special cases where highlighting is not needed but intention could be handy --- .../AnonymousCanBeLambdaInspection.java | 12 ++++++++++-- .../daemon/impl/HighlightInfoFilterImpl.java | 9 ++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java index 0300a2e1f30c..f1d19afeeafc 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java @@ -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()); } } }; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoFilterImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoFilterImpl.java index d96f1a8f4cf9..8faeeeb4e3d5 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoFilterImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoFilterImpl.java @@ -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); } }