do not show tooltips for INFORMATION infos for some inspections

This commit is contained in:
Alexey Kudravtsev
2017-02-20 15:52:49 +03:00
parent 0b3a66fc4b
commit 18547af62e
6 changed files with 46 additions and 24 deletions
@@ -100,21 +100,34 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
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;
ProblemHighlightType type = 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;
type = ProblemHighlightType.INFORMATION;
}
}
holder.registerProblem(parent, "Anonymous #ref #loc can be replaced with lambda",
problemHighlightType, rangeInElement, new ReplaceWithLambdaFix());
ProblemDescriptorBase descriptor = new ProblemDescriptorBase(parent, parent, "Anonymous #ref #loc can be replaced with lambda",
new LocalQuickFix[]{new ReplaceWithLambdaFix()},
type, false, rangeInElement,
type != ProblemHighlightType.INFORMATION, true);
holder.registerProblem(descriptor);
}
}
};
}
interface R { void run(); }
void f(R r) {
f(new R() {
@Override
public void run() {
System.out.println();
}
});
}
static boolean hasRuntimeAnnotations(PsiMethod method, @NotNull Set<String> runtimeAnnotationsToIgnore) {
PsiAnnotation[] annotations = method.getModifierList().getAnnotations();
for (PsiAnnotation annotation : annotations) {
@@ -75,10 +75,9 @@ public class SuperClassHasFrequentlyUsedInheritorsInspection extends BaseJavaBat
break;
}
}
return new ProblemDescriptor[]{manager
.createProblemDescriptor(aClass, getDisplayName(), false,
topInheritorsQuickFix.toArray(new LocalQuickFix[topInheritorsQuickFix.size()]),
ProblemHighlightType.INFORMATION)};
return new ProblemDescriptor[]{
manager.createProblemDescriptor(aClass, getDisplayName(), false, ProblemHighlightType.INFORMATION, false,
topInheritorsQuickFix.toArray(new LocalQuickFix[topInheritorsQuickFix.size()]))};
}
@Nullable
@@ -98,11 +98,14 @@ public class AnonymousCanBeMethodReferenceInspection extends BaseJavaBatchLocalI
final PsiElement lBrace = aClass.getLBrace();
LOG.assertTrue(lBrace != null);
final TextRange rangeInElement = new TextRange(0, aClass.getStartOffsetInParent() + lBrace.getStartOffsetInParent());
ProblemHighlightType highlightType = LambdaCanBeMethodReferenceInspection.checkQualifier(lambdaBodyCandidate) ? ProblemHighlightType.LIKE_UNUSED_SYMBOL
ProblemHighlightType type = LambdaCanBeMethodReferenceInspection.checkQualifier(lambdaBodyCandidate) ? ProblemHighlightType.LIKE_UNUSED_SYMBOL
: ProblemHighlightType.INFORMATION;
holder.registerProblem(parent,
"Anonymous #ref #loc can be replaced with method reference",
highlightType, rangeInElement, new ReplaceWithMethodRefFix());
ProblemDescriptorBase descriptor = new ProblemDescriptorBase(parent, parent,
"Anonymous #ref #loc can be replaced with method reference",
new LocalQuickFix[]{new ReplaceWithMethodRefFix()},
type, false, rangeInElement,
type != ProblemHighlightType.INFORMATION, true);
holder.registerProblem(descriptor);
}
}
}
@@ -57,9 +57,12 @@ public class OptionalIsPresentInspection extends BaseJavaBatchLocalInspectionToo
void registerProblem(ProblemsHolder holder, PsiExpression condition, OptionalIsPresentCase scenario) {
if(this != NONE) {
holder.registerProblem(condition, "Can be replaced with single expression in functional style",
this == INFO ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
new OptionalIsPresentFix(scenario));
holder.registerProblem(holder.getManager().createProblemDescriptor(condition,
"Can be replaced with single expression in functional style",
this != INFO,
this == INFO ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
true,
new OptionalIsPresentFix(scenario)));
}
}
}
@@ -107,14 +107,15 @@ public class Java8MapForEachInspection extends BaseJavaBatchLocalInspectionTool
isOnTheFly && (DO_NOT_HIGHLIGHT_LOOP || InspectionProjectProfileManager.isInformationLevel(getShortName(), loop));
TextRange range;
PsiJavaToken rParenth = loop.getRParenth();
PsiElement firstChild = loop.getFirstChild();
if (wholeStatement && rParenth != null) {
range = new TextRange(0, rParenth.getStartOffsetInParent() + 1);
}
else {
range = new TextRange(0, loop.getFirstChild().getTextLength());
range = new TextRange(0, firstChild.getTextLength());
}
holder.registerProblem(loop.getFirstChild(), InspectionsBundle.message("inspection.map.foreach.message"),
type, range, new ReplaceWithMapForEachFix());
holder.registerProblem(new ProblemDescriptorBase(firstChild, firstChild, InspectionsBundle.message("inspection.map.foreach.message"),
new LocalQuickFix[]{new ReplaceWithMapForEachFix()}, type, false, range, type != ProblemHighlightType.INFORMATION, holder.isOnTheFly()));
}
}
};
@@ -95,17 +95,20 @@ public class LambdaCanBeMethodReferenceInspection extends BaseJavaBatchLocalInsp
? ((PsiNewExpression)methodRefCandidate).getQualifier()
: null;
boolean safeQualifier = checkQualifier(qualifier);
ProblemHighlightType errorOrWarning;
ProblemHighlightType type;
if (safeQualifier) {
errorOrWarning = ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
type = ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
}
else {
if (!isOnTheFly) return;
errorOrWarning = ProblemHighlightType.INFORMATION;
type = ProblemHighlightType.INFORMATION;
}
holder.registerProblem(InspectionProjectProfileManager.isInformationLevel(getShortName(), expression) ? expression : candidate,
"Can be replaced with method reference",
errorOrWarning, new ReplaceWithMethodRefFix(safeQualifier ? "" : " (may change semantics)"));
PsiElement element = InspectionProjectProfileManager.isInformationLevel(getShortName(), expression) ? expression : candidate;
holder.registerProblem(holder.getManager().createProblemDescriptor(
element,
"Can be replaced with method reference",
type != ProblemHighlightType.INFORMATION,
type, true, new ReplaceWithMethodRefFix(safeQualifier ? "" : " (may change semantics)")));
}
}
}