IDEA-182933 Simplifying boolean condition removes necessary brackets and changes semantics

This commit is contained in:
Tagir Valeev
2017-12-01 13:28:36 +07:00
parent 1f504cd082
commit ad807309af
4 changed files with 33 additions and 1 deletions
@@ -0,0 +1,13 @@
class Test {
// IDEA-182933
public static void main(String[] args) {
int a = 1;
int b = 2;
boolean f = false;
String s = "Hello " + (a + b) + (<warning descr="Condition 'f' is always 'false'"><caret>f</warning> ? " Earth" : " World");
System.out.println(s); // Prints Hello 3 World
}
}
@@ -0,0 +1,13 @@
class Test {
// IDEA-182933
public static void main(String[] args) {
int a = 1;
int b = 2;
boolean f = false;
String s = "Hello " + (a + b) + " World";
System.out.println(s); // Prints Hello 3 World
}
}
@@ -498,6 +498,11 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
checkIntentionResult("Simplify 'Test.valueOf(value) != null' to true extracting side effects");
}
public void testSimplifyConcatWithParentheses() {
doTest();
checkIntentionResult("Simplify 'f' to false");
}
public void testSideEffectWhile() {
doTest();
checkIntentionResult("Remove 'while' statement extracting side effects");
@@ -309,7 +309,8 @@ public class ParenthesesUtils {
return;
}
}
if (ignoreClarifyingParentheses) {
if (ignoreClarifyingParentheses ||
(parentOperator == JavaTokenType.PLUS && TypeUtils.isJavaLangString(parentType) && !TypeUtils.isJavaLangString(bodyType))) {
if (parentOperator.equals(bodyOperator)) {
removeParentheses(body, ignoreClarifyingParentheses);
}