redundant code block: compare same overload resolution (IDEA-174288)

instead of trying with cast afterwards, don't suggest to remove the block at the first place
This commit is contained in:
Anna Kozlova
2017-06-14 11:48:31 +03:00
parent 268a6149e3
commit 3dff91600a
2 changed files with 6 additions and 3 deletions

View File

@@ -87,7 +87,8 @@ public class RedundantLambdaCodeBlockInspection extends BaseJavaBatchLocalInspec
if (psiExpression != null && !findCommentsOutsideExpression(body, psiExpression)) {
if (LambdaUtil.isExpressionStatementExpression(psiExpression)) {
final PsiCall call = LambdaUtil.treeWalkUp(body);
if (call != null && call.resolveMethod() != null) {
PsiMethod oldTarget;
if (call != null && (oldTarget = call.resolveMethod()) != null) {
final int offsetInTopCall = body.getTextRange().getStartOffset() - call.getTextRange().getStartOffset();
PsiCall copyCall = LambdaUtil.copyTopLevelCall(call);
if (copyCall == null) return null;
@@ -96,7 +97,7 @@ public class RedundantLambdaCodeBlockInspection extends BaseJavaBatchLocalInspec
final PsiElement parent = codeBlock.getParent();
if (parent instanceof PsiLambdaExpression) {
codeBlock.replace(psiExpression);
if (copyCall.resolveMethod() == null || ((PsiLambdaExpression)parent).getFunctionalInterfaceType() == null) {
if (copyCall.resolveMethod() != oldTarget || ((PsiLambdaExpression)parent).getFunctionalInterfaceType() == null) {
return null;
}
}

View File

@@ -9,6 +9,8 @@ class A {
}
public static void main(String[] args) {
submit((Runnable) () -> new A());
submit(() -> {
new A();
});
}
}