diff --git a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java index bbaa5017f036..90b235c071ff 100644 --- a/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java +++ b/java/java-psi-impl/src/com/intellij/psi/controlFlow/ControlFlowAnalyzer.java @@ -1449,6 +1449,16 @@ class ControlFlowAnalyzer extends JavaElementVisitor { @Override public void visitLambdaExpression(PsiLambdaExpression expression) { startElement(expression); + final PsiElement body = expression.getBody(); + if (body != null) { + body.accept(this); + List array = new ArrayList(); + addUsedVariables(array, body); + for (PsiVariable var : array) { + ProgressIndicatorProvider.checkCanceled(); + generateReadInstruction(var); + } + } finishElement(expression); } diff --git a/java/java-tests/testData/refactoring/inlineLocal/LocalVarInsideLambdaBody.java b/java/java-tests/testData/refactoring/inlineLocal/LocalVarInsideLambdaBody.java new file mode 100644 index 000000000000..550a93f4addf --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineLocal/LocalVarInsideLambdaBody.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +public class Test2 { + { + final String p = "hello"; + Runnable r = () -> {System.out.println(p);}; + System.out.println(p); + } +} + diff --git a/java/java-tests/testData/refactoring/inlineLocal/LocalVarInsideLambdaBody.java.after b/java/java-tests/testData/refactoring/inlineLocal/LocalVarInsideLambdaBody.java.after new file mode 100644 index 000000000000..e941dd3d7453 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineLocal/LocalVarInsideLambdaBody.java.after @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +public class Test2 { + { + Runnable r = () -> {System.out.println("hello");}; + System.out.println("hello"); + } +} + diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java index 24c3fda9ecc5..45103653238f 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineLocalTest.java @@ -154,6 +154,10 @@ public class InlineLocalTest extends LightCodeInsightTestCase { doTest(true); } + public void testLocalVarInsideLambdaBody() throws Exception { + doTest(true); + } + private void doTest(final boolean inlineDef, String conflictMessage) throws Exception { try { doTest(inlineDef);