mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-17 21:43:33 +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
+25
@@ -0,0 +1,25 @@
|
||||
// "Fix all 'Optional can be replaced with sequence of if statements' problems in file" "true"
|
||||
|
||||
class Test {
|
||||
|
||||
void exceptionIsThrownOnNullValue(String in) {
|
||||
String out = Optional.of<caret>(in).get();
|
||||
}
|
||||
|
||||
void exceptionIsTheSameWithOrElseThrow(String in) {
|
||||
Integer out = Optional.of(in).map(s -> getLen(s)).orElseThrow(() -> new IllegalArgumentException("value is null"));
|
||||
}
|
||||
|
||||
void redundantCheckIsRemoved() {
|
||||
String in = "not null value";
|
||||
String out = Optional.of(in).orElseThrow(() -> new IllegalArgumentException("value is null"));
|
||||
}
|
||||
|
||||
private Integer getLen(String s) {
|
||||
return s.startsWith("abc") ? null : s;
|
||||
}
|
||||
|
||||
private Integer filterLen(String s) {
|
||||
return s.length() > 42 ? s.length() : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user