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 fac35822aa13..e6af19f806c1 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/AnonymousCanBeLambdaInspection.java @@ -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 runtimeAnnotationsToIgnore) { PsiAnnotation[] annotations = method.getModifierList().getAnnotations(); for (PsiAnnotation annotation : annotations) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/inheritance/SuperClassHasFrequentlyUsedInheritorsInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/inheritance/SuperClassHasFrequentlyUsedInheritorsInspection.java index e7b9e3e353a4..d7c8e0aa4675 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/inheritance/SuperClassHasFrequentlyUsedInheritorsInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/inheritance/SuperClassHasFrequentlyUsedInheritorsInspection.java @@ -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 diff --git a/java/java-impl/src/com/intellij/codeInspection/AnonymousCanBeMethodReferenceInspection.java b/java/java-impl/src/com/intellij/codeInspection/AnonymousCanBeMethodReferenceInspection.java index 473770741a3e..896a6b7fe4d9 100644 --- a/java/java-impl/src/com/intellij/codeInspection/AnonymousCanBeMethodReferenceInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/AnonymousCanBeMethodReferenceInspection.java @@ -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); } } } diff --git a/java/java-impl/src/com/intellij/codeInspection/OptionalIsPresentInspection.java b/java/java-impl/src/com/intellij/codeInspection/OptionalIsPresentInspection.java index 6fb31afa813d..6f6a69c6c9b8 100644 --- a/java/java-impl/src/com/intellij/codeInspection/OptionalIsPresentInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/OptionalIsPresentInspection.java @@ -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))); } } } diff --git a/java/java-impl/src/com/intellij/codeInspection/java18api/Java8MapForEachInspection.java b/java/java-impl/src/com/intellij/codeInspection/java18api/Java8MapForEachInspection.java index 91b2e197f861..e48e2deacab2 100644 --- a/java/java-impl/src/com/intellij/codeInspection/java18api/Java8MapForEachInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/java18api/Java8MapForEachInspection.java @@ -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())); } } }; diff --git a/plugins/InspectionGadgets/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java b/plugins/InspectionGadgets/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java index adc7e76c69f4..fe7f1bdc5b57 100644 --- a/plugins/InspectionGadgets/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java +++ b/plugins/InspectionGadgets/src/com/intellij/codeInspection/LambdaCanBeMethodReferenceInspection.java @@ -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)"))); } } }