[kotlin] Extract variable: choose class body as container when introducing class property and replacing all occurrences

^KTIJ-9043 Fixed
^KTIJ-14455 Fixed

GitOrigin-RevId: cabc4ee5ad81253f9f51dedfe072a54c9b18923a
This commit is contained in:
Andrey Cherkasov
2024-10-03 18:03:51 +00:00
committed by intellij-monorepo-bot
parent e75f89a4f7
commit bda0682dc8
7 changed files with 41 additions and 1 deletions
@@ -872,6 +872,16 @@ public abstract class ExtractionTestGenerated extends AbstractExtractionTest {
runTest("testData/refactoring/introduceVariable/javaInnerClassQualifier.kt");
}
@TestMetadata("KTIJ-14455.kt")
public void testKTIJ_14455() throws Exception {
runTest("testData/refactoring/introduceVariable/KTIJ-14455.kt");
}
@TestMetadata("KTIJ-9043.kt")
public void testKTIJ_9043() throws Exception {
runTest("testData/refactoring/introduceVariable/KTIJ-9043.kt");
}
@TestMetadata("kt10808.kt")
public void testKt10808() throws Exception {
runTest("testData/refactoring/introduceVariable/kt10808.kt");
@@ -0,0 +1,5 @@
class X {
val s0 = ""
val s1 = <selection>s0.substring(0)</selection>
val s2 = s0.substring(0)
}
@@ -0,0 +1,6 @@
class X {
val s0 = ""
val substring = s0.substring(0)
val s1 = substring
val s2 = substring
}
@@ -0,0 +1,4 @@
class Foo {
val bar = <selection>0</selection>
val baz = 0
}
@@ -0,0 +1,5 @@
class Foo {
val i = 0
val bar = i
val baz = i
}
@@ -217,7 +217,7 @@ abstract class KotlinIntroduceVariableHandler : RefactoringActionHandler {
}
fun KtElement.getContainer(): KtElement? {
if (this is KtBlockExpression) return this
if (this is KtBlockExpression || this is KtClassBody) return this
return (parentsWithSelf.zip(parents)).firstOrNull {
val (place, parent) = it
@@ -870,6 +870,16 @@ public abstract class K2IntroduceVariableTestGenerated extends AbstractK2Introdu
runTest("../../idea/tests/testData/refactoring/introduceVariable/javaInnerClassQualifier.kt");
}
@TestMetadata("KTIJ-14455.kt")
public void testKTIJ_14455() throws Exception {
runTest("../../idea/tests/testData/refactoring/introduceVariable/KTIJ-14455.kt");
}
@TestMetadata("KTIJ-9043.kt")
public void testKTIJ_9043() throws Exception {
runTest("../../idea/tests/testData/refactoring/introduceVariable/KTIJ-9043.kt");
}
@TestMetadata("kt10808.kt")
public void testKt10808() throws Exception {
runTest("../../idea/tests/testData/refactoring/introduceVariable/kt10808.kt");