BoolUtils: fixed for erroneous but parseable expression !()

This commit is contained in:
Tagir Valeev
2018-01-09 11:13:54 +07:00
parent 605cfae244
commit 414a3e5aab
2 changed files with 17 additions and 4 deletions
@@ -58,7 +58,8 @@ public class BoolUtils {
return null;
}
final PsiExpression operand = prefixExpression.getOperand();
return ParenthesesUtils.stripParentheses(operand);
PsiExpression stripped = ParenthesesUtils.stripParentheses(operand);
return stripped == null ? operand : stripped;
}
@NotNull
@@ -95,10 +96,9 @@ public class BoolUtils {
}
if (isNegation(expression)) {
final PsiExpression negated = getNegated(expression);
if (negated == null) {
return "";
if (negated != null) {
return ParenthesesUtils.getText(tracker.markUnchanged(negated), precedence);
}
return ParenthesesUtils.getText(tracker.markUnchanged(negated), precedence);
}
if (expression instanceof PsiPolyadicExpression) {
final PsiPolyadicExpression polyadicExpression = (PsiPolyadicExpression)expression;
@@ -15,4 +15,17 @@ public class FlipConditionalIntentionTest extends IPPTestCase {
"class X { void test(boolean foo, boolean bar) { boolean c = false; boolean b = !foo ? c || bar : true;//comment at the end\n" +
" }}");
}
public void testIncomplete() {
doTest("class X {\n" +
" void test() {\n" +
" System.out.println(/*_Flip '?:'*/!()?\"foo\":\"bar\");\n" +
" }\n" +
"}",
"class X {\n" +
" void test() {\n" +
" System.out.println(() ? \"bar\" : \"foo\");\n" +
" }\n" +
"}");
}
}