Java: Intention that wraps list/set/map with Collections.unmodifiable - check the required type (IDEA-93154)

This commit is contained in:
Pavel Dolgov
2019-02-21 18:03:24 +03:00
parent 61dba455d0
commit 0267b104b3
9 changed files with 146 additions and 25 deletions
@@ -0,0 +1,12 @@
// "Wrap with unmodifiable map" "true"
import java.util.Collections;
import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.TreeMap;
class C {
SortedMap<String, Integer> test() {
NavigableMap<String, Integer> result = new TreeMap<>();
return Collections.unmodifiableSortedMap(result);
}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable set" "false"
import java.util.Set;
import java.util.HashSet;
class C {
void test() {
HashSet<String> result = new HashSet<>();
HashSet<String> other;
other = <caret>result;
}
}
@@ -0,0 +1,12 @@
// "Wrap with unmodifiable map" "false"
import java.util.Map;
import java.util.HashMap;
class C {
void test() {
var result = new HashMap<>();
foo(<caret>result);
}
void foo(HashMap<String, Integer> map) {}
}
@@ -0,0 +1,10 @@
// "Wrap with unmodifiable set" "false"
import java.util.Set;
import java.util.TreeSet;
class C {
void test() {
TreeSet<String> result = new TreeSet<>();
TreeSet<String> other = <caret>result;
}
}
@@ -0,0 +1,12 @@
// "Wrap with unmodifiable map" "false"
import java.util.Map;
import java.util.HashMap;
class C {
void test() {
var result = new HashMap<>();
foo(<caret>result);
}
void foo(Map<String, Integer> map) {}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable map" "true"
import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.TreeMap;
class C {
SortedMap<String, Integer> test() {
NavigableMap<String, Integer> result = new TreeMap<>();
return <caret>result;
}
}
@@ -0,0 +1,10 @@
// "Wrap with unmodifiable list" "false"
import java.util.List;
import java.util.ArrayList;
class C {
ArrayList<String> test() {
List<String> result = new ArrayList<>();
return <caret>result;
}
}
@@ -0,0 +1,11 @@
// "Wrap with unmodifiable map" "false"
import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.TreeMap;
class C {
NavigableMap<String, Integer> test() {
NavigableMap<String, Integer> result = new TreeMap<>();
return <caret>result;
}
}