redundant cast: take into account custom return type processing for getClass (IDEA-109527)

This commit is contained in:
Anna Kozlova
2013-06-25 21:34:51 +04:00
parent 7e85581ef8
commit a00aac060c
4 changed files with 15 additions and 2 deletions
@@ -251,8 +251,8 @@ public class RedundantCastUtil {
final JavaResolveResult newResult = newCall.getMethodExpression().advancedResolve(false);
if (!newResult.isValidResult()) return;
final PsiMethod newTargetMethod = (PsiMethod)newResult.getElement();
final PsiType newReturnType = newResult.getSubstitutor().substitute(newTargetMethod.getReturnType());
final PsiType oldReturnType = resolveResult.getSubstitutor().substitute(targetMethod.getReturnType());
final PsiType newReturnType = newCall.getType();
final PsiType oldReturnType = methodCall.getType();
if (Comparing.equal(newReturnType, oldReturnType)) {
if (newTargetMethod.equals(targetMethod) ||
(newTargetMethod.getSignature(newResult.getSubstitutor()).equals(targetMethod.getSignature(resolveResult.getSubstitutor())) &&
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -0,0 +1,10 @@
class B { }
class A extends B { }
class C {
void m(Class<? extends A> c) {}
void x(B b) {
m(((A)b).getClass());
}
}
@@ -46,6 +46,7 @@ public class RedundantCast15Test extends InspectionTestCase {
public void testIDEA22899() throws Exception { doTest();}
public void testRawCast1() throws Exception { doTest();}
public void testInferenceFromCast() throws Exception { doTest();}
public void testGetClassProcessing() throws Exception { doTest();}
public void testTypeParameterAccessChecksJava7() throws Exception {
((JavaVersionServiceImpl)JavaVersionService.getInstance()).setTestVersion(JavaSdkVersion.JDK_1_7, getTestRootDisposable());