Create from Usage: Always insert parentheses around secondary constructor parameter list

#KT-10912 Fixed
This commit is contained in:
Alexey Sedunov
2016-02-05 16:12:45 +03:00
parent 8e81d0ce5f
commit cc2a65e874
4 changed files with 22 additions and 1 deletions
@@ -436,7 +436,9 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
fun renderParamList(): String {
val prefix = if (classKind == ClassKind.ANNOTATION_CLASS) "val " else ""
val list = callableInfo.parameterInfos.indices.map { i -> "${prefix}p$i: Any" }.joinToString(", ")
return if (callableInfo.parameterInfos.isNotEmpty() || callableInfo.kind == CallableKind.FUNCTION) "($list)" else list
return if (callableInfo.parameterInfos.isNotEmpty()
|| callableInfo.kind == CallableKind.FUNCTION
|| callableInfo.kind == CallableKind.SECONDARY_CONSTRUCTOR) "($list)" else list
}
val paramList = when (callableInfo.kind) {
@@ -0,0 +1,4 @@
// "Create secondary constructor" "true"
// ERROR: Primary constructor call expected
class Creation(val f: Int)
val v = Creation(<caret>)
@@ -0,0 +1,9 @@
// "Create secondary constructor" "true"
// ERROR: Primary constructor call expected
class Creation(val f: Int) {
constructor() {
//To change body of created constructors use File | Settings | File Templates.
}
}
val v = Creation()
@@ -2601,6 +2601,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("noParameters.kt")
public void testNoParameters() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createSecondaryConstructor/noParameters.kt");
doTest(fileName);
}
@TestMetadata("superCall.kt")
public void testSuperCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createSecondaryConstructor/superCall.kt");