mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
redundant cast: open capture to compare old and new result types
This commit is contained in:
@@ -281,10 +281,13 @@ public class RedundantCastUtil {
|
||||
final JavaResolveResult newResult = newCall.getMethodExpression().advancedResolve(false);
|
||||
if (!newResult.isValidResult()) return;
|
||||
final PsiMethod newTargetMethod = (PsiMethod)newResult.getElement();
|
||||
final PsiType newReturnType = newCall.getType();
|
||||
final PsiType oldReturnType = methodCall.getType();
|
||||
PsiType newReturnType = newCall.getType(), oldReturnType = methodCall.getType();
|
||||
if (newReturnType instanceof PsiCapturedWildcardType && oldReturnType instanceof PsiCapturedWildcardType) {
|
||||
newReturnType = ((PsiCapturedWildcardType)newReturnType).getUpperBound();
|
||||
oldReturnType = ((PsiCapturedWildcardType)oldReturnType).getUpperBound();
|
||||
}
|
||||
if (Comparing.equal(newReturnType, oldReturnType)) {
|
||||
if (newTargetMethod.equals(targetMethod) ||
|
||||
if (Comparing.equal(newTargetMethod, targetMethod) ||
|
||||
(newTargetMethod.getSignature(newResult.getSubstitutor()).equals(targetMethod.getSignature(resolveResult.getSubstitutor())) &&
|
||||
!(newTargetMethod.isDeprecated() && !targetMethod.isDeprecated()) && // see SCR11555, SCR14559
|
||||
areThrownExceptionsCompatible(targetMethod, newTargetMethod))) {
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
interface Pair<A extends String> {
|
||||
A get();
|
||||
}
|
||||
|
||||
class B {
|
||||
void m(final Pair<?> p) {
|
||||
String v = ((<warning descr="Casting 'p' to 'Pair<?>' is redundant">Pair<?></warning>) p).get();
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -56,6 +56,11 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
public void testCastInMethodCallQualifierWithWildcardReturn() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user