diff --git a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/AtomicConversionRule.java b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/AtomicConversionRule.java index 2ba1e0fa7461..acefde2c937e 100644 --- a/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/AtomicConversionRule.java +++ b/java/typeMigration/src/com/intellij/refactoring/typeMigration/rules/AtomicConversionRule.java @@ -206,7 +206,10 @@ public class AtomicConversionRule extends TypeConversionRule { final PsiJavaToken signToken = ((PsiAssignmentExpression)context).getOperationSign(); final IElementType operationSign = signToken.getTokenType(); final String sign = signToken.getText(); - if (parent instanceof PsiExpressionStatement) { + boolean voidContext = parent instanceof PsiExpressionStatement || + (parent instanceof PsiLambdaExpression && PsiType.VOID.equals(LambdaUtil.getFunctionalInterfaceReturnType( + (PsiFunctionalExpression)parent))); + if (voidContext) { if (operationSign == JavaTokenType.EQ) { final PsiExpression lExpression = ((PsiAssignmentExpression)context).getLExpression(); if (lExpression instanceof PsiReferenceExpression) { diff --git a/java/typeMigration/testData/intentions/atomic/afterInLambdas.java b/java/typeMigration/testData/intentions/atomic/afterInLambdas.java new file mode 100644 index 000000000000..fc7061887455 --- /dev/null +++ b/java/typeMigration/testData/intentions/atomic/afterInLambdas.java @@ -0,0 +1,14 @@ +import java.util.concurrent.atomic.AtomicInteger; + +// "Convert to atomic" "true" +public class InLambdas +{ + public void test() + { + AtomicInteger x = new AtomicInteger(0); + Runnable r1 = () -> x.getAndIncrement(); + Runnable r2 = () -> x.addAndGet(2); + Runnable r3 = () -> x.updateAndGet(v -> v * 2); + Runnable r4 = () -> x.set(5); + } +} \ No newline at end of file diff --git a/java/typeMigration/testData/intentions/atomic/beforeInLambdas.java b/java/typeMigration/testData/intentions/atomic/beforeInLambdas.java new file mode 100644 index 000000000000..0a947749547e --- /dev/null +++ b/java/typeMigration/testData/intentions/atomic/beforeInLambdas.java @@ -0,0 +1,12 @@ +// "Convert to atomic" "true" +public class InLambdas +{ + public void test() + { + int x = 0; + Runnable r1 = () -> x++; + Runnable r2 = () -> x+=2; + Runnable r3 = () -> x*=2; + Runnable r4 = () -> x = 5; + } +} \ No newline at end of file