mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
CollapseIntoLoopAction: avoid counting loop for two iterations when step is not +1/-1
GitOrigin-RevId: d8aef85c6d2620a9dd7e9216932388672a049979
This commit is contained in:
committed by
intellij-monorepo-bot
parent
613d4368f1
commit
868aa78cf3
@@ -136,6 +136,8 @@ public class CollapseIntoLoopAction implements IntentionAction {
|
||||
last = cur;
|
||||
}
|
||||
if (start == null || step == null) return null;
|
||||
// Prefer for(int x : new int[] {12, 17}) over for(int x = 12; x <= 17; x+= 5)
|
||||
if (myLoopElements.size() == 2 && step != 1L && step != -1L) return null;
|
||||
String suffix = PsiType.LONG.equals(myType) ? "L" : "";
|
||||
String initial = myType.getCanonicalText() + " " + varName + "=" + start + suffix;
|
||||
String condition =
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Collapse into loop" "true"
|
||||
class X {
|
||||
void test() {
|
||||
for (int i = 12; i <= 22; i += 5) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Collapse into loop" "true"
|
||||
class X {
|
||||
void test() {
|
||||
for (int i : new int[]{12, 17}) {
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Collapse into loop" "true"
|
||||
class X {
|
||||
void test() {
|
||||
<caret>System.out.println(12);
|
||||
System.out.println(17);
|
||||
System.out.println(22);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Collapse into loop" "true"
|
||||
class X {
|
||||
void test() {
|
||||
<caret>System.out.println(12);
|
||||
System.out.println(17);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user