Java: Implemented the quick-fix Collection.toArray() that is offered in the context where an array is required but a collection is provided (IDEA-163341)

This commit is contained in:
Pavel Dolgov
2017-01-11 15:56:51 +03:00
parent 6610647716
commit 26a7739891
26 changed files with 359 additions and 1 deletions

View File

@@ -0,0 +1,11 @@
// "Apply conversion '.toArray(new int[0][])'" "true"
import java.util.*;
class Array {
static int[][] foo() {
Set<int[]> set = new HashSet<>();
set.add(new int[]{1, 2});
int[][] arr = set.toArray(new int[0][]);
return arr;
}
}

View File

@@ -0,0 +1,11 @@
// "Apply conversion '.toArray(new java.lang.String[0])'" "true"
import java.util.*;
class Assign {
String[] foo() {
Set<String> set = Collections.singleton("s");
String[] arr;
arr = set.toArray(new String[0]);
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.lang.Integer[0])'" "true"
import java.util.*;
class Cast {
Integer[] foo() {
Iterable<Integer> c = Arrays.asList(1, 2);
Integer[] arr = ((Collection<Integer>)c).toArray(new Integer[0]);
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.lang.String[0])'" "true"
import java.util.*;
class Expression {
String[] foo() {
String[] arr;
arr = Collections.<String>singleton("s").toArray(new String[0]);
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.util.List[0])'" "true"
import java.util.*;
class Generic {
List<String>[] foo() {
Set<List<String>> set = new HashSet<>();
List<String>[] arr = set.toArray(new List[0]);
return arr;
}
}

View File

@@ -0,0 +1,11 @@
// "Apply conversion '.toArray(new java.util.List[0][])'" "true"
import java.util.*;
class GenericArray {
static List<String>[][] foo() {
Set<List<String>[]> set = new HashSet<>();
set.add(new List[]{Arrays.asList("a", "b"), Arrays.asList("c", "d")});
List<String>[][] arr = set.toArray(new List[0][]);
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.lang.Integer[0])'" "true"
import java.util.*;
class Initialize {
Integer[] foo() {
Collection<Integer> c = Arrays.asList(1, 2);
Integer[] arr = c.toArray(new Integer[0]);
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray()'" "true"
import java.util.*;
class Raw {
Object[] foo() {
Set set = new TreeSet();
Object[] arr = set.toArray();
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.lang.String[0])'" "true"
import java.util.*;
class Return {
String[] foo() {
List<String> list = new ArrayList<>();
list.add("s");
return list.toArray(new String[0]);
}
}

View File

@@ -0,0 +1,11 @@
// "Apply conversion '.toArray(new int[0][])'" "true"
import java.util.*;
class Array {
static int[][] foo() {
Set<int[]> set = new HashSet<>();
set.add(new int[]{1, 2});
int[][] arr <caret>= set;
return arr;
}
}

View File

@@ -0,0 +1,11 @@
// "Apply conversion '.toArray(new java.lang.String[0])'" "true"
import java.util.*;
class Assign {
String[] foo() {
Set<String> set = Collections.singleton("s");
String[] arr;
<caret>arr = set;
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.lang.Integer[0])'" "true"
import java.util.*;
class Cast {
Integer[] foo() {
Iterable<Integer> c = Arrays.asList(1, 2);
Integer[] arr = (Collection<Integer>)<caret>c;
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.lang.String[0])'" "true"
import java.util.*;
class Expression {
String[] foo() {
String[] arr;
arr<caret> = Collections.<String>singleton("s");
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.util.List[0])'" "true"
import java.util.*;
class Generic {
List<String>[] foo() {
Set<List<String>> set = new HashSet<>();
List<String>[] <caret>arr = set;
return arr;
}
}

View File

@@ -0,0 +1,11 @@
// "Apply conversion '.toArray(new java.util.List[0][])'" "true"
import java.util.*;
class GenericArray {
static List<String>[][] foo() {
Set<List<String>[]> set = new HashSet<>();
set.add(new List[]{Arrays.asList("a", "b"), Arrays.asList("c", "d")});
List<String>[][] arr = <caret>set;
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.lang.Integer[0])'" "true"
import java.util.*;
class Initialize {
Integer[] foo() {
Collection<Integer> c = Arrays.asList(1, 2);
Integer[] arr<caret> = c;
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new int[0])'" "false"
import java.util.*;
class Primitive {
int[] foo() {
Collection<Integer> c = Arrays.asList(1, 2);
int[] arr<caret> = c;
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray()'" "true"
import java.util.*;
class Raw {
Object[] foo() {
Set set = new TreeSet();
Object[] <caret>arr = set;
return arr;
}
}

View File

@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new java.lang.String[0])'" "true"
import java.util.*;
class Return {
String[] foo() {
List<String> list = new ArrayList<>();
list.add("s");
return list<caret>;
}
}