mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
StreamToLoopInspection fixes: toArray intermediate list type fixed; keywords are filtered out from possible var names; context added to expression passed to BoolUtils; supported inside method calls
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static boolean test(List<String> list) {
|
||||
for (String s : list) {
|
||||
if (s.trim() != s.toLowerCase()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static test(List<String> packages) {
|
||||
Optional<String> found = Optional.empty();
|
||||
for (String s : packages) {
|
||||
if (s.startsWith("xyz")) {
|
||||
found = Optional.of(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found.filter(pkg -> pkg.endsWith("abc")).isPresent();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("xyzabc", "xyz123", "123abc", "123")));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> test) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : test) {
|
||||
sb.append(s);
|
||||
}
|
||||
System.out.println("x"+ sb.toString() +"y");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static List<?>[] test(int[] numbers) {
|
||||
List<List<?>> list = new ArrayList<>();
|
||||
List<List<Integer>> list = new ArrayList<>();
|
||||
for (int number : numbers) {
|
||||
Integer n = number;
|
||||
List<Integer> integers = Collections.singletonList(n);
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static Object[] test(int[] numbers) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for (int number : numbers) {
|
||||
Integer integer = number;
|
||||
list.add(integer);
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static Number[] test(Object[] objects) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (Object object : objects) {
|
||||
if (Number.class.isInstance(object)) {
|
||||
list.add(object);
|
||||
}
|
||||
}
|
||||
return list.toArray(new Number[0]);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.asList(test(new Object[]{1, 2, 3, "string", 4})));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static boolean test(List<String> list) {
|
||||
return list.stream().al<caret>lMatch(s -> s.trim() == s.toLowerCase());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static test(List<String> packages) {
|
||||
return packages.stream().filter(pkg -> pkg.startsWith("xyz")).fin<caret>dAny().filter(pkg -> pkg.endsWith("abc")).isPresent();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("xyzabc", "xyz123", "123abc", "123")));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> test) {
|
||||
System.out.println("x"+test.stream().c<caret>ollect(Collectors.joining())+"y");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static Number[] test(Object[] objects) {
|
||||
return Stream.of(objects).filter(Number.class::isInstance).toArr<caret>ay(Number[]::new);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.asList(test(new Object[]{1, 2, 3, "string", 4})));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user