Convert to primary constructor preserves accessors #KT-17996 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
4346fb5c23
commit
b206f6288d
+3
-1
@@ -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)
|
||||
|
||||
+14
@@ -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
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun log(s: String) {
|
||||
}
|
||||
|
||||
class A(x: String) {
|
||||
var x: String = x
|
||||
get() {
|
||||
log(field)
|
||||
return field
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -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
|
||||
}
|
||||
}
|
||||
+11
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user