mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
suspicious removeAll: compare type arguments, not qualifiers
This commit is contained in:
+7
-4
@@ -158,11 +158,14 @@ public class SuspiciousMethodCallUtil {
|
||||
PsiType paramType = parameters[0].getType();
|
||||
if (InheritanceUtil.isInheritor(paramType, CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
PsiType qualifierType = qualifier.getType();
|
||||
if (qualifierType != null && !qualifierType.isAssignableFrom(argType)) {
|
||||
if (qualifierType != null) {
|
||||
final PsiType itemType = JavaGenericsUtil.getCollectionItemType(argType, calleeMethod.getResolveScope());
|
||||
return InspectionsBundle.message("inspection.suspicious.collections.method.calls.problem.descriptor",
|
||||
PsiFormatUtil.formatType(qualifierType, 0, PsiSubstitutor.EMPTY),
|
||||
PsiFormatUtil.formatType(itemType, 0, PsiSubstitutor.EMPTY));
|
||||
final PsiType qualifierItemType = JavaGenericsUtil.getCollectionItemType(qualifierType, calleeMethod.getResolveScope());
|
||||
if (qualifierItemType != null && itemType != null && !qualifierItemType.isAssignableFrom(itemType)) {
|
||||
return InspectionsBundle.message("inspection.suspicious.collections.method.calls.problem.descriptor",
|
||||
PsiFormatUtil.formatType(qualifierType, 0, PsiSubstitutor.EMPTY),
|
||||
PsiFormatUtil.formatType(itemType, 0, PsiSubstitutor.EMPTY));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
class Clazz {
|
||||
void foo(List<String> l, Set<String> s) {
|
||||
l.removeAll(s);
|
||||
}
|
||||
}
|
||||
+1
@@ -21,6 +21,7 @@ public class SuspiciousCollectionMethodCallsTest extends LightCodeInsightFixture
|
||||
|
||||
public void testConcurrentHashMap() throws Exception { doTest(); }
|
||||
public void testRemoveAllCall() throws Exception { doTest(); }
|
||||
public void testSetList() throws Exception { doTest(); }
|
||||
public void testUseDfa() throws Exception { doTest(); }
|
||||
public void testWildcard() throws Exception { doTest(); }
|
||||
public void testIgnoreConvertible() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user