diff --git a/java/java-tests/testData/codeInsight/invertIfCondition/afterParenthesis.java b/java/java-tests/testData/codeInsight/invertIfCondition/afterParenthesis.java new file mode 100644 index 000000000000..19bb3770a235 --- /dev/null +++ b/java/java-tests/testData/codeInsight/invertIfCondition/afterParenthesis.java @@ -0,0 +1,10 @@ +// "Invert If Condition" "true" +class A { + public boolean foo(boolean a, boolean b, boolean c, boolean d) { + + if ((a || b) && !c && !d) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/invertIfCondition/beforeParenthesis.java b/java/java-tests/testData/codeInsight/invertIfCondition/beforeParenthesis.java new file mode 100644 index 000000000000..269790ebcd0b --- /dev/null +++ b/java/java-tests/testData/codeInsight/invertIfCondition/beforeParenthesis.java @@ -0,0 +1,9 @@ +// "Invert If Condition" "true" +class A { + public boolean foo(boolean a, boolean b, boolean c, boolean d) { + + if (!(a || b) || c || d) + return false; + return true; + } +} \ No newline at end of file diff --git a/java/openapi/src/com/intellij/codeInsight/CodeInsightServicesUtil.java b/java/openapi/src/com/intellij/codeInsight/CodeInsightServicesUtil.java index e06b22ab9027..7e350d960982 100644 --- a/java/openapi/src/com/intellij/codeInsight/CodeInsightServicesUtil.java +++ b/java/openapi/src/com/intellij/codeInsight/CodeInsightServicesUtil.java @@ -68,7 +68,11 @@ public class CodeInsightServicesUtil { if (expression.getOperationTokenType() == JavaTokenType.EXCL) { PsiExpression operand = expression.getOperand(); if (operand instanceof PsiParenthesizedExpression) { - operand = ((PsiParenthesizedExpression)operand).getExpression(); + final PsiElement parent = booleanExpression.getParent(); + if (parent instanceof PsiPolyadicExpression && + ((PsiPolyadicExpression)parent).getOperationTokenType() == JavaTokenType.ANDAND) { + operand = ((PsiParenthesizedExpression)operand).getExpression(); + } } return operand; }