IDEA-182206 Simplification for Arrays.asList().sublist().toArray()

This commit is contained in:
Tagir Valeev
2017-11-23 11:52:59 +07:00
parent 5d82bf9ea8
commit 0393b4fe2f
16 changed files with 394 additions and 0 deletions
@@ -0,0 +1,10 @@
// "Replace with 'clone()'" "true"
import java.util.Arrays;
class Test {
String[] arr;
String[] get() {
return arr.clone();
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Arrays.copyOfRange'" "true"
import java.util.Arrays;
class Test {
String[] arr;
String[] get() {
return Arrays.copyOfRange(arr, 1, 3);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Arrays.copyOfRange'" "true"
import java.util.Arrays;
class Test {
String[] arr;
CharSequence[] get(int from, int to) {
return Arrays.copyOfRange(arr, from, to, CharSequence[].class);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Arrays.copyOf'" "true"
import java.util.Arrays;
class Test {
String[] arr;
String[] get(int newLength) {
return Arrays.copyOf(arr, newLength);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Arrays.copyOf'" "true"
import java.util.Arrays;
class Test {
String[] arr;
Object[] get(int newLength) {
return Arrays.copyOf(arr, newLength, Object[].class);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'clone()'" "true"
import java.util.Arrays;
class Test {
String[] arr;
String[] get() {
return Arrays.asList(arr).toAr<caret>ray(new String[0]);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Arrays.copyOfRange'" "true"
import java.util.Arrays;
class Test {
String[] arr;
String[] get() {
return Arrays.asList(arr).subList(1, 3).toAr<caret>ray(new String[2]);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Arrays.copyOfRange'" "true"
import java.util.Arrays;
class Test {
String[] arr;
CharSequence[] get(int from, int to) {
return Arrays.asList(arr).subList(from, to).toAr<caret>ray(new CharSequence[to-from]);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Arrays.copyOfRange'" "false"
import java.util.Arrays;
class Test {
String[] arr;
String[] get() {
return Arrays.asList(arr).subList(1, 3).toAr<caret>ray(new String[3]);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Arrays.copyOf'" "true"
import java.util.Arrays;
class Test {
String[] arr;
String[] get(int newLength) {
return Arrays.asList(arr).subList(0, newLength).toAr<caret>ray(new String[newLength]);
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Arrays.copyOf'" "true"
import java.util.Arrays;
class Test {
String[] arr;
Object[] get(int newLength) {
return Arrays.asList(arr).subList(0, newLength).toAr<caret>ray();
}
}
@@ -0,0 +1,11 @@
// "Replace with 'clone()'" "false"
import java.util.Arrays;
class Test {
String[] arr;
CharSequence[] get() {
// Array type mismatch
return Arrays.asList(arr).toAr<caret>ray(new CharSequence[0]);
}
}