Initialize Property with Constructor Parameter Quick-Fix: Skip secondary constructors with this-delegation. Use containing class as a Change Signature context
#KT-10818 Fixed
This commit is contained in:
@@ -159,7 +159,7 @@ object InitializePropertyQuickFixFactory : KotlinIntentionActionsFactory() {
|
||||
val descriptor = descriptorsToProcess.next()
|
||||
val constructorPointer = descriptor.source.getPsi()?.createSmartPointer()
|
||||
val config = configureChangeSignature(propertyDescriptor)
|
||||
val changeSignature = { runChangeSignature(project, descriptor, config, element, text) }
|
||||
val changeSignature = { runChangeSignature(project, descriptor, config, element.containingClassOrObject!!, text) }
|
||||
|
||||
changeSignature.runRefactoringWithPostprocessing(project, "refactoring.changeSignature") {
|
||||
val constructorOrClass = constructorPointer?.element
|
||||
@@ -186,7 +186,10 @@ object InitializePropertyQuickFixFactory : KotlinIntentionActionsFactory() {
|
||||
listOf(classDescriptor.unsubstitutedPrimaryConstructor!!)
|
||||
}
|
||||
else {
|
||||
classDescriptor.secondaryConstructors
|
||||
classDescriptor.secondaryConstructors.filter {
|
||||
val constructor = it.source.getPsi() as? KtSecondaryConstructor
|
||||
constructor != null && !constructor.getDelegationCall().isCallToThis
|
||||
}
|
||||
}
|
||||
|
||||
project.runWithElementsToShortenIsEmptyIgnored {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Initialize with constructor parameter" "true"
|
||||
open class RGrandAccessor(x: Int) {}
|
||||
|
||||
open class RAccessor : RGrandAccessor {
|
||||
<caret>val f: Int
|
||||
constructor(p: Boolean) : super(1)
|
||||
constructor(p: String) : this(true)
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// "Initialize with constructor parameter" "true"
|
||||
open class RGrandAccessor(x: Int) {}
|
||||
|
||||
open class RAccessor : RGrandAccessor {
|
||||
<caret>val f: Int
|
||||
constructor(p: Boolean, f: Int) : super(1) {
|
||||
this.f = f
|
||||
}
|
||||
|
||||
constructor(p: String) : this(true, 0)
|
||||
}
|
||||
@@ -4442,6 +4442,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/initializeWithConstructorParameter"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("constructorWithThisDelegation.kt")
|
||||
public void testConstructorWithThisDelegation() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/initializeWithConstructorParameter/constructorWithThisDelegation.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("localVar.kt")
|
||||
public void testLocalVar() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/initializeWithConstructorParameter/localVar.kt");
|
||||
|
||||
Reference in New Issue
Block a user