mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
negation: parenthesis for conditional (IDEA-157530)
This commit is contained in:
+4
-3
@@ -72,9 +72,10 @@ public class BoolUtils {
|
||||
}
|
||||
if (expression instanceof PsiConditionalExpression) {
|
||||
final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)expression;
|
||||
return conditionalExpression.getCondition().getText() +
|
||||
'?' + getNegatedExpressionText(conditionalExpression.getThenExpression()) +
|
||||
':' + getNegatedExpressionText(conditionalExpression.getElseExpression());
|
||||
final boolean needParenthesis = ParenthesesUtils.getPrecedence(conditionalExpression) >= precedence;
|
||||
final String text = conditionalExpression.getCondition().getText() + '?' + getNegatedExpressionText(conditionalExpression.getThenExpression()) +
|
||||
':' + getNegatedExpressionText(conditionalExpression.getElseExpression());
|
||||
return needParenthesis ? "(" + text + ")" : text;
|
||||
}
|
||||
else if (isNegation(expression)) {
|
||||
final PsiExpression negated = getNegated(expression);
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class IssueDemo {
|
||||
private String str1;
|
||||
private String str2;
|
||||
public boolean foo(IssueDemo c) {
|
||||
return (str2 != null ? str2.equals(c.str2) : c.str2 == null) && (str1 != null ? str1.equals(c.str1) : c.str1 == null);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class IssueDemo {
|
||||
private String str1;
|
||||
private String str2;
|
||||
public boolean foo(IssueDemo c) {
|
||||
i<caret>f (str2 != null ? !str2.equals(c.str2) : c.str2 != null) return false;
|
||||
return str1 != null ? str1.equals(c.str1) : c.str1 == null;
|
||||
}
|
||||
}
|
||||
+1
@@ -27,6 +27,7 @@ public class SimplifiableIfStatementFixTest extends IGQuickFixesTestCase {
|
||||
public void testComments() { doTest(); }
|
||||
public void testParentheses() { doTest(); }
|
||||
public void testMoreParentheses() { doTest(); }
|
||||
public void testParenthesesForConditional() { doTest(); }
|
||||
public void testPrecedence() { doTest(); }
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user