IDEA-167942 Migrate to simplified collection factories (JEP 269): initial implementation (supported scenarios 2, 3, 4 for sets and similar for lists)

This commit is contained in:
Tagir Valeev
2017-02-27 10:35:34 +07:00
parent 671c9cee20
commit 2dda8819cc
22 changed files with 465 additions and 26 deletions
@@ -0,0 +1,9 @@
// "Replace with 'List.of' call" "true"
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Test {
public static final List<Number> EVEN = List.of(2, 4, 6, 8, 10);
}
@@ -0,0 +1,8 @@
// "Replace with 'List.of' call" "true"
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Test {
public static final List<Number> EVEN = List.of(0, 2, 4, 6, 8);
}
@@ -0,0 +1,8 @@
// "Replace with 'List.of' call" "true"
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Test {
public static final List<Number> EVEN = List.of(2, 4, 6, 8, 10);
}
@@ -0,0 +1,9 @@
// "Replace with 'Set.of' call" "true"
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class Test {
public static final Set<String> MY_SET = Set.of("a", "b", "c");
}
@@ -0,0 +1,8 @@
// "Replace with 'Set.of' call" "true"
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class Test {
public static final Set<String> MY_SET = Set.of("a", "b", "c".toUpperCase());
}
@@ -0,0 +1,9 @@
// "Replace with 'List.of' call" "true"
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Test {
public static final List<Class<?>> MY_LIST = List.of(String.class, int.class, Object.class);
}
@@ -0,0 +1,9 @@
// "Replace with 'Set.of' call" "true"
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Test {
public static final Set<Class<?>> MY_SET = Set.of(String.class, int.class, Object.class);
}
@@ -0,0 +1,9 @@
// "Replace with 'List.of' call" "true"
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Test {
public static final List<Number> EVEN = Collections.unmo<caret>difiableList(new ArrayList<>(Arrays.asList(2,4,6,8,10)));
}
@@ -0,0 +1,14 @@
// "Replace with 'List.of' call" "true"
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Test {
public static final List<Number> EVEN = Collections.unmodif<caret>iableList(new ArrayList<>() {{
this.add(0);
this.add(2);
this.add(4);
this.add(6);
this.add(8);
}});
}
@@ -0,0 +1,8 @@
// "Replace with 'List.of' call" "true"
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Test {
public static final List<Number> EVEN = Collections.unmodi<caret>fiableList(Arrays.asList(2,4,6,8,10));
}
@@ -0,0 +1,9 @@
// "Replace with 'Set.of' call" "true"
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class Test {
public static final Set<String> MY_SET = Collections.unm<caret>odifiableSet(new HashSet<>(Arrays.asList("a", "b", "c")));
}
@@ -0,0 +1,12 @@
// "Replace with 'Set.of' call" "true"
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class Test {
public static final Set<String> MY_SET = Collections.unmodi<caret>fiableSet(new HashSet<String>() {{
add("a");
add("b");
add("c".toUpperCase());
}});
}
@@ -0,0 +1,14 @@
// "Replace with 'Set.of' call" "false"
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class Test {
static Set<String> WRONG_SET = new HashSet<>();
public static final Set<String> MY_SET = Collections.unmod<caret>ifiableSet(new HashSet<String>() {{
add("a");
add("b");
WRONG_SET.add("c".toUpperCase());
}});
}
@@ -0,0 +1,10 @@
// "Replace with 'List.of' call" "true"
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Test {
public static final List<Class<?>> MY_LIST = Collections
.unmo<caret>difiableList(Stream.of(String.class, int.class, Object.class).collect(Collectors.toList()));
}
@@ -0,0 +1,10 @@
// "Replace with 'Set.of' call" "true"
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Test {
public static final Set<Class<?>> MY_SET = Collections
.un<caret>modifiableSet(Stream.of(String.class, int.class, Object.class).collect(Collectors.toSet()));
}