From 101ad553b7fc075d0ba7b421b92199b7f1ef106c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 29 Dec 2020 13:05:02 +0100 Subject: [PATCH] java invert if: ignore redundant return stmts (IDEA-258495) GitOrigin-RevId: 4a1fc182d5e8e053dd60288b85764a511e72c08a --- .../codeInsight/intention/impl/InvertIfConditionAction.java | 3 ++- .../afterBrokenCodeWithTypeParameterDeclaredInside.java | 3 --- .../testData/codeInsight/invertIfCondition/afterFlow3.java | 3 --- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java index 8367c89f227f..c21e8d7f208a 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java @@ -327,7 +327,8 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction { } } } - if (thenBranch instanceof PsiContinueStatement) { + if (thenBranch instanceof PsiContinueStatement || + thenBranch instanceof PsiReturnStatement && ((PsiReturnStatement)thenBranch).getReturnValue() == null) { PsiStatement elseBranch = ifStatement.getElseBranch(); if (elseBranch != null) { elseBranch.delete(); diff --git a/java/java-tests/testData/codeInsight/invertIfCondition/afterBrokenCodeWithTypeParameterDeclaredInside.java b/java/java-tests/testData/codeInsight/invertIfCondition/afterBrokenCodeWithTypeParameterDeclaredInside.java index 96b0156d673a..f4e442ce1d81 100644 --- a/java/java-tests/testData/codeInsight/invertIfCondition/afterBrokenCodeWithTypeParameterDeclaredInside.java +++ b/java/java-tests/testData/codeInsight/invertIfCondition/afterBrokenCodeWithTypeParameterDeclaredInside.java @@ -12,8 +12,5 @@ class A { }); } - else { - return; - } } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/invertIfCondition/afterFlow3.java b/java/java-tests/testData/codeInsight/invertIfCondition/afterFlow3.java index c458d370f243..dfc54b13eeb8 100644 --- a/java/java-tests/testData/codeInsight/invertIfCondition/afterFlow3.java +++ b/java/java-tests/testData/codeInsight/invertIfCondition/afterFlow3.java @@ -4,8 +4,5 @@ class A { if (c) { foo(); } - else { - return; - } } } \ No newline at end of file