diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspectionBase.java index cf9cbb0be624..da6c519bb3b6 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspectionBase.java @@ -77,6 +77,14 @@ public class BooleanMethodIsAlwaysInvertedInspectionBase extends GlobalJavaBatch refMethod.putUserData(ALWAYS_INVERTED, Boolean.FALSE); } } + + @Override + public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) { + super.visitMethodReferenceExpression(expression); + if (expression.isReferenceTo(psiElement)) { + refMethod.putUserData(ALWAYS_INVERTED, Boolean.FALSE); + } + } }); } diff --git a/plugins/InspectionGadgets/test/invertedBoolean/methodReferenceIgnored/expected.xml b/plugins/InspectionGadgets/test/invertedBoolean/methodReferenceIgnored/expected.xml new file mode 100644 index 000000000000..5e933496b9cf --- /dev/null +++ b/plugins/InspectionGadgets/test/invertedBoolean/methodReferenceIgnored/expected.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/invertedBoolean/methodReferenceIgnored/src/Test.java b/plugins/InspectionGadgets/test/invertedBoolean/methodReferenceIgnored/src/Test.java new file mode 100644 index 000000000000..40a1948dcfb4 --- /dev/null +++ b/plugins/InspectionGadgets/test/invertedBoolean/methodReferenceIgnored/src/Test.java @@ -0,0 +1,14 @@ +class Test { + { + I ii = this::isFoo; + if (!isFoo()); + } + + boolean isFoo() { + return true; + } + + interface I { + boolean i(); + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/intellij/codeInspection/BooleanMethodInvertedTest.java b/plugins/InspectionGadgets/testsrc/com/intellij/codeInspection/BooleanMethodInvertedTest.java index 0fa73d215602..9051a173773a 100644 --- a/plugins/InspectionGadgets/testsrc/com/intellij/codeInspection/BooleanMethodInvertedTest.java +++ b/plugins/InspectionGadgets/testsrc/com/intellij/codeInspection/BooleanMethodInvertedTest.java @@ -1,5 +1,8 @@ package com.intellij.codeInspection; +import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; import com.siyeh.ig.IGInspectionTestCase; import com.intellij.codeInspection.booleanIsAlwaysInverted.BooleanMethodIsAlwaysInvertedInspection; @@ -61,6 +64,18 @@ public class BooleanMethodInvertedTest extends IGInspectionTestCase { doTest(); } + public void testMethodReferenceIgnored() throws Exception { + final LanguageLevelProjectExtension projectExtension = LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()); + final LanguageLevel oldLevel = projectExtension.getLanguageLevel(); + try { + projectExtension.setLanguageLevel(LanguageLevel.JDK_1_8); + doTest(); + } + finally { + projectExtension.setLanguageLevel(oldLevel); + } + } + private void doTest() throws Exception { doTest(false); }