mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-09 20:42:52 +07:00
IDEA-167574 Provide inspection for find redundant StreamSupport.stream
Refactor SimplifyStreamApiCallChainsInspection
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ import java.util.List;
|
||||
|
||||
public class Test {
|
||||
public void test(List<List<String>> list) {
|
||||
List<?>[] arr = list.stream().toArray(List[]::new);
|
||||
List<?>[] arr = list.toArray(new List[0]);
|
||||
System.out.println(Arrays.toString(arr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Fix all 'Simplify stream API call chains' problems in file" "true"
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class Test {
|
||||
public static void test(List<String> list, Collection<Number> collection, Iterable<Integer> iterable) {
|
||||
list.stream().filter(Objects::nonNull).forEach(System.out::println);
|
||||
collection.parallelStream().forEach(System.out::println);
|
||||
StreamSupport.stream(iterable.spliterator(), true).forEach(System.out::println);
|
||||
StreamSupport.stream(list.spliterator(), collection.isEmpty()).forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@ import java.util.stream.Stream;
|
||||
|
||||
public class ArraysStreamSingleElementArray {
|
||||
Stream<String[]> stream(String[] args) {
|
||||
return Arrays.<Strin<caret>g[]>asList(args).stream();
|
||||
return Arrays.<String[]>asList(args).st<caret>ream();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@ import java.util.stream.Stream;
|
||||
|
||||
public class ArraysStreamSingleObjectElementArray {
|
||||
Stream<Object[]> stream(String[] args) {
|
||||
return Arrays.<Objec<caret>t[]>asList(args).stream();
|
||||
return Arrays.<Object[]>asList(args).stre<caret>am();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,6 +4,6 @@ import java.util.Arrays;
|
||||
|
||||
class AsListArrayStream {
|
||||
String max(String[] args) {
|
||||
return Arrays.asL<caret>ist(args).stream().max(String::compareTo);
|
||||
return Arrays.asList(args).st<caret>ream().max(String::compareTo);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,6 +4,6 @@ import static java.util.Arrays.asList;
|
||||
|
||||
class AsListArrayStreamStaticImport {
|
||||
String max(String[] args) {
|
||||
return asL<caret>ist(args).stream().max(String::compareTo);
|
||||
return asList(args).st<caret>ream().max(String::compareTo);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@ import java.util.stream.Stream;
|
||||
|
||||
class AsListIncompleteArgsStream {
|
||||
Stream<String> abc() {
|
||||
return Ar<caret>rays.asList("a", , ).stream();
|
||||
return Arrays.asList("a", , ).stre<caret>am();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
List<List<Object>> list = Arrays.<List<Object>>asL<caret>ist(Arrays.asList(1,2,3), Arrays.asList(1.0, 2.0, 3.0)).stream()
|
||||
List<List<Object>> list = Arrays.<List<Object>>asList(Arrays.asList(1,2,3), Arrays.asList(1.0, 2.0, 3.0)).str<caret>eam()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ import java.util.stream.Stream;
|
||||
|
||||
class CollectionEmptyListStream {
|
||||
Stream<String> stream(String[] args) {
|
||||
return args.length == 1 ? Col<caret>lections.<String>emptyList().stream() : Arrays.stream(args);
|
||||
return args.length == 1 ? Collections.<String>emptyList().st<caret>ream() : Arrays.stream(args);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@ import java.util.stream.Stream;
|
||||
|
||||
class CollectionEmptySetStream {
|
||||
Stream<String> stream(String[] args) {
|
||||
return args.length == 1 ? Col<caret>lections.<String>emptySet().stream() : Arrays.stream(args);
|
||||
return args.length == 1 ? Collections.<String>emptySet().st<caret>ream() : Arrays.stream(args);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@ import java.util.stream.Stream;
|
||||
|
||||
class CollectionSingletonArrayStream {
|
||||
Stream<String[]> stream(String[] args) {
|
||||
return Col<caret>lections.singleton(args).stream();
|
||||
return Collections.singleton(args).str<caret>eam();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,6 +5,6 @@ import java.util.stream.Stream;
|
||||
|
||||
class CollectionSingletonStream {
|
||||
Stream<String> stream(String[] args) {
|
||||
return Col<caret>lections.<String>singleton("xyz").stream();
|
||||
return Collections.<String>singleton("xyz").st<caret>ream();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Fix all 'Simplify stream API call chains' problems in file" "true"
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class Test {
|
||||
public static void test(List<String> list, Collection<Number> collection, Iterable<Integer> iterable) {
|
||||
StreamSupport.str<caret>eam(list.spliterator(), false).filter(Objects::nonNull).forEach(System.out::println);
|
||||
StreamSupport.stream(collection.spliterator(), true).forEach(System.out::println);
|
||||
StreamSupport.stream(iterable.spliterator(), true).forEach(System.out::println);
|
||||
StreamSupport.stream(list.spliterator(), collection.isEmpty()).forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user