mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix stream to option codegen: forbid overload Stream.of: IDEA-189448
This commit is contained in:
@@ -170,7 +170,10 @@ public class OptionalUtil {
|
||||
PsiMethod method = mappedStream.resolveMethod();
|
||||
if(method != null && method.getContainingClass() != null) {
|
||||
String className = method.getContainingClass().getQualifiedName();
|
||||
if(className != null && className.startsWith("java.util.stream.")) {
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
if(className != null && className.startsWith("java.util.stream.")
|
||||
&& parameters.length == 1
|
||||
&& !(parameters[0].getType() instanceof PsiArrayType)) {
|
||||
PsiExpression arg = args[0];
|
||||
if(ExpressionUtils.isReferenceTo(arg, var)) {
|
||||
return qualifier + ".stream()";
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Simplify optional chain to '...isPresent()'" "true"
|
||||
import java.util.Optional;
|
||||
|
||||
public class Test {
|
||||
|
||||
public void test() {
|
||||
Optional<String[]> s = Optional.of(new String[] {"1","2","3"});
|
||||
Stream<String> s1 = s.map(Stream::of).orElse(Stream.empty());
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public final class MyClass {
|
||||
}
|
||||
|
||||
public static void testStream(Person p) {
|
||||
p.name().stream().forEach(System.out::println);
|
||||
p.name().stream().flatMap(Stream::of).forEach(System.out::println);
|
||||
p.name().stream().map(String::trim).forEach(System.out::println);
|
||||
p.name().stream().flatMap(n -> Stream.of(n.split(""))).forEach(System.out::println);
|
||||
p.name().stream().mapToInt(String::length).forEach(System.out::println);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Simplify optional chain to 's.stream()'" "false"
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
|
||||
public void test() {
|
||||
Optional<String[]> s = Optional.of(new String[] {"1","2","3"});
|
||||
Stream<String> s1 = s.map(Stream::of).orE<caret>lse(Stream.empty());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user