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

This commit is contained in:
Anna.Kozlova
2016-09-29 18:35:29 +02:00
parent 8d7598c6fe
commit b4703a61d3
2 changed files with 16 additions and 5 deletions
@@ -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());
}
}
};
@@ -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);
}
}