Extract property: do not add unnecessary extension receiver
#KT-24615 Fixed
This commit is contained in:
committed by
igoriakovlev
parent
0fe5694cb7
commit
4b5f3b7a94
+6
@@ -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)
|
CodeStyleManager.getInstance(descriptor.extractionData.project).reformat(declaration)
|
||||||
|
|
||||||
return ExtractionResult(this, declaration, duplicateReplacers)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -2927,6 +2927,11 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
|||||||
runTest("idea/testData/refactoring/introduceProperty/kt21530.kt");
|
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")
|
@TestMetadata("primaryConstructorParameterReference.kt")
|
||||||
public void testPrimaryConstructorParameterReference() throws Exception {
|
public void testPrimaryConstructorParameterReference() throws Exception {
|
||||||
runTest("idea/testData/refactoring/introduceProperty/primaryConstructorParameterReference.kt");
|
runTest("idea/testData/refactoring/introduceProperty/primaryConstructorParameterReference.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user