mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
redundant cast: take into account custom return type processing for getClass (IDEA-109527)
This commit is contained in:
@@ -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())) &&
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems/>
|
||||
+10
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user