mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-231237 Loop-to-stream conversion produces incorrect code if pattern variable is introduced
Also: pattern variable can be deleted via simple .delete() GitOrigin-RevId: d3523f64d86de28d90b82d7bd98c1fd70567652d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ede907a364
commit
26221c0641
+10
@@ -0,0 +1,10 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class X {
|
||||
void test(List<Object> list) {
|
||||
List<String> result = list.stream().filter(o -> o instanceof String).map(o -> (String) o).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class X {
|
||||
void test(List<Object> list) {
|
||||
List<Object> result = list.stream().filter(o -> getObject(o) instanceof String s && !s.isEmpty()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
native Object getObject(Object obj);
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class X {
|
||||
void test(List<Object> list) {
|
||||
List<String> result = list.stream().filter(o -> o instanceof String s && !s.isEmpty()).map(o -> (String) o).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
class X {
|
||||
void test(List<Object> list) {
|
||||
List<String> result = new ArrayList<>();
|
||||
f<caret>or (Object o : list) {
|
||||
if (o instanceof String s) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
class X {
|
||||
void test(List<Object> list) {
|
||||
List<Object> result = new ArrayList<>();
|
||||
f<caret>or (Object o : list) {
|
||||
if (getObject(o) instanceof String s && !s.isEmpty()) {
|
||||
result.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
native Object getObject(Object obj);
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Fix all 'Loop can be collapsed with Stream API' problems in file" "true"
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
class X {
|
||||
void test(List<Object> list) {
|
||||
List<String> result = new ArrayList<>();
|
||||
f<caret>or (Object o : list) {
|
||||
if (o instanceof String s && !s.isEmpty()) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user