mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-17 06:49:59 +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
+54
@@ -0,0 +1,54 @@
|
||||
// "Fix all 'Optional can be replaced with sequence of if statements' problems in file" "true"
|
||||
|
||||
class Test {
|
||||
|
||||
private void reusesVariable(String in) {
|
||||
if (in == null) throw new NullPointerException();
|
||||
String id = id(in);
|
||||
if (id == null) throw new NoSuchElementException("No value present");
|
||||
Object out = id;
|
||||
}
|
||||
|
||||
private void checkIsRemoved(String in) {
|
||||
if (in == null) throw new NullPointerException();
|
||||
String out = in;
|
||||
}
|
||||
|
||||
void simple(String in) {
|
||||
String out = "bar";
|
||||
if (in != null) out = in;
|
||||
}
|
||||
|
||||
void simpleWithMap(String in) {
|
||||
String out = "bar";
|
||||
if (in != null) {
|
||||
String id = id(in);
|
||||
if (id != null) out = id;
|
||||
}
|
||||
}
|
||||
|
||||
void nested(String in) {
|
||||
String out = "bar";
|
||||
if (in != null) out = in;
|
||||
}
|
||||
|
||||
void outer(String in, String p) {
|
||||
String out = "bar";
|
||||
if (in != null) {
|
||||
String value = in + in + p;
|
||||
out = value;
|
||||
}
|
||||
}
|
||||
|
||||
void nullableOuter(String in, String p) {
|
||||
String out = "bar";
|
||||
if (in != null) {
|
||||
if (p == null) throw new NullPointerException();
|
||||
out = p;
|
||||
}
|
||||
}
|
||||
|
||||
<T> T id(T t) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user