IDEA-161925 Stream API migration: support toArray conversion, fixed mapping to initialized array, fixed final variable status, clean up in RefactoringUtil

This commit is contained in:
Tagir Valeev
2016-09-30 16:07:06 +07:00
parent e3d794ad99
commit 738994f1c0
26 changed files with 459 additions and 29 deletions
@@ -0,0 +1,10 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).toArray();
}
}
@@ -0,0 +1,13 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
Object[] arr;
arr = data.stream().filter(str -> !str.isEmpty()).toArray();
System.out.println(Arrays.toString(arr));
return arr;
}
}
@@ -0,0 +1,12 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
Object[] arr = data.stream().filter(str -> !str.isEmpty()).toArray();
System.out.println(Arrays.toString(arr));
return arr;
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public List<?>[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).map(Collections::singletonList).distinct().toArray(List<?>[]::new);
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).distinct().toArray(String[]::new);
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public CharSequence[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).distinct().toArray(CharSequence[]::new);
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[] testToArray(List<String> data) {
Set<String> result = new LinkedHashSet<>();
if(!data.isEmpty()) {
return data.stream().filter(str -> !str.isEmpty()).map(String::trim).distinct().toArray(String[]::new);
}
result.add("None");
return result.toArray(new String[1]);
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public Object[] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).distinct().sorted().toArray(String[]::new);
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[][] testToArray(List<String> data) {
return data.stream().filter(str -> !str.isEmpty()).map(str -> new String[]{str}).toArray(String[][]::new);
}
}
@@ -0,0 +1,20 @@
// "Replace with collect" "false"
import java.util.*;
public class Collect {
class Person {
String getName() {
return "";
}
}
void collectNames(List<Person> persons){
final Set<String> names = new HashSet<>(), other = new HashSet<>();
if(persons != null) {
for (Person person : pers<caret>ons) {
names.add(person.getName());
}
}
System.out.println(names);
}
}
@@ -0,0 +1,15 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray();
}
}
@@ -0,0 +1,18 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
Object[] arr;
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
arr = result.toArray();
System.out.println(Arrays.toString(arr));
return arr;
}
}
@@ -0,0 +1,17 @@
// "Replace with toArray" "true"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
Object[] arr = result.toArray();
System.out.println(Arrays.toString(arr));
return arr;
}
}
@@ -0,0 +1,17 @@
// "Replace with toArray" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
Object[] arr = result.toArray();
System.out.println(result);
return arr;
}
}
@@ -0,0 +1,16 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public List<?>[] testToArray(List<String> data) {
Set<List<String>> result = new LinkedHashSet<>();
for (String str : dat<caret>a) {
if (!str.isEmpty()) {
List<String> list = Collections.singletonList(str);
result.add(list);
}
}
return result.toArray(new List<?>[0]);
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[] testToArray(List<String> data) {
Set<String> result = new HashSet<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray(new String[0]);
}
}
@@ -0,0 +1,15 @@
// "Replace with toArray" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
Set<String> result = new IdentityHashSet<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray();
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public CharSequence[] testToArray(List<String> data) {
Set<String> result = new LinkedHashSet<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray(new CharSequence[result.size()]);
}
}
@@ -0,0 +1,19 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[] testToArray(List<String> data) {
Set<String> result = new LinkedHashSet<>();
if(!data.isEmpty()) {
for (String str : d<caret>ata) {
if (!str.isEmpty()) {
result.add(str.trim());
}
}
return result.toArray(new String[result.size()]);
}
result.add("None");
return result.toArray(new String[1]);
}
}
@@ -0,0 +1,14 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public Object[] testToArray(List<String> data) {
Set<String> result = new TreeSet<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray(new String[result.size()]);
}
}
@@ -0,0 +1,16 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
public String[][] testToArray(List<String> data) {
List<String[]> result = new ArrayList<>();
for (String str : dat<caret>a) {
if (!str.isEmpty()) {
String[] arr = {str};
result.add(arr);
}
}
return result.toArray(new String[result.size()][]);
}
}
@@ -0,0 +1,15 @@
// "Replace with toArray" "false"
import java.util.ArrayList;
import java.util.List;
public class Main {
public Object[] testToArray(List<String> data) {
List<String> result = new ArrayList<>();
for (String str : d<caret>ata) {
if (!str.isEmpty())
result.add(str);
}
return result.toArray(new String[10]);
}
}