mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-17 08:59:21 +07:00
OptionalToIfInspection: added inspection to desugar optional chain to sequence of if statements (IDEA-212269)
GitOrigin-RevId: c83b70e05544529b3dfffe24bc87997910edcb56
This commit is contained in:
committed by
intellij-monorepo-bot
parent
987f5c84d3
commit
6f1efb8fc0
+36
@@ -0,0 +1,36 @@
|
||||
// "Fix all 'Optional can be replaced with sequence of if statements' problems in file" "true"
|
||||
|
||||
class Test {
|
||||
|
||||
private void reusesVariable(String in) {
|
||||
Object out = Optional.of<caret>(in).flatMap(o -> Optional.of(o)).map(o -> id(o)).get();
|
||||
}
|
||||
|
||||
private void checkIsRemoved(String in) {
|
||||
String out = Optional.of(in).flatMap(s -> Optional.of(in)).get();
|
||||
}
|
||||
|
||||
void simple(String in) {
|
||||
String out = Optional.ofNullable<caret>(in).flatMap(s -> Optional.of(s)).orElse("bar");
|
||||
}
|
||||
|
||||
void simpleWithMap(String in) {
|
||||
String out = Optional.ofNullable<caret>(in).flatMap(s -> Optional.of(s).map(v -> id(v))).orElse("bar");
|
||||
}
|
||||
|
||||
void nested(String in) {
|
||||
String out = Optional.ofNullable(in).flatMap(s1 -> Optional.of(s1).flatMap(s2 -> Optional.of(s2))).orElse("bar");
|
||||
}
|
||||
|
||||
void outer(String in, String p) {
|
||||
String out = Optional.ofNullable(in).flatMap(s1 -> Optional.of(s1).flatMap(s2 -> Optional.of(s2 + s1 + p))).orElse("bar");
|
||||
}
|
||||
|
||||
void nullableOuter(String in, String p) {
|
||||
String out = Optional.ofNullable(in).flatMap(s1 -> Optional.of(p)).orElse("bar");
|
||||
}
|
||||
|
||||
<T> T id(T t) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user