diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/AbstractInplaceIntroduceFunctionTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/AbstractInplaceIntroduceFunctionTest.kt
new file mode 100644
index 000000000000..9e794f156cf4
--- /dev/null
+++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/AbstractInplaceIntroduceFunctionTest.kt
@@ -0,0 +1,60 @@
+// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+package org.jetbrains.kotlin.idea.refactoring.introduce
+
+import com.intellij.codeInsight.template.impl.TemplateManagerImpl
+import com.intellij.java.refactoring.ExtractMethodAndDuplicatesInplaceTest.Companion.nextTemplateVariable
+import com.intellij.java.refactoring.ExtractMethodAndDuplicatesInplaceTest.Companion.renameTemplate
+import com.intellij.openapi.application.impl.NonBlockingReadActionImpl
+import com.intellij.util.ui.UIUtil
+import org.jetbrains.kotlin.idea.base.test.IgnoreTests
+import org.jetbrains.kotlin.idea.base.test.InTextDirectivesUtils
+import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.AbstractExtractKotlinFunctionHandler
+import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.ExtractKotlinFunctionHandler
+import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
+import java.io.File
+
+abstract class AbstractInplaceIntroduceFunctionTest : KotlinLightCodeInsightFixtureTestCase() {
+ fun doTest(unused: String) {
+ val disableTestDirective = if (isFirPlugin) IgnoreTests.DIRECTIVES.IGNORE_K2 else IgnoreTests.DIRECTIVES.IGNORE_K1
+
+ IgnoreTests.runTestIfNotDisabledByFileDirective(
+ dataFilePath(),
+ disableTestDirective,
+ directivePosition = IgnoreTests.DirectivePosition.LAST_LINE_IN_FILE
+ ) { isTestEnabled -> doTestInternal() }
+ }
+
+ private fun doTestInternal() {
+ TemplateManagerImpl.setTemplateTesting(testRootDisposable)
+ val mainFile = File(testDataDirectory, fileName())
+ myFixture.testDataPath = mainFile.parent
+ val file = myFixture.configureByFile(mainFile.name)
+ getExtractFunctionHandler(getTestName(true).contains("Local")).invoke(myFixture.project, myFixture.editor, myFixture.file, null)
+ NonBlockingReadActionImpl.waitForAsyncTaskCompletion()
+ val template = getActiveTemplate()
+ require(template != null) { "Failed to start refactoring" }
+
+ val fileText = file.text
+ val changedName: String? = InTextDirectivesUtils.findListWithPrefixes(fileText, "// CHANGED_NAME: ").firstOrNull()
+ val checkResult: Boolean = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// IGNORE_RESULT")
+ if (changedName != null) {
+ renameTemplate(template, changedName)
+ }
+ nextTemplateVariable(template)
+ UIUtil.dispatchAllInvocationEvents()
+ if (checkResult) {
+ val testName = getTestName(false)
+ var expectedFile = "$testName.kt.after"
+ if (isFirPlugin && File(testDataDirectory, "$testName.kt.fir.after").exists()) {
+ expectedFile = "$testName.kt.fir.after"
+ }
+
+ myFixture.checkResultByFile(expectedFile)
+ }
+ }
+
+ protected open fun getExtractFunctionHandler(allContainersEnabled: Boolean): AbstractExtractKotlinFunctionHandler =
+ ExtractKotlinFunctionHandler(allContainersEnabled)
+
+ private fun getActiveTemplate() = TemplateManagerImpl.getTemplateState(editor)
+}
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/InplaceExtractFunctionTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/InplaceExtractFunctionTest.kt
deleted file mode 100644
index 8e0971e0a41e..000000000000
--- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/InplaceExtractFunctionTest.kt
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
-package org.jetbrains.kotlin.idea.refactoring.introduce
-
-import com.intellij.codeInsight.template.impl.TemplateManagerImpl
-import com.intellij.java.refactoring.ExtractMethodAndDuplicatesInplaceTest.Companion.nextTemplateVariable
-import com.intellij.java.refactoring.ExtractMethodAndDuplicatesInplaceTest.Companion.renameTemplate
-import com.intellij.openapi.application.impl.NonBlockingReadActionImpl
-import com.intellij.util.ui.UIUtil
-import junit.framework.TestCase
-import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.ExtractKotlinFunctionHandler
-import org.jetbrains.kotlin.idea.test.IDEA_TEST_DATA_DIR
-import org.jetbrains.kotlin.idea.test.JUnit3RunnerWithInners
-import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
-import org.junit.runner.RunWith
-
-@RunWith(JUnit3RunnerWithInners::class)
-class InplaceExtractFunctionTest : KotlinLightCodeInsightFixtureTestCase() {
-
- override val testDataDirectory = IDEA_TEST_DATA_DIR.resolve("refactoring/extractFunctionInplace")
-
- fun testStringTemplate() {
- doTest()
- }
-
- fun testStringTemplateWithNameConflict() {
- doTest(changedName = "substring")
- }
-
- fun testConflictNameNotAccepted() {
- doTest(changedName = "conflict", checkResult = false)
- TestCase.assertTrue(getActiveTemplate() != null)
- }
-
- fun testConsecutiveDuplicates() {
- doTest(changedName = "renamed")
- }
-
- fun testExposedAssignment() {
- doTest(changedName = "getX")
- }
-
- fun doTest(changedName: String? = null, checkResult: Boolean = true) {
- TemplateManagerImpl.setTemplateTesting(testRootDisposable)
- myFixture.configureByFile("${getTestName(false)}.kt")
- ExtractKotlinFunctionHandler().invoke(myFixture.project, myFixture.editor, myFixture.file, null)
- NonBlockingReadActionImpl.waitForAsyncTaskCompletion()
- val template = getActiveTemplate()
- require(template != null) { "Failed to start refactoring" }
- if (changedName != null) {
- renameTemplate(template, changedName)
- }
- nextTemplateVariable(template)
- UIUtil.dispatchAllInvocationEvents()
- if (checkResult) {
- myFixture.checkResultByFile("${getTestName(false)}.after.kt")
- }
- }
-
- private fun getActiveTemplate() = TemplateManagerImpl.getTemplateState(editor)
-}
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/InplaceIntroduceFunctionTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/InplaceIntroduceFunctionTestGenerated.java
new file mode 100644
index 000000000000..2e2ff34d852d
--- /dev/null
+++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/InplaceIntroduceFunctionTestGenerated.java
@@ -0,0 +1,85 @@
+// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+
+package org.jetbrains.kotlin.idea.refactoring.introduce;
+
+import com.intellij.testFramework.TestDataPath;
+import org.jetbrains.kotlin.idea.test.JUnit3RunnerWithInners;
+import org.jetbrains.kotlin.idea.test.KotlinTestUtils;
+import org.jetbrains.kotlin.test.TestMetadata;
+import org.jetbrains.kotlin.idea.base.test.TestRoot;
+import org.junit.runner.RunWith;
+
+/**
+ * This class is generated by {@link org.jetbrains.kotlin.testGenerator.generator.TestGenerator}.
+ * DO NOT MODIFY MANUALLY.
+ */
+@SuppressWarnings("all")
+@TestRoot("idea/tests")
+@TestDataPath("$CONTENT_ROOT")
+@RunWith(JUnit3RunnerWithInners.class)
+@TestMetadata("testData/refactoring/extractFunctionInplace")
+public class InplaceIntroduceFunctionTestGenerated extends AbstractInplaceIntroduceFunctionTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
+ }
+
+ @TestMetadata("ConflictNameNotAccepted.kt")
+ public void testConflictNameNotAccepted() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt");
+ }
+
+ @TestMetadata("ConsecutiveDuplicates.kt")
+ public void testConsecutiveDuplicates() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.kt");
+ }
+
+ @TestMetadata("DontSkipWhitespacesBefore.kt")
+ public void testDontSkipWhitespacesBefore() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.kt");
+ }
+
+ @TestMetadata("EmptySpaces.kt")
+ public void testEmptySpaces() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/EmptySpaces.kt");
+ }
+
+ @TestMetadata("ExposedAssignment.kt")
+ public void testExposedAssignment() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/ExposedAssignment.kt");
+ }
+
+ @TestMetadata("ExtractLocal.kt")
+ public void testExtractLocal() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/ExtractLocal.kt");
+ }
+
+ @TestMetadata("MoveLambdaOutsideParenthesis.kt")
+ public void testMoveLambdaOutsideParenthesis() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis.kt");
+ }
+
+ @TestMetadata("MoveLambdaOutsideParenthesis1.kt")
+ public void testMoveLambdaOutsideParenthesis1() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis1.kt");
+ }
+
+ @TestMetadata("SearchForCallAfter.kt")
+ public void testSearchForCallAfter() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/SearchForCallAfter.kt");
+ }
+
+ @TestMetadata("SkipCommentsBefore.kt")
+ public void testSkipCommentsBefore() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/SkipCommentsBefore.kt");
+ }
+
+ @TestMetadata("StringTemplate.kt")
+ public void testStringTemplate() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/StringTemplate.kt");
+ }
+
+ @TestMetadata("StringTemplateWithNameConflict.kt")
+ public void testStringTemplateWithNameConflict() throws Exception {
+ runTest("testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt");
+ }
+}
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt
index e7963fed3faf..8242625b67db 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt
@@ -1,3 +1,5 @@
+// CHANGED_NAME: conflict
+// IGNORE_RESULT
fun sample(){
println("42")
}
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt.after
similarity index 56%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt.after
index 92bb0a6ba417..f057840f90a3 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.after.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt.after
@@ -1,3 +1,5 @@
+// CHANGED_NAME: conflict
+// IGNORE_RESULT
fun sample(){
println("42")
}
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.kt
index 8a579f13d0a8..e4166000494b 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.kt
@@ -1,3 +1,4 @@
+// CHANGED_NAME: renamed
fun sample(){
println("duplicate")
println("duplicate")
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.kt.after
similarity index 80%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.kt.after
index 72023161e271..09bf1de77a29 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.after.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.kt.after
@@ -1,3 +1,4 @@
+// CHANGED_NAME: renamed
fun sample(){
renamed()
renamed()
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.kt.after
similarity index 100%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.kt.after
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.kt
index ef2ef7f9b633..8b5e13747936 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.kt
@@ -10,4 +10,5 @@ fun foo() {
print(10)
-}
\ No newline at end of file
+}
+// IGNORE_K1
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.kt.after
similarity index 93%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.kt.after
index 3a726c3060cd..66a7b3813bfb 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.after.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.kt.after
@@ -15,4 +15,5 @@ private fun bool(v: IntRange): Boolean {
}
}
return false
-}
\ No newline at end of file
+}
+// IGNORE_K1
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.kt
index bfcb9cfec33b..40e9c436df50 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.kt
@@ -1,3 +1,4 @@
+// CHANGED_NAME: getX
fun sample(){
val x = 42
println()
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.kt.after
similarity index 85%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.kt.after
index 7df567326498..5c1da5c1c5f5 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.after.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.kt.after
@@ -1,3 +1,4 @@
+// CHANGED_NAME: getX
fun sample(){
val x = getX()
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExtractLocal.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExtractLocal.kt.after
similarity index 100%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExtractLocal.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/ExtractLocal.kt.after
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis.kt.after b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis.kt.after
new file mode 100644
index 000000000000..b1b202ef2303
--- /dev/null
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis.kt.after
@@ -0,0 +1,7 @@
+fun interface FunctionalInterface {
+ fun paramOutput(name: String): String
+}
+
+fun getFunInterface(): FunctionalInterface = FunctionalInterface(function())
+
+private fun function() = { paramName -> "ParamName is $paramName!" }
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis.kt.fir.after
similarity index 100%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis.kt.fir.after
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis1.kt.after b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis1.kt.after
new file mode 100644
index 000000000000..e29eaa91e3ba
--- /dev/null
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis1.kt.after
@@ -0,0 +1,6 @@
+val lazyFun: Int by lazy(function())
+
+private fun function() = {
+ print("i'm lazy")
+ 1000
+}
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis1.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis1.kt.fir.after
similarity index 100%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis1.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis1.kt.fir.after
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.after.kt
deleted file mode 100644
index 70ace04a5633..000000000000
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.after.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-fun initList() = ints()
-
-private fun ints(): List = listOf(1, 2, 3, 4)
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.kt
index e02b38250aa4..f260a5037b3e 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.kt
@@ -1 +1,2 @@
-fun initList() = listOf(1,2,3,4)
\ No newline at end of file
+fun initList() = listOf(1,2,3,4)
+// IGNORE_K1
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.kt.after b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.kt.after
new file mode 100644
index 000000000000..9d9ee2e714d9
--- /dev/null
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.kt.after
@@ -0,0 +1,4 @@
+fun initList() = ints()
+
+private fun ints(): List = listOf(1, 2, 3, 4)
+// IGNORE_K1
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SkipCommentsBefore.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SkipCommentsBefore.kt.after
similarity index 100%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SkipCommentsBefore.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/SkipCommentsBefore.kt.after
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplate.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplate.kt.after
similarity index 100%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplate.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplate.kt.after
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplate.fir.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplate.kt.fir.after
similarity index 100%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplate.fir.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplate.kt.fir.after
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt
index ecba7a02f991..2d7548642fd9 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt
@@ -1,3 +1,4 @@
+// CHANGED_NAME: substring
val example = "STRING_SAMPLE_BIG"
fun s(): String = "42"
\ No newline at end of file
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt.after
similarity index 78%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt.after
index e635d8b5fe78..ffaf23dcd180 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.after.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt.after
@@ -1,3 +1,4 @@
+// CHANGED_NAME: substring
val example = "STRING_${substring()}_BIG"
private fun substring() = "SAMPLE"
diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.fir.after.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt.fir.after
similarity index 80%
rename from plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.fir.after.kt
rename to plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt.fir.after
index a8088e96d684..58a7a475e986 100644
--- a/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.fir.after.kt
+++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt.fir.after
@@ -1,3 +1,4 @@
+// CHANGED_NAME: substring
val example = "STRING_${substring()}_BIG"
private fun substring(): String = "SAMPLE"
diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/AbstractK2InplaceIntroduceFunctionTest.kt b/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/AbstractK2InplaceIntroduceFunctionTest.kt
new file mode 100644
index 000000000000..c14ba5e3197e
--- /dev/null
+++ b/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/AbstractK2InplaceIntroduceFunctionTest.kt
@@ -0,0 +1,26 @@
+// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+package org.jetbrains.kotlin.idea.k2.refactoring.introduce
+
+import com.intellij.testFramework.LightProjectDescriptor
+import org.jetbrains.kotlin.idea.fir.invalidateCaches
+import org.jetbrains.kotlin.idea.k2.refactoring.introduce.extractFunction.KotlinFirExtractFunctionHandler
+import org.jetbrains.kotlin.idea.refactoring.introduce.AbstractInplaceIntroduceFunctionTest
+import org.jetbrains.kotlin.idea.refactoring.introduce.extractFunction.AbstractExtractKotlinFunctionHandler
+import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
+import org.jetbrains.kotlin.idea.test.runAll
+
+abstract class AbstractK2InplaceIntroduceFunctionTest : AbstractInplaceIntroduceFunctionTest() {
+ override fun isFirPlugin(): Boolean = true
+
+ override fun getExtractFunctionHandler(allContainersEnabled: Boolean): AbstractExtractKotlinFunctionHandler =
+ KotlinFirExtractFunctionHandler(allContainersEnabled)
+
+ override fun tearDown() {
+ runAll(
+ { myFixture.project.invalidateCaches() },
+ { super.tearDown() }
+ )
+ }
+
+ override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.getInstance()
+}
\ No newline at end of file
diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/FirInplaceExtractFunctionTest.kt b/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/FirInplaceExtractFunctionTest.kt
deleted file mode 100644
index 4f999e4ace7c..000000000000
--- a/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/FirInplaceExtractFunctionTest.kt
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
-package org.jetbrains.kotlin.idea.k2.refactoring.introduce
-
-import com.intellij.codeInsight.template.impl.TemplateManagerImpl
-import com.intellij.openapi.application.impl.NonBlockingReadActionImpl
-import com.intellij.util.ui.UIUtil
-import org.jetbrains.kotlin.idea.k2.refactoring.introduce.extractFunction.KotlinFirExtractFunctionHandler
-import org.jetbrains.kotlin.idea.test.IDEA_TEST_DATA_DIR
-import org.jetbrains.kotlin.idea.test.JUnit3RunnerWithInners
-import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
-import org.junit.runner.RunWith
-import com.intellij.java.refactoring.ExtractMethodAndDuplicatesInplaceTest.Companion.nextTemplateVariable
-import com.intellij.java.refactoring.ExtractMethodAndDuplicatesInplaceTest.Companion.renameTemplate
-import com.intellij.testFramework.LightProjectDescriptor
-import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
-import java.io.File
-
-
-@RunWith(JUnit3RunnerWithInners::class)
-class FirInplaceExtractFunctionTest : KotlinLightCodeInsightFixtureTestCase() {
- override fun isFirPlugin(): Boolean = true
-
- override val testDataDirectory = IDEA_TEST_DATA_DIR.resolve("refactoring/extractFunctionInplace")
-
- override fun getProjectDescriptor(): LightProjectDescriptor {
- return KotlinWithJdkAndRuntimeLightProjectDescriptor.getInstance()
- }
-
- fun testStringTemplate() {
- doTest()
- }
-
- fun testEmptySpaces() {
- doTest()
- }
-
- fun testSearchForCallAfter() {
- doTest()
- }
-
- fun testMoveLambdaOutsideParenthesis() {
- doTest()
- }
-
- fun testMoveLambdaOutsideParenthesis1() {
- doTest()
- }
-
- fun testSkipCommentsBefore() {
- doTest()
- }
-
- fun testDontSkipWhitespacesBefore() {
- doTest()
- }
-
- fun testExtractLocal() {
- doTest()
- }
-
- fun testStringTemplateWithNameConflict() {
- doTest(changedName = "substring")
- }
-
- fun testConflictNameNotAccepted() {
- doTest(changedName = "conflict", checkResult = false)
- assertTrue(getActiveTemplate() != null)
- }
-
- fun testConsecutiveDuplicates() {
- doTest(changedName = "renamed")
- }
-
- fun testExposedAssignment() {
- doTest(changedName = "getX")
- }
-
- fun doTest(changedName: String? = null, checkResult: Boolean = true) {
- TemplateManagerImpl.setTemplateTesting(testRootDisposable)
- myFixture.configureByFile("${getTestName(false)}.kt")
- KotlinFirExtractFunctionHandler(getTestName(true).contains("Local")).invoke(myFixture.project, myFixture.editor, myFixture.file, null)
- NonBlockingReadActionImpl.waitForAsyncTaskCompletion()
- val template = getActiveTemplate()
- require(template != null) { "Failed to start refactoring" }
- if (changedName != null) {
- renameTemplate(template, changedName)
- }
- nextTemplateVariable(template)
- UIUtil.dispatchAllInvocationEvents()
- if (checkResult) {
- var expectedFile = "${getTestName(false)}.fir.after.kt"
- if (!File(testDataDirectory, expectedFile).exists()) {
- expectedFile = "${getTestName(false)}.after.kt"
- }
-
- myFixture.checkResultByFile(expectedFile)
- }
- }
-
- private fun getActiveTemplate() = TemplateManagerImpl.getTemplateState(editor)
-}
\ No newline at end of file
diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/K2InplaceIntroduceFunctionTestGenerated.java b/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/K2InplaceIntroduceFunctionTestGenerated.java
new file mode 100644
index 000000000000..6fb4b2c9f539
--- /dev/null
+++ b/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/K2InplaceIntroduceFunctionTestGenerated.java
@@ -0,0 +1,85 @@
+// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+
+package org.jetbrains.kotlin.idea.k2.refactoring.introduce;
+
+import com.intellij.testFramework.TestDataPath;
+import org.jetbrains.kotlin.idea.test.JUnit3RunnerWithInners;
+import org.jetbrains.kotlin.idea.test.KotlinTestUtils;
+import org.jetbrains.kotlin.test.TestMetadata;
+import org.jetbrains.kotlin.idea.base.test.TestRoot;
+import org.junit.runner.RunWith;
+
+/**
+ * This class is generated by {@link org.jetbrains.kotlin.testGenerator.generator.TestGenerator}.
+ * DO NOT MODIFY MANUALLY.
+ */
+@SuppressWarnings("all")
+@TestRoot("refactorings/kotlin.refactorings.tests.k2")
+@TestDataPath("$CONTENT_ROOT")
+@RunWith(JUnit3RunnerWithInners.class)
+@TestMetadata("../../idea/tests/testData/refactoring/extractFunctionInplace")
+public class K2InplaceIntroduceFunctionTestGenerated extends AbstractK2InplaceIntroduceFunctionTest {
+ private void runTest(String testDataFilePath) throws Exception {
+ KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
+ }
+
+ @TestMetadata("ConflictNameNotAccepted.kt")
+ public void testConflictNameNotAccepted() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt");
+ }
+
+ @TestMetadata("ConsecutiveDuplicates.kt")
+ public void testConsecutiveDuplicates() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/ConsecutiveDuplicates.kt");
+ }
+
+ @TestMetadata("DontSkipWhitespacesBefore.kt")
+ public void testDontSkipWhitespacesBefore() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/DontSkipWhitespacesBefore.kt");
+ }
+
+ @TestMetadata("EmptySpaces.kt")
+ public void testEmptySpaces() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/EmptySpaces.kt");
+ }
+
+ @TestMetadata("ExposedAssignment.kt")
+ public void testExposedAssignment() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/ExposedAssignment.kt");
+ }
+
+ @TestMetadata("ExtractLocal.kt")
+ public void testExtractLocal() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/ExtractLocal.kt");
+ }
+
+ @TestMetadata("MoveLambdaOutsideParenthesis.kt")
+ public void testMoveLambdaOutsideParenthesis() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis.kt");
+ }
+
+ @TestMetadata("MoveLambdaOutsideParenthesis1.kt")
+ public void testMoveLambdaOutsideParenthesis1() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/MoveLambdaOutsideParenthesis1.kt");
+ }
+
+ @TestMetadata("SearchForCallAfter.kt")
+ public void testSearchForCallAfter() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/SearchForCallAfter.kt");
+ }
+
+ @TestMetadata("SkipCommentsBefore.kt")
+ public void testSkipCommentsBefore() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/SkipCommentsBefore.kt");
+ }
+
+ @TestMetadata("StringTemplate.kt")
+ public void testStringTemplate() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/StringTemplate.kt");
+ }
+
+ @TestMetadata("StringTemplateWithNameConflict.kt")
+ public void testStringTemplateWithNameConflict() throws Exception {
+ runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/StringTemplateWithNameConflict.kt");
+ }
+}
diff --git a/plugins/kotlin/util/test-generator-fe10/test/org/jetbrains/kotlin/fe10/testGenerator/Fe10GenerateTests.kt b/plugins/kotlin/util/test-generator-fe10/test/org/jetbrains/kotlin/fe10/testGenerator/Fe10GenerateTests.kt
index cb48eb213df4..52a7a7707eee 100644
--- a/plugins/kotlin/util/test-generator-fe10/test/org/jetbrains/kotlin/fe10/testGenerator/Fe10GenerateTests.kt
+++ b/plugins/kotlin/util/test-generator-fe10/test/org/jetbrains/kotlin/fe10/testGenerator/Fe10GenerateTests.kt
@@ -107,6 +107,7 @@ import org.jetbrains.kotlin.idea.refactoring.inline.AbstractInlineMultiFileTest
import org.jetbrains.kotlin.idea.refactoring.inline.AbstractInlineTest
import org.jetbrains.kotlin.idea.refactoring.inline.AbstractInlineTestWithSomeDescriptors
import org.jetbrains.kotlin.idea.refactoring.introduce.AbstractExtractionTest
+import org.jetbrains.kotlin.idea.refactoring.introduce.AbstractInplaceIntroduceFunctionTest
import org.jetbrains.kotlin.idea.refactoring.move.AbstractK1MultiModuleMoveTest
import org.jetbrains.kotlin.idea.refactoring.move.AbstractMoveTest
import org.jetbrains.kotlin.idea.refactoring.pullUp.AbstractPullUpTest
@@ -1150,7 +1151,7 @@ private fun assembleWorkspace(): TWorkspace = workspace {
testGroup("idea/tests", category = EXTRACT_REFACTORING) {
testClass {
model("refactoring/introduceVariable", pattern = KT_OR_KTS_WITHOUT_DOTS, testMethodName = "doIntroduceVariableTest")
- model("refactoring/extractFunction", pattern = KT_OR_KTS, testMethodName = "doExtractFunctionTest", excludedDirectories = listOf("inplace"))
+ model("refactoring/extractFunction", pattern = KT_OR_KTS, testMethodName = "doExtractFunctionTest")
model("refactoring/introduceProperty", pattern = KT_OR_KTS, testMethodName = "doIntroducePropertyTest")
model("refactoring/introduceParameter", pattern = KT_OR_KTS, testMethodName = "doIntroduceSimpleParameterTest")
model("refactoring/introduceLambdaParameter", pattern = KT_OR_KTS, testMethodName = "doIntroduceLambdaParameterTest")
@@ -1161,6 +1162,9 @@ private fun assembleWorkspace(): TWorkspace = workspace {
model("refactoring/extractSuperclass", pattern = KT_OR_KTS_WITHOUT_DOTS, testMethodName = "doExtractSuperclassTest")
model("refactoring/extractInterface", pattern = KT_OR_KTS_WITHOUT_DOTS, testMethodName = "doExtractInterfaceTest")
}
+ testClass {
+ model("refactoring/extractFunctionInplace")
+ }
}
testGroup("scripting-support", category = SCRIPTS) {
diff --git a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/GenerateK2RefactoringsTests.kt b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/GenerateK2RefactoringsTests.kt
index 0f5bd1fc6729..92940f9739b5 100644
--- a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/GenerateK2RefactoringsTests.kt
+++ b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/GenerateK2RefactoringsTests.kt
@@ -6,6 +6,7 @@ import org.jetbrains.kotlin.idea.k2.refactoring.bindToElement.AbstractK2BindToFq
import org.jetbrains.kotlin.idea.k2.refactoring.copy.AbstractK2CopyTest
import org.jetbrains.kotlin.idea.k2.refactoring.copy.AbstractK2MultiModuleCopyTest
import org.jetbrains.kotlin.idea.k2.refactoring.inline.AbstractKotlinFirInlineTest
+import org.jetbrains.kotlin.idea.k2.refactoring.introduce.AbstractK2InplaceIntroduceFunctionTest
import org.jetbrains.kotlin.idea.k2.refactoring.introduce.AbstractK2IntroduceConstantTest
import org.jetbrains.kotlin.idea.k2.refactoring.introduce.AbstractK2PsiUnifierTest
import org.jetbrains.kotlin.idea.k2.refactoring.introduce.introduceVariable.AbstractK2IntroduceVariableTest
@@ -85,6 +86,10 @@ internal fun MutableTWorkspace.generateK2RefactoringsTests() {
model("refactoring/extractFunction", pattern = Patterns.KT_OR_KTS, testMethodName = "doExtractFunctionTest")
}
+ testClass {
+ model("refactoring/extractFunctionInplace")
+ }
+
testClass {
model("refactoring/introduceParameter", pattern = Patterns.KT_OR_KTS, testMethodName = "doIntroduceParameterTest")
}