mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +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
+29
@@ -0,0 +1,29 @@
|
||||
// "Fix all 'Optional can be replaced with sequence of if statements' problems in file" "true"
|
||||
|
||||
class Test {
|
||||
|
||||
String checkForNullable(String in) {
|
||||
return Optional.<caret>of(in).map(s -> getStrOrNull(s)).get();
|
||||
}
|
||||
|
||||
String checkIsRemovedForNotNull(String in) {
|
||||
return Optional.of(in).map(s -> id(s)).filter(s -> s.length() > 2).get();
|
||||
}
|
||||
|
||||
String twoMapsProduceTwoVariables(String in, boolean b) {
|
||||
return Optional.of(in).map(s -> id(s)).map(s -> getStrIfTrue(s, b)).filter(s -> s.length > 2).get();
|
||||
}
|
||||
|
||||
private String id(String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
private String getStrOrNull(String s) {
|
||||
return s.length() > 2 ? s : null;
|
||||
}
|
||||
|
||||
private String getStrIfTrue(String s, boolean b) {
|
||||
return b ? s : null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user