mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
StreamToLoopInspection fixed when collection result is non-trivial generic type involving ? extends wildcards
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private List<? extends CharSequence> asList(CharSequence s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
|
||||
public List<? extends CharSequence> getList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private void collect() {
|
||||
List<List<? extends CharSequence>> list = new ArrayList<>();
|
||||
for (CharSequence charSequence : getList()) {
|
||||
List<? extends CharSequence> charSequences = asList(charSequence);
|
||||
list.add(charSequences);
|
||||
}
|
||||
List<? extends List<? extends CharSequence>> res2 = list;
|
||||
System.out.println(res2);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
static class MyList<T, X> extends ArrayList<X> {}
|
||||
|
||||
public List<CharSequence> getList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public MyList<? extends Number, CharSequence> createList() {
|
||||
return new MyList<>();
|
||||
}
|
||||
|
||||
private void collect() {
|
||||
Map<Integer, MyList<? extends Number, CharSequence>> result = new HashMap<>();
|
||||
for (CharSequence x : getList()) {
|
||||
result.computeIfAbsent(x.length(), k -> createList()).add(x);
|
||||
}
|
||||
Map<Integer, ? extends MyList<? extends Number, ? extends CharSequence>> map =
|
||||
result;
|
||||
System.out.println(map);
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
static class MyList<T> extends ArrayList<List<? extends CharSequence>> {
|
||||
}
|
||||
|
||||
private List<? extends CharSequence> asList(CharSequence s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
|
||||
public List<? extends CharSequence> getList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private void collect() {
|
||||
MyList<? extends List<? extends CharSequence>> res2 =
|
||||
new MyList<>();
|
||||
for (CharSequence charSequence : getList()) {
|
||||
List<? extends CharSequence> charSequences = asList(charSequence);
|
||||
res2.add(charSequences);
|
||||
}
|
||||
System.out.println(res2);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public List<? extends CharSequence> asList(CharSequence s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
|
||||
public List<? extends CharSequence> getList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private void collect() {
|
||||
Map<CharSequence, List<? extends CharSequence>> result = new HashMap<>();
|
||||
for (CharSequence charSequence : getList()) {
|
||||
if (Objects.nonNull(charSequence)) {
|
||||
if (result.put(charSequence, asList(charSequence)) != null) {
|
||||
throw new IllegalStateException("Duplicate key");
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<? extends CharSequence, ? extends List<? extends CharSequence>> map = result;
|
||||
System.out.println(map);
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private List<? extends CharSequence> asList(CharSequence s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
|
||||
public List<? extends CharSequence> getList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private void collect() {
|
||||
List<? extends List<? extends CharSequence>> res2 = getList().stream().map(this::asList).col<caret>lect(Collectors.toList());
|
||||
System.out.println(res2);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
static class MyList<T, X> extends ArrayList<X> {}
|
||||
|
||||
public List<CharSequence> getList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public MyList<? extends Number, CharSequence> createList() {
|
||||
return new MyList<>();
|
||||
}
|
||||
|
||||
private void collect() {
|
||||
Map<Integer, ? extends MyList<? extends Number, ? extends CharSequence>> map =
|
||||
getList().stream().co<caret>llect(Collectors.groupingBy(x -> x.length(), Collectors.toCollection(this::createList)));
|
||||
System.out.println(map);
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
static class MyList<T> extends ArrayList<List<? extends CharSequence>> {
|
||||
}
|
||||
|
||||
private List<? extends CharSequence> asList(CharSequence s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
|
||||
public List<? extends CharSequence> getList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private void collect() {
|
||||
MyList<? extends List<? extends CharSequence>> res2 =
|
||||
getList().stream().map(this::asList).coll<caret>ect(Collectors.toCollection(MyList::new));
|
||||
System.out.println(res2);
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public List<? extends CharSequence> asList(CharSequence s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
|
||||
public List<? extends CharSequence> getList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private void collect() {
|
||||
Map<? extends CharSequence, ? extends List<? extends CharSequence>> map = getList()
|
||||
.stream().filter(Objects::nonNull).co<caret>llect(Collectors.toMap(Function.identity(), this::asList));
|
||||
System.out.println(map);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user