IDEA-195069 Quick Fix: "Transform to mutable collection" in response to "Immutable object is modified" inspection

This commit is contained in:
Tagir Valeev
2018-07-09 16:23:35 +07:00
parent 36e0c17ad4
commit 99387de7f5
10 changed files with 223 additions and 2 deletions
@@ -0,0 +1,9 @@
// "Wrap 'map' with 'HashMap'" "true"
import java.util.*;
class Test {
void testComparator() {
Map<String, Integer> map = new HashMap<>(Math.random() > 0.5 ? Collections.emptyMap() : Collections.singletonMap("foo", 1));
map.put(123, 456);
}
}
@@ -0,0 +1,9 @@
// "Wrap 'integers' with 'HashSet'" "true"
import java.util.*;
class Test {
void testComparator() {
var integers = new HashSet<>(Set.of(4, 3, 2, 1));
integers.add(123);
}
}
@@ -0,0 +1,9 @@
// "Wrap 'integers' with 'ArrayList'" "true"
import java.util.*;
class Test {
void testComparator() {
List<Integer> integers = new ArrayList<>(List.of(4, 3, 2, 1));
integers.sort(Comparator.naturalOrder());
}
}
@@ -0,0 +1,9 @@
// "Wrap 'map' with 'HashMap'" "true"
import java.util.*;
class Test {
void testComparator() {
Map<String, Integer> map = Math.random() > 0.5 ? Collections.emptyMap() : Collections.singletonMap("foo", 1);
map.p<caret>ut(123, 456);
}
}
@@ -0,0 +1,9 @@
// "Wrap 'integers' with 'HashSet'" "true"
import java.util.*;
class Test {
void testComparator() {
var integers = Set.of(4, 3, 2, 1);
integers.a<caret>dd(123);
}
}
@@ -0,0 +1,9 @@
// "Wrap 'integers' with 'ArrayList'" "true"
import java.util.*;
class Test {
void testComparator() {
List<Integer> integers = List.of(4, 3, 2, 1);
integers.so<caret>rt(Comparator.naturalOrder());
}
}