Primary constructor to secondary: always try to build constructor body #KT-14475 Fixed
This commit is contained in:
+3
-3
@@ -89,7 +89,6 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
|||||||
superTypeEntry.replace(factory.createSuperTypeEntry(superTypeEntry.typeReference!!.text))
|
superTypeEntry.replace(factory.createSuperTypeEntry(superTypeEntry.typeReference!!.text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (element.valueParameters.firstOrNull { it.hasValOrVar() } != null || initializerMap.isNotEmpty()) {
|
|
||||||
val valueParameterInitializers = element.valueParameters.filter { it.hasValOrVar() }.joinToString(separator = "\n") {
|
val valueParameterInitializers = element.valueParameters.filter { it.hasValOrVar() }.joinToString(separator = "\n") {
|
||||||
val name = it.name!!
|
val name = it.name!!
|
||||||
"this.$name = $name"
|
"this.$name = $name"
|
||||||
@@ -113,8 +112,9 @@ class ConvertPrimaryConstructorToSecondaryIntention : SelfTargetingIntention<KtP
|
|||||||
} ?: ""
|
} ?: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blockBody(listOf(valueParameterInitializers, classBodyInitializers)
|
val allInitializers = listOf(valueParameterInitializers, classBodyInitializers).filter(String::isNotEmpty)
|
||||||
.filter(String::isNotEmpty).joinToString(separator = "\n"))
|
if (allInitializers.isNotEmpty()) {
|
||||||
|
blockBody(allInitializers.joinToString(separator = "\n"))
|
||||||
}
|
}
|
||||||
}.asString()
|
}.asString()
|
||||||
)
|
)
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fun println(arg: Int) = arg
|
||||||
|
|
||||||
|
class My<caret>() {
|
||||||
|
val x = 1
|
||||||
|
|
||||||
|
val y = 2
|
||||||
|
|
||||||
|
init {
|
||||||
|
println(x)
|
||||||
|
println(y)
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+13
@@ -0,0 +1,13 @@
|
|||||||
|
fun println(arg: Int) = arg
|
||||||
|
|
||||||
|
class My {
|
||||||
|
constructor() {
|
||||||
|
println(x)
|
||||||
|
println(y)
|
||||||
|
}
|
||||||
|
|
||||||
|
val x: Int = 1
|
||||||
|
|
||||||
|
val y: Int = 2
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4537,6 +4537,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("initWithoutAssignments.kt")
|
||||||
|
public void testInitWithoutAssignments() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPrimaryConstructorToSecondary/initWithoutAssignments.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("paramsAndProperties.kt")
|
@TestMetadata("paramsAndProperties.kt")
|
||||||
public void testParamsAndProperties() throws Exception {
|
public void testParamsAndProperties() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPrimaryConstructorToSecondary/paramsAndProperties.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertPrimaryConstructorToSecondary/paramsAndProperties.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user