From 1703f863b879105cc870493c2397eaa9b4367347 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 6 Sep 2012 14:24:11 +0400 Subject: [PATCH] lambda: correct control flow for lambda body; additional test for IDEA-91076 --- .../extractMethod/FromLambdaBody.java | 23 ++++++++++++++++ .../extractMethod/FromLambdaBody_after.java | 27 +++++++++++++++++++ .../refactoring/ExtractMethodTest.java | 4 +++ 3 files changed, 54 insertions(+) create mode 100644 java/java-tests/testData/refactoring/extractMethod/FromLambdaBody.java create mode 100644 java/java-tests/testData/refactoring/extractMethod/FromLambdaBody_after.java diff --git a/java/java-tests/testData/refactoring/extractMethod/FromLambdaBody.java b/java/java-tests/testData/refactoring/extractMethod/FromLambdaBody.java new file mode 100644 index 000000000000..eba4ec178fd7 --- /dev/null +++ b/java/java-tests/testData/refactoring/extractMethod/FromLambdaBody.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. + */ +class Test { + public void foo() { + Runnable r = () -> { + String hello = "hello"; + System.out.println(hello); + }; + } +} diff --git a/java/java-tests/testData/refactoring/extractMethod/FromLambdaBody_after.java b/java/java-tests/testData/refactoring/extractMethod/FromLambdaBody_after.java new file mode 100644 index 000000000000..b8f419191a62 --- /dev/null +++ b/java/java-tests/testData/refactoring/extractMethod/FromLambdaBody_after.java @@ -0,0 +1,27 @@ +/* + * 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. + */ +class Test { + public void foo() { + Runnable r = () -> { + String hello = "hello"; + newMethod(hello); + }; + } + + private void newMethod(String hello) { + System.out.println(hello); + } +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java index 803987f50f16..7d2747f2d5b3 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ExtractMethodTest.java @@ -532,6 +532,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase { doTest(); } + public void testFromLambdaBody() throws Exception { + doTest(); + } + private void doTestDisabledParam() throws PrepareFailedException { final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()); settings.ELSE_ON_NEW_LINE = true;