mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
redundant cast: always report casts in instanceOf checks for class types; exclude primitive types
This commit is contained in:
@@ -21,7 +21,6 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.source.resolve.DefaultParameterTypeInferencePolicy;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -494,7 +493,10 @@ public class RedundantCastUtil {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (TypeConversionUtil.isAssignable(castTo, opType, false)) {
|
||||
if (parent instanceof PsiInstanceOfExpression && opType instanceof PsiPrimitiveType) {
|
||||
return;
|
||||
}
|
||||
if (parent instanceof PsiInstanceOfExpression || TypeConversionUtil.isAssignable(castTo, opType, false)) {
|
||||
addToResults(typeCast);
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>8</line>
|
||||
<description>Casting <code>o</code> to <code>List</code> is redundant</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RedundantCast {
|
||||
boolean redundantCasts(Object o) {
|
||||
int p = 0;
|
||||
if ((Number)p instanceof Integer) {}
|
||||
return (List)o instanceof ArrayList;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ public class RedundantCast15Test extends InspectionTestCase {
|
||||
public void testRawCast1() throws Exception { doTest();}
|
||||
public void testInferenceFromCast() throws Exception { doTest();}
|
||||
public void testGetClassProcessing() throws Exception { doTest();}
|
||||
public void testInstanceOfChecks() throws Exception { doTest();}
|
||||
|
||||
public void testTypeParameterAccessChecksJava7() throws Exception {
|
||||
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_7, getModule(), getTestRootDisposable());
|
||||
|
||||
Reference in New Issue
Block a user