mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
Stream API migration: do not convert continue statements which belong to the nested loops (IDEA-204250)
This commit is contained in:
@@ -7,6 +7,7 @@ import com.intellij.psi.controlFlow.ControlFlow;
|
||||
import com.intellij.psi.controlFlow.ControlFlowUtil;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.IntArrayList;
|
||||
@@ -468,6 +469,8 @@ class TerminalBlock {
|
||||
* @param factory factory to use to create new element if necessary
|
||||
*/
|
||||
void replaceContinueWithReturn(PsiElementFactory factory) {
|
||||
PsiLoopStatement currentLoop = PsiTreeUtil.getParentOfType(myStatements[0], PsiLoopStatement.class);
|
||||
if (currentLoop == null) return;
|
||||
for (int i = 0, length = myStatements.length; i < length; i++) {
|
||||
PsiStatement statement = myStatements[i];
|
||||
if(statement instanceof PsiContinueStatement) {
|
||||
@@ -476,6 +479,7 @@ class TerminalBlock {
|
||||
}
|
||||
StreamEx.ofTree(statement, (PsiElement s) -> StreamEx.of(s.getChildren()))
|
||||
.select(PsiContinueStatement.class)
|
||||
.filter(stmt -> stmt.findContinuedStatement() == currentLoop)
|
||||
.forEach(stmt -> new CommentTracker().replaceAndRestoreComments(stmt, "return;"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Replace with forEach" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public class Test {
|
||||
void test(int[] arr, int[] arr2) {
|
||||
Arrays.stream(arr).forEach(x -> {
|
||||
int y = x * 2;
|
||||
if (x > y) return; // comment
|
||||
for (int i : arr2) {
|
||||
if (i % 2 == 0) continue;
|
||||
System.out.println(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace with forEach" "true"
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class Test {
|
||||
void test(int[] arr, int[] arr2) {
|
||||
for<caret>(int x : arr) {
|
||||
int y = x*2;
|
||||
if(x > y) continue; // comment
|
||||
for(int i : arr2) {
|
||||
if (i % 2 == 0) continue;
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user