StreamApiMigrationInspection: improve stream source recognition

This commit is contained in:
Roman
2017-09-27 12:28:23 +07:00
parent 1779a8a871
commit 545ae69261
19 changed files with 571 additions and 30 deletions
@@ -0,0 +1,14 @@
// "Replace with collect" "true"
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
List<String> test(BufferedReader br) throws IOException {
List<String> result = br.lines().map(String::trim).collect(Collectors.toList());
return result;
}
}
@@ -0,0 +1,14 @@
// "Replace with collect" "true"
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
List<String> test(BufferedReader br) throws IOException {
List<String> result = br.lines().map(String::trim).collect(Collectors.toList());
return result;
}
}
@@ -0,0 +1,16 @@
// "Replace with collect" "true"
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Main {
List<String> test(BufferedReader br) throws IOException {
List<String> result = new ArrayList<>();
for <caret>(String line = br.readLine(); line != null; line = br.readLine()) {
result.add(line.trim());
}
return result;
}
}
@@ -0,0 +1,16 @@
// "Replace with collect" "true"
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Main {
List<String> test(BufferedReader br) throws IOException {
List<String> result = new ArrayList<>();
for <caret>(String line; (line = br.readLine()) != null; ) {
result.add(line.trim());
}
return result;
}
}
@@ -0,0 +1,17 @@
// "Replace with forEach" "true"
import java.util.function.UnaryOperator;
import java.util.stream.Stream;
public class Main {
static class A {
A next(){return null;}
int x;
}
static boolean isGood(A a) {}
public long test() {
Stream.iterate(new A(), (UnaryOperator<A>) Main::isGood, a -> a.next()).filter(a -> a.x < 3).forEach(System.out::println);
}
}
@@ -0,0 +1,18 @@
// "Replace with forEach" "true"
public class Main {
static class A {
A next(){return null;}
int x;
}
static boolean isGood(A a) {}
public long test() {
for <caret>(A a = new A(); isGood(a); a = a.next()) {
if(a.x < 3) {
System.out.println(a);
}
}
}
}
@@ -0,0 +1,13 @@
// "Replace with forEach" "false"
public class Main {
public long test() {
int j = 0;
for <caret>(int i = 0; j < 10; j = j + i) {
if(i < 3) {
System.out.println(i);
}
}
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static int find(List<List<String>> list) {
String sb = IntStream.iterate(0, i -> i + 1).filter(i -> i % 100 == 0).mapToObj(String::valueOf).collect(Collectors.joining());
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static int find(List<List<String>> list) {
String sb = IntStream.iterate(0, i -> i + 23 * 11).filter(i -> i % 100 == 0).mapToObj(String::valueOf).collect(Collectors.joining());
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static int find(List<List<String>> list) {
String sb = IntStream.iterate(0, i -> i * (i + 23)).filter(i -> i % 100 == 0).mapToObj(String::valueOf).collect(Collectors.joining());
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static int find(List<List<String>> list) {
String sb = IntStream.iterate(0, i -> (int) (i + 10L)).filter(i -> i % 100 == 0).mapToObj(String::valueOf).collect(Collectors.joining());
}
}
@@ -0,0 +1,19 @@
// "Replace with collect" "true"
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class A {
B next() {return null;}
int x;
}
class B extends A {}
public class Main {
public static int find(List<List<String>> list) {
String sb = Stream.iterate(new A(), A::next).filter(a -> a.x % 100 == 0).map(a -> String.valueOf(a.x)).collect(Collectors.joining());
}
}
@@ -0,0 +1,14 @@
// "Replace with collect" "true"
import java.util.List;
public class Main {
public static int find(List<List<String>> list) {
StringBuilder sb = new StringBuilder();
for <caret> (int i = 0;; i++) {
if(i % 100 == 0) {
sb.append(i);
}
}
}
}
@@ -0,0 +1,14 @@
// "Replace with collect" "true"
import java.util.List;
public class Main {
public static int find(List<List<String>> list) {
StringBuilder sb = new StringBuilder();
for <caret> (int i = 0;; i = i + 23 * 11) {
if(i % 100 == 0) {
sb.append(i);
}
}
}
}
@@ -0,0 +1,14 @@
// "Replace with collect" "true"
import java.util.List;
public class Main {
public static int find(List<List<String>> list) {
StringBuilder sb = new StringBuilder();
for <caret> (int i = 0;; i *= i + 23) {
if(i % 100 == 0) {
sb.append(i);
}
}
}
}
@@ -0,0 +1,14 @@
// "Replace with collect" "true"
import java.util.List;
public class Main {
public static int find(List<List<String>> list) {
StringBuilder sb = new StringBuilder();
for <caret> (int i = 0;; i += 10L) {
if(i % 100 == 0) {
sb.append(i);
}
}
}
}
@@ -0,0 +1,22 @@
// "Replace with collect" "true"
import java.util.List;
class A {
B next() {return null;}
int x;
}
class B extends A {}
public class Main {
public static int find(List<List<String>> list) {
StringBuilder sb = new StringBuilder();
for <caret> (A a = new A();; a = a.next()) {
if(a.x % 100 == 0) {
sb.append(a.x);
}
}
}
}