mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 14:01:44 +07:00
StreamToLoopInspection: handle labeled expression statement (found by property testing)
This commit is contained in:
@@ -563,7 +563,14 @@ public class StreamToLoopInspection extends AbstractBaseJavaLocalInspectionTool
|
||||
public PsiElement makeFinalReplacement() {
|
||||
LOG.assertTrue(myStreamExpression != null);
|
||||
if (myFinisher == null || myStreamExpression instanceof PsiStatement) {
|
||||
myCommentTracker.delete(myStreamExpression);
|
||||
PsiElement toDelete = myStreamExpression;
|
||||
if (toDelete instanceof PsiExpression && toDelete.getParent() instanceof PsiExpressionStatement) {
|
||||
toDelete = toDelete.getParent();
|
||||
while (toDelete instanceof PsiExpressionStatement && toDelete.getParent() instanceof PsiLabeledStatement) {
|
||||
toDelete = toDelete.getParent();
|
||||
}
|
||||
}
|
||||
myCommentTracker.delete(toDelete);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
void test() {
|
||||
for (String s : Arrays.asList("foo", "bar", "baz")) {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
String s = "xyz";
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
void test() {
|
||||
test:
|
||||
Stream<caret>.of("foo", "bar", "baz").forEach(System.out::println);
|
||||
|
||||
String s = "xyz";
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user