Java: Intention that wraps list/set/map with Collections.unmodifiableList/Set/Map (IDEA-93154)

This commit is contained in:
Pavel Dolgov
2019-02-20 18:00:15 +03:00
parent f588d814fa
commit 63092d9c2e
22 changed files with 322 additions and 0 deletions
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable list" "true"
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
class C {
List<String> test() {
List<String> result = new ArrayList<>();
return Collections.unmodifiableList(result);
}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable map" "true"
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
class C {
Map<String, Integer> test() {
var result = new HashMap<>();
return Collections.unmodifiableMap(result);
}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable set" "true"
import java.util.Collections;
import java.util.Set;
import java.util.HashSet;
class C {
Set<String> test() {
Set<String> result = new HashSet<>();
return Collections.unmodifiableSet(result);
}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable map" "true"
import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;
class C {
SortedMap<String, Integer> test() {
SortedMap<String, Integer> result = new TreeMap<>();
return Collections.unmodifiableSortedMap(result);
}
}
@@ -0,0 +1,9 @@
// "Wrap with unmodifiable set" "true"
import java.util.*;
class C {
Set<String> test() {
SortedSet<String> result = new TreeSet<>();
return Collections.unmodifiableSortedSet(result);
}
}
@@ -0,0 +1,10 @@
// "Wrap with unmodifiable list" "true"
import java.util.List;
import java.util.ArrayList;
class C {
List<String> test() {
List<String> result = new ArrayList<>();
return <caret>result;
}
}
@@ -0,0 +1,10 @@
// "Wrap with unmodifiable map" "true"
import java.util.Map;
import java.util.HashMap;
class C {
Map<String, Integer> test() {
var result = new HashMap<>();
return <caret>result;
}
}
@@ -0,0 +1,10 @@
// "Wrap with unmodifiable set" "true"
import java.util.Set;
import java.util.HashSet;
class C {
Set<String> test() {
Set<String> result = new HashSet<>();
return <caret>result;
}
}
@@ -0,0 +1,10 @@
// "Wrap with unmodifiable map" "true"
import java.util.SortedMap;
import java.util.TreeMap;
class C {
SortedMap<String, Integer> test() {
SortedMap<String, Integer> result = new TreeMap<>();
return <caret>result;
}
}
@@ -0,0 +1,9 @@
// "Wrap with unmodifiable set" "true"
import java.util.*;
class C {
Set<String> test() {
SortedSet<String> result = new TreeSet<>();
return <caret>result;
}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable list" "false"
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
class C {
List<String> test() {
List<String> result = new ArrayList<>();
return Collections.<caret>unmodifiableList(result);
}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable list" "false"
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
class C {
List<String> test() {
List<String> result = new ArrayList<>();
return Collections.unmodifiableList(<caret>result);
}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable map" "false"
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
class C {
Map<String, Integer> test() {
Map<String, Integer> result = new HashMap<>();
return Collections.unmodifiab<caret>leMap(result);
}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable map" "false"
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
class C {
Map<String, Integer> test() {
Map<String, Integer> result = new HashMap<>();
return Collections.unmodifiableMap((res<caret>ult));
}
}
@@ -0,0 +1,9 @@
// "Wrap with unmodifiable set" "false"
import java.util.*;
class C {
Set<String> test() {
SortedSet<String> result = new TreeSet<>();
return Collections.unmodifiableSor<caret>tedSet(result);
}
}