mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-17 21:43:33 +07:00
Simplify boolean expression improvements
1. Add "may change semantics" when side-effect cannot be extracted 2. Use condition reporting (instead of constant value reporting) for non-short-circuiting & and | (fixes IDEA-216245) 3. Use SimplifyBooleanExpressionFix for boolean constant value instead of replace fix. GitOrigin-RevId: f3e63a75bd92a7305e36fce58bf9e34bdbb03c51
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a7decca33a
commit
0b3fd46151
+10
@@ -0,0 +1,10 @@
|
||||
// "Simplify 'Objects.nonNull(...)' to true extracting side effects" "true"
|
||||
import java.util.Set;
|
||||
import java.util.Objects;
|
||||
|
||||
class X {
|
||||
void test(Set<String> set) {
|
||||
set.add("foo");
|
||||
boolean b = true;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Unwrap 'do-while' statement (may change semantics)" "true"
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
class X {
|
||||
@Contract("_ -> true")
|
||||
boolean test(Object obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void doSmth(Object obj) {
|
||||
System.out.println("aaahh");
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Simplify 'pureConsumer(...)' to true extracting side effects" "true"
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
public class Main {
|
||||
private static int counter = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
while (true) {
|
||||
sideEffect();
|
||||
if (!(counter < 5)) break;
|
||||
System.out.println(counter);
|
||||
}
|
||||
}
|
||||
|
||||
@Contract(value = "!null->true;null->false", pure = true)
|
||||
private static boolean pureConsumer(Object consumed) {
|
||||
return consumed != null;
|
||||
}
|
||||
|
||||
private static int sideEffect() {
|
||||
return counter++;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Simplify 'Objects.nonNull(...)' to true extracting side effects" "true"
|
||||
import java.util.Set;
|
||||
import java.util.Objects;
|
||||
|
||||
class X {
|
||||
void test(Set<String> set) {
|
||||
boolean b = Objects.nonNull(set.<caret>add("foo"));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Unwrap 'do-while' statement (may change semantics)" "true"
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
class X {
|
||||
@Contract("_ -> true")
|
||||
boolean test(Object obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void doSmth(Object obj) {
|
||||
do {
|
||||
System.out.println("aaahh");
|
||||
}
|
||||
while(obj <caret>!= null && test(obj) && obj == null);
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Simplify 'pureConsumer(...)' to true extracting side effects" "true"
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
public class Main {
|
||||
private static int counter = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
while (pureConsumer<caret>(sideEffect()) & counter < 5) {
|
||||
System.out.println(counter);
|
||||
}
|
||||
}
|
||||
|
||||
@Contract(value = "!null->true;null->false", pure = true)
|
||||
private static boolean pureConsumer(Object consumed) {
|
||||
return consumed != null;
|
||||
}
|
||||
|
||||
private static int sideEffect() {
|
||||
return counter++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user