diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt index ef8626af25f..9e2b06074df 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt @@ -668,6 +668,12 @@ fun ExtractionGeneratorConfiguration.generateDeclaration( } } + if (declaration is KtProperty && declaration.isExtensionDeclaration() && !declaration.isTopLevel) { + val receiverTypeReference = (declaration as? KtCallableDeclaration)?.receiverTypeReference + receiverTypeReference?.siblings(withItself = false)?.firstOrNull { it.node.elementType == KtTokens.DOT }?.delete() + receiverTypeReference?.delete() + } + CodeStyleManager.getInstance(descriptor.extractionData.project).reformat(declaration) return ExtractionResult(this, declaration, duplicateReplacers) diff --git a/idea/testData/refactoring/introduceProperty/kt24615.kt b/idea/testData/refactoring/introduceProperty/kt24615.kt new file mode 100644 index 00000000000..28624b96a1c --- /dev/null +++ b/idea/testData/refactoring/introduceProperty/kt24615.kt @@ -0,0 +1,9 @@ +// EXTRACTION_TARGET: property with getter + +open class Base(protected val i: Int) + +class Impl(i: Int) : Base(i) { + fun foo(): Int { + return 2 + 3 + i + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/introduceProperty/kt24615.kt.after b/idea/testData/refactoring/introduceProperty/kt24615.kt.after new file mode 100644 index 00000000000..faeb1eba715 --- /dev/null +++ b/idea/testData/refactoring/introduceProperty/kt24615.kt.after @@ -0,0 +1,12 @@ +// EXTRACTION_TARGET: property with getter + +open class Base(protected val i: Int) + +class Impl(i: Int) : Base(i) { + private val i: Int + get() = 2 + 3 + i + + fun foo(): Int { + return i + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java index 1cf9bf43a24..5ee5a5322b6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java @@ -2927,6 +2927,11 @@ public class ExtractionTestGenerated extends AbstractExtractionTest { runTest("idea/testData/refactoring/introduceProperty/kt21530.kt"); } + @TestMetadata("kt24615.kt") + public void testKt24615() throws Exception { + runTest("idea/testData/refactoring/introduceProperty/kt24615.kt"); + } + @TestMetadata("primaryConstructorParameterReference.kt") public void testPrimaryConstructorParameterReference() throws Exception { runTest("idea/testData/refactoring/introduceProperty/primaryConstructorParameterReference.kt");