mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-182933 Simplifying boolean condition removes necessary brackets and changes semantics
This commit is contained in:
+13
@@ -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
|
||||
}
|
||||
}
|
||||
+13
@@ -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");
|
||||
|
||||
+2
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user