IDEA-163764 "Replace Optional.isPresent() checks with functional-style expressions" create uncompilable code

IDEA-163463 Stream API migration: type argument before map appears sometimes when it's unnecessary
This commit is contained in:
Tagir Valeev
2016-11-11 11:28:44 +07:00
parent 67c4dfb483
commit 7e574d661c
16 changed files with 190 additions and 16 deletions
@@ -5,7 +5,7 @@ import java.util.stream.Collectors;
public class Main {
public List<Runnable> test(List<String> list) {
List<Runnable> result = list.stream().<Runnable>map(s -> new Runnable() {
List<Runnable> result = list.stream().map(s -> new Runnable() {
@Override
public void run() {
String str = s;
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public List<CharSequence> getListCharSequence(List<String> input) {
List<CharSequence> result = input.stream().filter(s -> !s.isEmpty()).map(String::trim).collect(Collectors.toList());
return result;
}
}
@@ -0,0 +1,10 @@
// "Replace with findFirst()" "true"
import java.util.*;
public class Main {
public List<String> getErrors(List<String> data) {
List<String> def = Collections.singletonList("Not found");
return data.stream().filter(s -> s.startsWith("xyz")).findFirst().<List<String>>map(s -> s.length() < 10 ? Collections.emptyList() : Arrays.asList()).orElse(def);
}
}
@@ -0,0 +1,10 @@
// "Replace with findFirst()" "true"
import java.util.*;
public class Main {
public Runnable getRunnable(List<String> data) {
Runnable def = () -> {};
return data.stream().filter(s -> s.startsWith("xyz")).findFirst().<Runnable>map(s -> s.length() > 2 ? s::trim : System.out::println).orElse(def);
}
}
@@ -0,0 +1,15 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
public List<CharSequence> getListCharSequence(List<String> input) {
List<CharSequence> result = new ArrayList<>();
for(String s : in<caret>put) {
if(!s.isEmpty()) {
result.add(s.trim());
}
}
return result;
}
}
@@ -0,0 +1,15 @@
// "Replace with findFirst()" "true"
import java.util.*;
public class Main {
public List<String> getErrors(List<String> data) {
List<String> def = Collections.singletonList("Not found");
for(String s : dat<caret>a) {
if(s.startsWith("xyz")) {
return s.length() < 10 ? Collections.emptyList() : Arrays.asList();
}
}
return def;
}
}
@@ -0,0 +1,15 @@
// "Replace with findFirst()" "true"
import java.util.*;
public class Main {
public Runnable getRunnable(List<String> data) {
Runnable def = () -> {};
for(String s : dat<caret>a) {
if(s.startsWith("xyz")) {
return s.length() > 2 ? s::trim : System.out::println;
}
}
return def;
}
}