mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
OptionalIsPresentInspection: do not warn if map() part can be null
If we cannot determine the non-nullity of map expression, then info level is used. Fixes IDEA-172609 "Replace Optional.isPresent() checks with functional-style expressions" is broken.
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Main {
|
||||
|
||||
public void test(Optional<String> opt, Function<String, Object> onPresent, Supplier<Object> onEmpty) {
|
||||
// information level: could be semantic change if onPresent returns null
|
||||
Object o = opt.map(onPresent::apply).orElseGet(onEmpty::get);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Main {
|
||||
|
||||
public void test(Optional<String> opt, Function<String, @NotNull Object> onPresent, Supplier<Object> onEmpty) {
|
||||
Object o = opt.map(onPresent::apply).orElseGet(onEmpty::get);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "INFORMATION"
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Main {
|
||||
|
||||
public void test(Optional<String> opt, Function<String, Object> onPresent, Supplier<Object> onEmpty) {
|
||||
// information level: could be semantic change if onPresent returns null
|
||||
Object o = opt.is<caret>Present() ? onPresent.apply(opt.get()) : onEmpty.get();
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Main {
|
||||
|
||||
public void test(Optional<String> opt, Function<String, @NotNull Object> onPresent, Supplier<Object> onEmpty) {
|
||||
Object o = opt.i<caret>sPresent() ? onPresent.apply(opt.get()) : onEmpty.get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user