IDEA-163767 Simplify optional.isPresent() inspection doesn't suggest simplify trivial case

This commit is contained in:
Tagir Valeev
2016-11-11 13:14:55 +07:00
parent 9fe8c96b78
commit 1d74e0af9d
5 changed files with 59 additions and 13 deletions
@@ -0,0 +1,9 @@
// "Replace Optional.isPresent() condition with functional style expression" "true"
import java.util.*;
public class Main<T> {
Optional<Object> foo(Optional<Object> first) {
return first;
}
}
@@ -0,0 +1,14 @@
// "Replace Optional.isPresent() condition with functional style expression" "false"
import java.util.*;
public class Main<T> {
Optional<Object> foo(Optional<Object> first) {
// could be replaced in Java-9 with return first.or(() -> "xyz");
// but the only option in Java-8 is return first.map(Optional::of).orElseGet(() -> Optional.of("xyz")) which is weird
if (first.isPr<caret>esent()) {
return first;
}
return Optional.of("xyz");
}
}
@@ -0,0 +1,12 @@
// "Replace Optional.isPresent() condition with functional style expression" "true"
import java.util.*;
public class Main<T> {
Optional<Object> foo(Optional<Object> first) {
if (first.isPr<caret>esent()) {
return first;
}
return Optional.empty();
}
}