Convert to primary constructor preserves accessors #KT-17996 Fixed

This commit is contained in:
Dmitry Neverov
2017-05-29 07:34:09 +03:00
committed by Mikhail Glukhikh
parent 4346fb5c23
commit b206f6288d
6 changed files with 65 additions and 1 deletions
@@ -128,7 +128,9 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio
if (parameterDescriptor != null && propertyDescriptor != null) {
val property = DescriptorToSourceUtils.descriptorToDeclaration(propertyDescriptor) as? KtProperty
if (property != null) {
if (propertyDescriptor.name == parameterDescriptor.name && propertyDescriptor.type == parameterDescriptor.type) {
if (propertyDescriptor.name == parameterDescriptor.name &&
propertyDescriptor.type == parameterDescriptor.type &&
propertyDescriptor.accessors.all { it.isDefault }) {
propertyCommentSaver = CommentSaver(property)
val valOrVar = if (property.isVar) factory.createVarKeyword() else factory.createValKeyword()
newParameter.addBefore(valOrVar, newParameter.nameIdentifier)
@@ -0,0 +1,14 @@
fun log(s: String) {
}
class A {
var x: String
get() {
log(field)
return field
}
<caret>constructor(x: String) {
this.x = x
}
}
@@ -0,0 +1,11 @@
fun log(s: String) {
}
class A(x: String) {
var x: String = x
get() {
log(field)
return field
}
}
@@ -0,0 +1,14 @@
fun log(s: String) {
}
class A {
var x: String
set(value) {
log(value)
field = value
}
<caret>constructor(x: String) {
this.x = x
}
}
@@ -0,0 +1,11 @@
fun log(s: String) {
}
class A(x: String) {
var x: String = x
set(value) {
log(value)
field = value
}
}
@@ -5867,6 +5867,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("propertyWithGetter.kt")
public void testPropertyWithGetter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/propertyWithGetter.kt");
doTest(fileName);
}
@TestMetadata("propertyWithSetter.kt")
public void testPropertyWithSetter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/propertyWithSetter.kt");
doTest(fileName);
}
@TestMetadata("protectedConstructor.kt")
public void testProtectedConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertSecondaryConstructorToPrimary/protectedConstructor.kt");