diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index aa0b485e96fc..a98cda24ab24 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1430,6 +1430,12 @@ public class HighlightUtil extends HighlightUtilBase { HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(parentExpr).descriptionAndTooltip(message).create(); if (parentExpr instanceof PsiPrefixExpression && token.getTokenType() == JavaTokenType.EXCL) { QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createNegationBroadScopeFix((PsiPrefixExpression)parentExpr)); + if (expression instanceof PsiMethodCallExpression) { + PsiMethod method = ((PsiMethodCallExpression)expression).resolveMethod(); + if (method != null) { + QuickFixAction.registerQuickFixAction(highlightInfo, QUICK_FIX_FACTORY.createMethodReturnFix(method, PsiType.BOOLEAN, true)); + } + } } return highlightInfo; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/afterNegated.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/afterNegated.java new file mode 100644 index 000000000000..0a5edfb085d2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/afterNegated.java @@ -0,0 +1,16 @@ +// "Make 'victim' return 'boolean'" "true" +class Test { + public void trigger() { + if (!victim()) { + System.out.println("***"); + } + } + + public boolean victim() { + final int something = 1; + final boolean value = false; + int another = 10; + final boolean secondBoolean = another == something; + return value; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/beforeNegated.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/beforeNegated.java new file mode 100644 index 000000000000..fe61b9faed1b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/methodReturnBooleanFix/beforeNegated.java @@ -0,0 +1,15 @@ +// "Make 'victim' return 'boolean'" "true" +class Test { + public void trigger() { + if (!victim()) { + System.out.println("***"); + } + } + + public void victim() { + final int something = 1; + final boolean value = false; + int another = 10; + final boolean secondBoolean = another == something; + } +} \ No newline at end of file