diff --git a/java/java-impl/src/com/intellij/codeInspection/RedundantUnmodifiableInspection.java b/java/java-impl/src/com/intellij/codeInspection/RedundantUnmodifiableInspection.java index 535656359c4f..06fcd4edee5d 100644 --- a/java/java-impl/src/com/intellij/codeInspection/RedundantUnmodifiableInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/RedundantUnmodifiableInspection.java @@ -8,41 +8,20 @@ import com.intellij.java.JavaBundle; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; -import com.intellij.util.ArrayUtil; import com.intellij.util.ObjectUtils; import com.siyeh.ig.callMatcher.CallMatcher; import com.siyeh.ig.psiutils.CommentTracker; +import com.siyeh.ig.psiutils.ExpressionUtils; import org.jetbrains.annotations.NotNull; import static com.intellij.psi.CommonClassNames.JAVA_UTIL_COLLECTIONS; -import static com.siyeh.ig.callMatcher.CallMatcher.anyOf; import static com.siyeh.ig.callMatcher.CallMatcher.staticCall; public class RedundantUnmodifiableInspection extends AbstractBaseJavaLocalInspectionTool { - private static final CallMatcher COLLECTIONS_UNMODIFIABLE_COLLECTION = - staticCall(JAVA_UTIL_COLLECTIONS, "unmodifiableCollection").parameterCount(1); - private static final CallMatcher COLLECTIONS_UNMODIFIABLE_LIST = - staticCall(JAVA_UTIL_COLLECTIONS, "unmodifiableList").parameterCount(1); - private static final CallMatcher COLLECTIONS_UNMODIFIABLE_SET = - staticCall(JAVA_UTIL_COLLECTIONS, "unmodifiableSet").parameterCount(1); - private static final CallMatcher COLLECTIONS_UNMODIFIABLE_MAP = - staticCall(JAVA_UTIL_COLLECTIONS, "unmodifiableMap").parameterCount(1); - - private static final CallMatcher COLLECTIONS_UNMODIFIABLE_SORTED_SET = - staticCall(JAVA_UTIL_COLLECTIONS, "unmodifiableSortedSet").parameterCount(1); - private static final CallMatcher COLLECTIONS_UNMODIFIABLE_SORTED_MAP = - staticCall(JAVA_UTIL_COLLECTIONS, "unmodifiableSortedMap").parameterCount(1); - - private static final CallMatcher COLLECTIONS_UNMODIFIABLE_NAVIGABLE_MAP = - staticCall(JAVA_UTIL_COLLECTIONS, "unmodifiableNavigableMap").parameterCount(1); - private static final CallMatcher COLLECTIONS_UNMODIFIABLE_NAVIGABLE_SET = - staticCall(JAVA_UTIL_COLLECTIONS, "unmodifiableNavigableSet").parameterCount(1); - private static final CallMatcher COLLECTIONS_UNMODIFIABLE = - anyOf(COLLECTIONS_UNMODIFIABLE_COLLECTION, COLLECTIONS_UNMODIFIABLE_SET, - COLLECTIONS_UNMODIFIABLE_MAP, COLLECTIONS_UNMODIFIABLE_LIST, - COLLECTIONS_UNMODIFIABLE_SORTED_SET, COLLECTIONS_UNMODIFIABLE_SORTED_MAP, - COLLECTIONS_UNMODIFIABLE_NAVIGABLE_MAP, COLLECTIONS_UNMODIFIABLE_NAVIGABLE_SET); + staticCall(JAVA_UTIL_COLLECTIONS,"unmodifiableCollection", "unmodifiableList", + "unmodifiableSet", "unmodifiableMap", "unmodifiableSortedSet", "unmodifiableSortedMap", + "unmodifiableNavigableMap", "unmodifiableNavigableSet").parameterCount(1); @NotNull @Override @@ -51,10 +30,9 @@ public class RedundantUnmodifiableInspection extends AbstractBaseJavaLocalInspec @Override public void visitMethodCallExpression(PsiMethodCallExpression call) { - super.visitMethodCallExpression(call); - + if (ExpressionUtils.isVoidContext(call)) return; if (COLLECTIONS_UNMODIFIABLE.test(call)) { - PsiExpression arg = ArrayUtil.getFirstElement(call.getArgumentList().getExpressions()); + PsiExpression arg = call.getArgumentList().getExpressions()[0]; if (arg == null) return; DfType dfType = CommonDataflow.getDfType(arg); @@ -77,7 +55,7 @@ public class RedundantUnmodifiableInspection extends AbstractBaseJavaLocalInspec @NotNull @Override public String getFamilyName() { - return JavaBundle.message("inspection.redundant.unmodifiable.call.replace.with.arg.quickfix"); + return JavaBundle.message("inspection.redundant.unmodifiable.call.unwrap.argument.quickfix"); } @Override diff --git a/java/java-impl/src/inspectionDescriptions/RedundantUnmodifiable.html b/java/java-impl/src/inspectionDescriptions/RedundantUnmodifiable.html index cceaccdfc526..4ba18a182c21 100644 --- a/java/java-impl/src/inspectionDescriptions/RedundantUnmodifiable.html +++ b/java/java-impl/src/inspectionDescriptions/RedundantUnmodifiable.html @@ -1,13 +1,13 @@ -Reports redundant calls to unmodifiable collection factories within the Collections class. -If the argument that is passed to an unmodifiable collection factory is already immutable, such wrapping becomes pointless. +Reports redundant calls to unmodifiable collection wrappers within the Collections class. +If the argument that is passed to an unmodifiable collection wrapper is already immutable, such wrapping becomes pointless.

Example:

 Collections.unmodifiableList(Collections.singletonList("abc"));
 
 
-In order to detect the methods that return unmodifiable collections, the inspection uses the @Unmodifiable annotation. Use this annotation if you want to extend the inspection to your own unmodifiable collection factories. +In order to detect the methods that return unmodifiable collections, the inspection uses the org.jetbrains.annotations.Unmodifiable and org.jetbrains.annotations.UnmodifiableView annotations. Use them to extend the inspection to your own unmodifiable collection wrappers.

New in 2020.3

diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterIntermediateMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterIntermediateMethod.java index 7783129d01eb..ef38bce789cd 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterIntermediateMethod.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterIntermediateMethod.java @@ -1,24 +1,21 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; class Main { public static void main(String[] args) { - getEmptyList(); + Collection unmodifiableCollection = getEmptyList(); - getEmptyList(); - getEmptySet(); - getEmptyMap(); + List unmodifiableList = getEmptyList(); + Set unmodifiableSet = getEmptySet(); + Map unmodifiableMap = getEmptyMap(); - getEmptySet(); - getEmptyMap(); + SortedSet unmodifiableSortedSet = getEmptySet(); + SortedMap unmodifiableSortedMap = getEmptyMap(); - getEmptySet(); - getEmptyMap(); + NavigableSet unmodifiableNavigableSet = getEmptySet(); + NavigableMap unmodifiableNavigableMap = getEmptyMap(); } static List getEmptyList() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterIntermediateVar.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterIntermediateVar.java index 37a2f02ab44d..c6c2c12ee588 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterIntermediateVar.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterIntermediateVar.java @@ -1,4 +1,4 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" import java.util.*; @@ -14,16 +14,16 @@ class Main { Map map = new HashMap(); map = Collections.emptyMap(); - list; + Collection unmodifiableCollection = list; - list; - set; - map; + List unmodifiableList = list; + Set unmodifiableSet = set; + Map unmodifiableMap = map; - set; - map; + SortedSet unmodifiableSortedSet = set; + SortedMap unmodifiableSortedMap = map; - set; - map; + NavigableSet unmodifiableNavigableSet = set; + NavigableMap unmodifiableNavigableMap = map; } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterUnmodifiableArg.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterUnmodifiableArg.java index faf3371326e0..25cef4f3b614 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterUnmodifiableArg.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterUnmodifiableArg.java @@ -1,20 +1,20 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; +import java.util.*; class Main { public static void main(String[] args) { - Collections.EMPTY_LIST; + Collections unmodifiableCollection = Collections.EMPTY_LIST; - Collections.EMPTY_LIST; - Collections.EMPTY_SET; - Collections.EMPTY_MAP; + List unmodifiableList = Collections.EMPTY_LIST; + Set unmodifiableSet = Collections.EMPTY_SET; + Map unmodifiableMap = Collections.EMPTY_MAP; - Collections.EMPTY_SET; - Collections.EMPTY_MAP; + SortedSet unmodifiableSortedSet = Collections.EMPTY_SET; + SortedMap unmodifiableSortedMap = Collections.EMPTY_MAP; - Collections.EMPTY_SET; - Collections.EMPTY_MAP; + NavigableSet unmodifiableNavigableSet = Collections.EMPTY_SET; + NavigableMap unmodifiableNavigableMap = Collections.EMPTY_MAP; } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterUnmodifiableMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterUnmodifiableMethod.java index ab3a85409e4c..db072ee86226 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterUnmodifiableMethod.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterUnmodifiableMethod.java @@ -1,20 +1,20 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; +import java.util.*; class Main { public static void main(String[] args) { - Collections.emptyList(); + Collections unmodifiableCollection = Collections.emptyList(); - Collections.emptyList(); - Collections.emptySet(); - Collections.emptyMap(); + List unmodifiableList = Collections.emptyList(); + Set unmodifiableSet = Collections.emptySet(); + Map unmodifiableMap = Collections.emptyMap(); - Collections.emptySet(); - Collections.emptyMap(); + SortedSet unmodifiableSortedSet = Collections.emptySet(); + SortedMap unmodifiableSortedMap = Collections.emptyMap(); - Collections.emptySet(); - Collections.emptyMap(); + NavigableSet unmodifiableNavigableSet = Collections.emptySet(); + NavigableMap unmodifiableNavigableMap = Collections.emptyMap(); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterWithComments.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterWithComments.java index 2b6b99bf5c50..2ca2cd7a536f 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterWithComments.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterWithComments.java @@ -1,6 +1,6 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; +import java.util.*; class Main { @@ -8,37 +8,37 @@ class Main { /*empty*/ /*empty too*/ /*blah blah blah*/ - Collections.emptyList(); + Collection unmodifiableCollection = Collections.emptyList(); /*empty*/ /*empty too*/ /*blah blah blah*/ - Collections.emptyList(); + List unmodifiableList = Collections.emptyList(); /*empty*/ /*empty too*/ /*blah blah blah*/ - Collections.emptySet(); + Set unmodifiableSet = Collections.emptySet(); /*empty*/ /*empty too*/ /*blah blah blah*/ - Collections.emptyMap(); + Map unmodifiableMap = Collections.emptyMap(); /*empty*/ /*empty too*/ /*blah blah blah*/ - Collections.emptySet(); + SortedSet unmodifiableSortedSet = Collections.emptySet(); /*empty*/ /*empty too*/ /*blah blah blah*/ - Collections.emptyMap(); + SortedMap unmodifiableSortedMap = Collections.emptyMap(); /*empty*/ /*empty too*/ /*blah blah blah*/ - Collections.emptySet(); + NavigableSet unmodifiableNavigableSet = Collections.emptySet(); /*empty*/ /*empty too*/ /*blah blah blah*/ - Collections.emptyMap(); + NavigableMap unmodifiableNavigableMap = Collections.emptyMap(); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterWithParentheses.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterWithParentheses.java index 4e6f3fdf0480..e7c64a1c1f93 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterWithParentheses.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/afterWithParentheses.java @@ -1,20 +1,20 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; +import java.util.*; class Main { public static void main(String[] args) { - ((Collections.emptyList())); + Collection unmodifiableCollection = ((Collections.emptyList())); - ((Collections.emptyList())); - ((Collections.emptySet())); - ((Collections.emptyMap())); + List unmodifiableList = ((Collections.emptyList())); + Set unmodifiableSet = ((Collections.emptySet())); + Map unmodifiableMap = ((Collections.emptyMap())); - ((Collections.emptySet())); - ((Collections.emptyMap())); + SortedSet unmodifiableSortedSet = ((Collections.emptySet())); + SortedMap unmodifiableSortedMap = ((Collections.emptyMap())); - ((Collections.emptySet())); - ((Collections.emptyMap())); + NavigableSet unmodifiableNavigableSet = ((Collections.emptySet())); + NavigableMap unmodifiableNavigableMap = ((Collections.emptyMap())); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeIntermediateMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeIntermediateMethod.java index 9f634802385c..223be7745a7c 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeIntermediateMethod.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeIntermediateMethod.java @@ -1,24 +1,21 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; class Main { public static void main(String[] args) { - Collections.unmodifiableCollection(getEmptyList()); + Collection unmodifiableCollection = Collections.unmodifiableCollection(getEmptyList()); - Collections.unmodifiableList(getEmptyList()); - Collections.unmodifiableSet(getEmptySet()); - Collections.unmodifiableMap(getEmptyMap()); + List unmodifiableList = Collections.unmodifiableList(getEmptyList()); + Set unmodifiableSet = Collections.unmodifiableSet(getEmptySet()); + Map unmodifiableMap = Collections.unmodifiableMap(getEmptyMap()); - Collections.unmodifiableSortedSet(getEmptySet()); - Collections.unmodifiableSortedMap(getEmptyMap()); + SortedSet unmodifiableSortedSet = Collections.unmodifiableSortedSet(getEmptySet()); + SortedMap unmodifiableSortedMap = Collections.unmodifiableSortedMap(getEmptyMap()); - Collections.unmodifiableNavigableSet(getEmptySet()); - Collections.unmodifiableNavigableMap(getEmptyMap()); + NavigableSet unmodifiableNavigableSet = Collections.unmodifiableNavigableSet(getEmptySet()); + NavigableMap unmodifiableNavigableMap = Collections.unmodifiableNavigableMap(getEmptyMap()); } static List getEmptyList() { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeIntermediateVar.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeIntermediateVar.java index 85c3dff60bfe..d8319db3d40c 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeIntermediateVar.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeIntermediateVar.java @@ -1,4 +1,4 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" import java.util.*; @@ -14,16 +14,16 @@ class Main { Map map = new HashMap(); map = Collections.emptyMap(); - Collections.unmodifiableCollection(list); + Collection unmodifiableCollection = Collections.unmodifiableCollection(list); - Collections.unmodifiableList(list); - Collections.unmodifiableSet(set); - Collections.unmodifiableMap(map); + List unmodifiableList = Collections.unmodifiableList(list); + Set unmodifiableSet = Collections.unmodifiableSet(set); + Map unmodifiableMap = Collections.unmodifiableMap(map); - Collections.unmodifiableSortedSet(set); - Collections.unmodifiableSortedMap(map); + SortedSet unmodifiableSortedSet = Collections.unmodifiableSortedSet(set); + SortedMap unmodifiableSortedMap = Collections.unmodifiableSortedMap(map); - Collections.unmodifiableNavigableSet(set); - Collections.unmodifiableNavigableMap(map); + NavigableSet unmodifiableNavigableSet = Collections.unmodifiableNavigableSet(set); + NavigableMap unmodifiableNavigableMap = Collections.unmodifiableNavigableMap(map); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeUnmodifiableArg.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeUnmodifiableArg.java index d95aa91d6857..a6e1503796ad 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeUnmodifiableArg.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeUnmodifiableArg.java @@ -1,20 +1,20 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; +import java.util.*; class Main { public static void main(String[] args) { - Collections.unmodifiableCollection(Collections.EMPTY_LIST); + Collections unmodifiableCollection = Collections.unmodifiableCollection(Collections.EMPTY_LIST); - Collections.unmodifiableList(Collections.EMPTY_LIST); - Collections.unmodifiableSet(Collections.EMPTY_SET); - Collections.unmodifiableMap(Collections.EMPTY_MAP); + List unmodifiableList = Collections.unmodifiableList(Collections.EMPTY_LIST); + Set unmodifiableSet = Collections.unmodifiableSet(Collections.EMPTY_SET); + Map unmodifiableMap = Collections.unmodifiableMap(Collections.EMPTY_MAP); - Collections.unmodifiableSortedSet(Collections.EMPTY_SET); - Collections.unmodifiableSortedMap(Collections.EMPTY_MAP); + SortedSet unmodifiableSortedSet = Collections.unmodifiableSortedSet(Collections.EMPTY_SET); + SortedMap unmodifiableSortedMap = Collections.unmodifiableSortedMap(Collections.EMPTY_MAP); - Collections.unmodifiableNavigableSet(Collections.EMPTY_SET); - Collections.unmodifiableNavigableMap(Collections.EMPTY_MAP); + NavigableSet unmodifiableNavigableSet = Collections.unmodifiableNavigableSet(Collections.EMPTY_SET); + NavigableMap unmodifiableNavigableMap = Collections.unmodifiableNavigableMap(Collections.EMPTY_MAP); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeUnmodifiableMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeUnmodifiableMethod.java index 861c863d209a..4f550b011126 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeUnmodifiableMethod.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeUnmodifiableMethod.java @@ -1,20 +1,20 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; +import java.util.*; class Main { public static void main(String[] args) { - Collections.unmodifiableCollection(Collections.emptyList()); + Collections unmodifiableCollection = Collections.unmodifiableCollection(Collections.emptyList()); - Collections.unmodifiableList(Collections.emptyList()); - Collections.unmodifiableSet(Collections.emptySet()); - Collections.unmodifiableMap(Collections.emptyMap()); + List unmodifiableList = Collections.unmodifiableList(Collections.emptyList()); + Set unmodifiableSet = Collections.unmodifiableSet(Collections.emptySet()); + Map unmodifiableMap = Collections.unmodifiableMap(Collections.emptyMap()); - Collections.unmodifiableSortedSet(Collections.emptySet()); - Collections.unmodifiableSortedMap(Collections.emptyMap()); + SortedSet unmodifiableSortedSet = Collections.unmodifiableSortedSet(Collections.emptySet()); + SortedMap unmodifiableSortedMap = Collections.unmodifiableSortedMap(Collections.emptyMap()); - Collections.unmodifiableNavigableSet(Collections.emptySet()); - Collections.unmodifiableNavigableMap(Collections.emptyMap()); + NavigableSet unmodifiableNavigableSet = Collections.unmodifiableNavigableSet(Collections.emptySet()); + NavigableMap unmodifiableNavigableMap = Collections.unmodifiableNavigableMap(Collections.emptyMap()); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeWithComments.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeWithComments.java index 7f7c8dbfce8f..fd6492ec33c2 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeWithComments.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeWithComments.java @@ -1,20 +1,20 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; +import java.util.*; class Main { public static void main(String[] args) { - Collections/*empty*/./*empty too*/unmodifiableCollection/*blah blah blah*/(Collections.emptyList()); + Collection unmodifiableCollection = Collections/*empty*/./*empty too*/unmodifiableCollection/*blah blah blah*/(Collections.emptyList()); - Collections/*empty*/./*empty too*/unmodifiableList/*blah blah blah*/(Collections.emptyList()); - Collections/*empty*/./*empty too*/unmodifiableSet/*blah blah blah*/(Collections.emptySet()); - Collections/*empty*/./*empty too*/unmodifiableMap/*blah blah blah*/(Collections.emptyMap()); + List unmodifiableList = Collections/*empty*/./*empty too*/unmodifiableList/*blah blah blah*/(Collections.emptyList()); + Set unmodifiableSet = Collections/*empty*/./*empty too*/unmodifiableSet/*blah blah blah*/(Collections.emptySet()); + Map unmodifiableMap = Collections/*empty*/./*empty too*/unmodifiableMap/*blah blah blah*/(Collections.emptyMap()); - Collections/*empty*/./*empty too*/unmodifiableSortedSet/*blah blah blah*/(Collections.emptySet()); - Collections/*empty*/./*empty too*/unmodifiableSortedMap/*blah blah blah*/(Collections.emptyMap()); + SortedSet unmodifiableSortedSet = Collections/*empty*/./*empty too*/unmodifiableSortedSet/*blah blah blah*/(Collections.emptySet()); + SortedMap unmodifiableSortedMap = Collections/*empty*/./*empty too*/unmodifiableSortedMap/*blah blah blah*/(Collections.emptyMap()); - Collections/*empty*/./*empty too*/unmodifiableNavigableSet/*blah blah blah*/(Collections.emptySet()); - Collections/*empty*/./*empty too*/unmodifiableNavigableMap/*blah blah blah*/(Collections.emptyMap()); + NavigableSet unmodifiableNavigableSet = Collections/*empty*/./*empty too*/unmodifiableNavigableSet/*blah blah blah*/(Collections.emptySet()); + NavigableMap unmodifiableNavigableMap = Collections/*empty*/./*empty too*/unmodifiableNavigableMap/*blah blah blah*/(Collections.emptyMap()); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeWithParentheses.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeWithParentheses.java index 462309df66c7..0e1bee676e86 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeWithParentheses.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUnmodifiable/beforeWithParentheses.java @@ -1,20 +1,20 @@ -// "Fix all 'Redundant usage of unmodifiable collection factories' problems in file" "true" +// "Fix all 'Redundant usage of unmodifiable collection wrappers' problems in file" "true" -import java.util.Collections; +import java.util.*; class Main { public static void main(String[] args) { - Collections.unmodifiableCollection(((Collections.emptyList()))); + Collection unmodifiableCollection = Collections.unmodifiableCollection(((Collections.emptyList()))); - Collections.unmodifiableList(((Collections.emptyList()))); - Collections.unmodifiableSet(((Collections.emptySet()))); - Collections.unmodifiableMap(((Collections.emptyMap()))); + List unmodifiableList = Collections.unmodifiableList(((Collections.emptyList()))); + Set unmodifiableSet = Collections.unmodifiableSet(((Collections.emptySet()))); + Map unmodifiableMap = Collections.unmodifiableMap(((Collections.emptyMap()))); - Collections.unmodifiableSortedSet(((Collections.emptySet()))); - Collections.unmodifiableSortedMap(((Collections.emptyMap()))); + SortedSet unmodifiableSortedSet = Collections.unmodifiableSortedSet(((Collections.emptySet()))); + SortedMap unmodifiableSortedMap = Collections.unmodifiableSortedMap(((Collections.emptyMap()))); - Collections.unmodifiableNavigableSet(((Collections.emptySet()))); - Collections.unmodifiableNavigableMap(((Collections.emptyMap()))); + NavigableSet unmodifiableNavigableSet = Collections.unmodifiableNavigableSet(((Collections.emptySet()))); + NavigableMap unmodifiableNavigableMap = Collections.unmodifiableNavigableMap(((Collections.emptyMap()))); } } diff --git a/java/openapi/resources/messages/JavaBundle.properties b/java/openapi/resources/messages/JavaBundle.properties index a13d3a1edf88..0f7c77bd099f 100644 --- a/java/openapi/resources/messages/JavaBundle.properties +++ b/java/openapi/resources/messages/JavaBundle.properties @@ -1550,6 +1550,6 @@ postfix.template.condition.boolean.name=boolean postfix.template.condition.number.name=number postfix.template.condition.not.primitive.type.name=not primitive type postfix.template.condition.array.name=array -inspection.redundant.unmodifiable.call.display.name=Redundant usage of the ''{0}'' factory -inspection.redundant.unmodifiable.call.description=Redundant usage of unmodifiable collection factories -inspection.redundant.unmodifiable.call.replace.with.arg.quickfix=Unwrap argument +inspection.redundant.unmodifiable.call.display.name=Redundant usage of the ''{0}'' wrapper +inspection.redundant.unmodifiable.call.description=Redundant usage of unmodifiable collection wrappers +inspection.redundant.unmodifiable.call.unwrap.argument.quickfix=Unwrap argument