ExplicitArrayFillingInspection: detect cases when for loop can be replaced with Arrays.fill call (IDEA-185394)

This commit is contained in:
Artemiy Sartakov
2019-04-19 17:12:13 +07:00
parent 2293202108
commit 861d2c1dde
14 changed files with 105 additions and 67 deletions
@@ -0,0 +1,14 @@
// "Replace loop with 'Arrays.fill' method call" "true"
import java.util.Arrays;
import java.util.List;
public class Test {
public static<T> void fill(T[] data, T value) {
/*comment*/
/*in body*/
/*in lvalue*/
/*in rvalue*/
Arrays.fill(data, value);
}
}
@@ -1,6 +1,6 @@
import java.util.Arrays;
// "Replace loop with Arrays.setAll" "true"
// "Replace loop with 'Arrays.setAll' method call" "true"
public class Test {
private Object[] data;
@@ -1,4 +1,4 @@
// "Replace loop with Arrays.setAll" "true"
// "Replace loop with 'Arrays.setAll' method call" "true"
import java.util.Arrays;
import java.util.List;
@@ -0,0 +1,13 @@
// "Replace loop with 'Arrays.fill' method call" "true"
import java.util.Arrays;
import java.util.List;
public class Test {
public static<T> void fill(T[] data, T value) {
for(int <caret>idx = 0; (/*comment*/data).length > idx; idx+=1) {
/*in body*/
data[/*in lvalue*/idx] = /*in rvalue*/value;
}
}
}
@@ -1,4 +1,4 @@
// "Replace loop with Arrays.setAll" "true"
// "Replace loop with 'Arrays.setAll' method call" "true"
public class Test {
private Object[] data;
@@ -1,4 +1,4 @@
// "Replace loop with Arrays.setAll" "true"
// "Replace loop with 'Arrays.setAll' method call" "true"
import java.util.Arrays;
import java.util.List;
@@ -1,4 +1,4 @@
// "Replace loop with Arrays.setAll" "false"
// "Fix all 'Explicit array filling' problems in file" "false"
import java.util.Arrays;
import java.util.List;
@@ -1,4 +1,4 @@
// "Replace loop with Arrays.setAll" "false"
// "Fix all 'Explicit array filling' problems in file" "false"
import java.util.Arrays;
import java.util.List;