Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/optionalToIf/afterFlatMap.java
Artemiy Sartakov f0c78aea15 OptionalToIfInspection: misc fixes
1. generate if with curly braces when it contains single declaration inside
2. restore else branch after generating code for flatMap
3. do not reassign source variable for nested source operations

GitOrigin-RevId: 061fbcc8d8dda586dcecb9a448752709a43370da
2020-04-21 08:55:39 +00:00

70 lines
1.5 KiB
Java

// "Fix all 'Optional can be replaced with sequence of if statements' problems in file" "true"
import java.util.*;
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;
}
}
void nestedFlatMap(String var0) {
boolean b = false;
if (var0 != null) {
String var2 = var0.toLowerCase();
b = true;
}
}
String flatMapWithOrInside() {
Object o1 = null;
String empty = null;
throw new NoSuchElementException("No value present");
}
<T> T id(T t) {
return t;
}
}