Extract property: do not add unnecessary extension receiver

#KT-24615 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-10-11 15:13:22 +09:00
committed by igoriakovlev
parent 0fe5694cb7
commit 4b5f3b7a94
4 changed files with 32 additions and 0 deletions
@@ -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)
@@ -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 <selection>2 + 3 + i</selection>
}
}
@@ -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
}
}
@@ -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");