suspicious call should ignore captured wildcard types assignments (IDEADEV-39955)

This commit is contained in:
Anna Kozlova
2009-09-03 18:27:27 +04:00
parent 28c7e9091b
commit 8e117beff5
7 changed files with 30 additions and 5 deletions
@@ -21,6 +21,7 @@ public class SuspiciousCollectionMethodCallsTest extends InspectionTestCase {
}
public void testWildcardCapture() throws Exception { doTest(); }
public void testWildcard() throws Exception { doTest(); }
public void testIgnoreConvertible() throws Exception {
myTool.REPORT_CONVERTIBLE_METHOD_CALLS = false;
doTest();
@@ -143,6 +143,9 @@ public class SuspiciousCollectionsMethodCallsInspection extends BaseLocalInspect
PsiType typeParamMapping = substitutor.substitute(typeParameter);
if (typeParamMapping == null) return;
String message = null;
if (typeParamMapping instanceof PsiCapturedWildcardType) {
typeParamMapping = ((PsiCapturedWildcardType)typeParamMapping).getWildcard();
}
if (!typeParamMapping.isAssignableFrom(argType)) {
if (typeParamMapping.isConvertibleFrom(argType)) {
if (REPORT_CONVERTIBLE_METHOD_CALLS) {
@@ -1,4 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>13</line>
<description>'List&lt;? extends Number&gt;' may not contain objects of type 'String'</description>
</problem>
</problems>
@@ -8,4 +8,8 @@ class Clazz {
return;
}
}
void foo(List<? extends Number> c) {
c.contains("");
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>6</line>
<description>'List&lt;? extends Number&gt;' may not contain objects of type 'String'</description>
</problem>
</problems>
@@ -0,0 +1,8 @@
import java.util.List;
import java.util.ArrayList;
class Clazz {
void foo(List<? extends Number> l) {
boolean b = l.contains("");
}
}
@@ -1,9 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>7</line>
<description>Suspicious call to 'List.indexOf'</description>
</problem>
</problems>