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 9815601a16c9..6815ca94c9df 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 @@ -158,8 +158,9 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction { } private static PsiElement findCodeBlock(PsiIfStatement ifStatement) { - PsiElement e = PsiTreeUtil.getParentOfType(ifStatement, PsiMethod.class, PsiClassInitializer.class); + PsiElement e = PsiTreeUtil.getParentOfType(ifStatement, PsiMethod.class, PsiClassInitializer.class, PsiLambdaExpression.class); if (e instanceof PsiMethod) return ((PsiMethod) e).getBody(); + if (e instanceof PsiLambdaExpression) return ((PsiLambdaExpression)e).getBody(); if (e instanceof PsiClassInitializer) return ((PsiClassInitializer) e).getBody(); return null; } diff --git a/java/java-tests/testData/codeInsight/invertIfCondition/afterInsideLambda.java b/java/java-tests/testData/codeInsight/invertIfCondition/afterInsideLambda.java new file mode 100644 index 000000000000..0c58356b054b --- /dev/null +++ b/java/java-tests/testData/codeInsight/invertIfCondition/afterInsideLambda.java @@ -0,0 +1,13 @@ +// "Invert If Condition" "true" +class A { + public void foo() { + Runnable r = () -> { + if (System.currentTimeMillis() <= 1) { + System.err.println("Elvis lives"); + } + else { + return; + } + }; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/invertIfCondition/beforeInsideLambda.java b/java/java-tests/testData/codeInsight/invertIfCondition/beforeInsideLambda.java new file mode 100644 index 000000000000..85aa03f9edac --- /dev/null +++ b/java/java-tests/testData/codeInsight/invertIfCondition/beforeInsideLambda.java @@ -0,0 +1,11 @@ +// "Invert If Condition" "true" +class A { + public void foo() { + Runnable r = () -> { + if (System.currentTimeMillis() > 1) { + return; + } + System.err.println("Elvis lives"); + }; + } +} \ No newline at end of file