IDEA-162945 Stream API migration: support cases where variable is modified and reassigned

This commit is contained in:
Tagir Valeev
2016-10-21 15:09:35 +07:00
parent b3e0b71a9f
commit 3df2d1925d
6 changed files with 108 additions and 28 deletions
@@ -0,0 +1,11 @@
// "Replace with sum()" "true"
import java.io.BufferedReader;
import java.io.IOException;
public class Main {
void test(BufferedReader br) throws IOException {
long count = br.lines().map(String::trim).mapToLong(String::length).sum();
System.out.println(count);
}
}
@@ -0,0 +1,12 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Main {
public void test(Map<String, String[]> map) {
List<String> result = map.entrySet().stream().filter(entry -> entry.getKey().startsWith("x")).map(Map.Entry::getValue).flatMap(Arrays::stream).map(String::trim).collect(Collectors.toList());
}
}
@@ -0,0 +1,15 @@
// "Replace with sum()" "false"
import java.io.BufferedReader;
import java.io.IOException;
public class Main {
void test(BufferedReader br) throws IOException {
String line = "";
long count = 0;
wh<caret>ile((line = br.readLine()) != null) {
count+=(line = line.trim()).length();
}
System.out.println(count);
}
}
@@ -1,4 +1,4 @@
// "Replace with sum()" "false"
// "Replace with sum()" "true"
import java.io.BufferedReader;
import java.io.IOException;
@@ -0,0 +1,19 @@
// "Replace with collect" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Main {
public void test(Map<String, String[]> map) {
List<String> result = new ArrayList<>();
for(Map.Entry<String, String[]> entry: m<caret>ap.entrySet()) {
if(entry.getKey().startsWith("x")) {
String[] arr = entry.getValue();
for (String str : arr) {
str = str.trim();
result.add(str);
}
}
}
}
}