mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
UnrollLoopAction: fixes according to review IDEA-CR-24513
1. Check that loop parameter is not written 2. Support List.of, Collections.singleton, Collections.singletonList 3. Support if w/o braces 4. Support break not in last position
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
// "Unroll loop" "true"
|
||||
class Test {
|
||||
void test() {
|
||||
if (!(Math.random() > 0.5)) {
|
||||
System.out.println((Object) "one");
|
||||
if (!(Math.random() > 0.5)) {
|
||||
System.out.println((Object) 1);
|
||||
if (!(Math.random() > 0.5)) {
|
||||
System.out.println((Object) 1.0);
|
||||
if (!(Math.random() > 0.5)) {
|
||||
System.out.println((Object) 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Unroll loop" "true"
|
||||
class Test {
|
||||
void test(String s1, String s2, String s3) {
|
||||
if (s1.length() <= 5) {
|
||||
System.out.println("Long string: " + s1);
|
||||
if (s1.length() <= 20) {
|
||||
System.out.println("Very long string: " + s1);
|
||||
if (s2.length() <= 5) {
|
||||
System.out.println("Long string: " + s2);
|
||||
if (s2.length() <= 20) {
|
||||
System.out.println("Very long string: " + s2);
|
||||
if (s3.length() <= 5) {
|
||||
System.out.println("Long string: " + s3);
|
||||
if (s3.length() <= 20) {
|
||||
System.out.println("Very long string: " + s3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Unroll loop" "true"
|
||||
class Test {
|
||||
void test(String s1, String s2, String s3) {
|
||||
if ((i += s1.length()) <= 10) {
|
||||
if ((i += s2.length()) <= 10) {
|
||||
if ((i += s3.length()) <= 10) {
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Unroll loop" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
if (!"foo".isEmpty()) {
|
||||
System.out.println("foo");
|
||||
}
|
||||
if (!"bar".isEmpty()) {
|
||||
System.out.println("bar");
|
||||
}
|
||||
if (!"baz".isEmpty()) {
|
||||
System.out.println("baz");
|
||||
}
|
||||
if (!"".isEmpty()) {
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Unroll loop" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
if (!"foo".isEmpty()) {
|
||||
System.out.println("foo");
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Unroll loop" "true"
|
||||
import java.util.Arrays;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
System.out.println("foo");
|
||||
System.out.println("bar");
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Unroll loop" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
if (!"xyz".isEmpty()) {
|
||||
System.out.println("xyz");
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Unroll loop" "false"
|
||||
// "Unroll loop" "true"
|
||||
class Test {
|
||||
void test() {
|
||||
fo<caret>r(Object x : new Object[] {"one", 1, 1.0, 1.0f}) {
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Unroll loop" "false"
|
||||
class Test {
|
||||
void test(String s1, String s2, String s3) {
|
||||
fo<caret>r(String s : new String[] {s1, s2, s3}) {
|
||||
if (!s.isEmpty()) {
|
||||
if(s.length() > 5) break;
|
||||
}
|
||||
System.out.println("Long string: "+s);
|
||||
if(s.length() > 20) break;
|
||||
System.out.println("Very long string: "+s);
|
||||
}
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Unroll loop" "true"
|
||||
class Test {
|
||||
void test(String s1, String s2, String s3) {
|
||||
fo<caret>r(String s : new String[] {s1, s2, s3}) {
|
||||
if(s.length() > 5) break;
|
||||
System.out.println("Long string: "+s);
|
||||
if(s.length() > 20) break;
|
||||
System.out.println("Very long string: "+s);
|
||||
}
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Unroll loop" "true"
|
||||
class Test {
|
||||
void test(String s1, String s2, String s3) {
|
||||
fo<caret>r(String s : new String[] {s1, s2, s3})
|
||||
if((i+=s.length()) > 10) break;
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Unroll loop" "false"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test(String[] data) {
|
||||
fo<caret>r(String s : Arrays.asList(data)) {
|
||||
if(!s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Unroll loop" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
fo<caret>r(String s : List.of("foo", "bar", "baz", "")) {
|
||||
if(!s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Unroll loop" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
fo<caret>r(String s : List.of("foo")) {
|
||||
if(!s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Unroll loop" "true"
|
||||
import java.util.Arrays;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
fo<caret>r(String s : Arrays.asList("foo", "bar")) System.out.println(s);
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Unroll loop" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
fo<caret>r(String s : Collections.singleton("xyz")) {
|
||||
if(!s.isEmpty()) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Unroll loop" "false"
|
||||
class Test {
|
||||
void test() {
|
||||
f<caret>or(int x : new int[]{1, 2, 3}) {
|
||||
System.out.println(x);
|
||||
x = 6;
|
||||
x++;
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
|
||||
void foo(boolean b) {}
|
||||
}
|
||||
Reference in New Issue
Block a user