IDEA-167942 Migrate to simplified collection factories (JEP 269): support explicit addition chain

This commit is contained in:
Tagir Valeev
2017-02-27 10:35:34 +07:00
parent 2dda8819cc
commit f8f7f60fd6
8 changed files with 137 additions and 8 deletions
@@ -0,0 +1,10 @@
// "Replace with 'List.of' call" "true"
import java.util.*;
public class Test {
public void testList() {
List<Integer> list;
list = List.of(1, 2);
System.out.println(list);
}
}
@@ -0,0 +1,11 @@
// "Replace with 'Set.of' call" "true"
import java.util.*;
public class Test {
private static final Set<String> MY_SET;
static {
Set<String> set;
MY_SET = Set.of("foo", "bar", "xyz");
}
}
@@ -0,0 +1,10 @@
// "Replace with 'Set.of' call" "true"
import java.util.*;
public class Test {
public void test2() {
Set<String> set;
set = Set.of("foo", "bar", "xyz");
System.out.println(set);
}
}
@@ -0,0 +1,12 @@
// "Replace with 'List.of' call" "true"
import java.util.*;
public class Test {
public void testList() {
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list = Collections.unmodifi<caret>ableList(list);
System.out.println(list);
}
}
@@ -0,0 +1,12 @@
// "Replace with 'List.of' call" "false"
import java.util.*;
public class Test {
public void testList() {
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
List<Integer> list2 = Collections.unmodifi<caret>ableList(list);
System.out.println(list); // mutable list is reused here
}
}
@@ -0,0 +1,14 @@
// "Replace with 'Set.of' call" "true"
import java.util.*;
public class Test {
private static final Set<String> MY_SET;
static {
Set<String> set = new HashSet<>();
set.add("foo");
set.add("bar");
set.add("xyz");
MY_SET = Collections.unmodif<caret>iableSet(set);
}
}
@@ -0,0 +1,13 @@
// "Replace with 'Set.of' call" "true"
import java.util.*;
public class Test {
public void test2() {
Set<String> set = new HashSet<>();
set.add("foo");
set.add("bar");
set.add("xyz");
set = Collections.unmodif<caret>iableSet(set);
System.out.println(set);
}
}