Create actual: do not generate default parameter values

So #KT-23105 Fixed
This commit is contained in:
Mikhail Glukhikh
2018-06-27 16:30:14 +03:00
parent b13e4535f5
commit 16c6d63b10
10 changed files with 54 additions and 0 deletions
@@ -259,6 +259,9 @@ internal fun KtPsiFactory.generateClassOrObjectByExpectedClass(
it.delete()
} else {
it.addModifier(KtTokens.ACTUAL_KEYWORD)
if (it is KtFunction) {
it.removeParameterDefaultValues()
}
}
}
}
@@ -343,6 +346,17 @@ private fun KtPsiFactory.generateFunction(
if (returnType != null && KotlinBuiltIns.isUnit(returnType)) {
typeReference = null
}
removeParameterDefaultValues()
}
}
private fun KtFunction.removeParameterDefaultValues() {
for (valueParameter in valueParameters) {
val defaultValue = valueParameter.defaultValue
if (defaultValue != null) {
val equalsToken = valueParameter.equalsToken
valueParameter.deleteChildRange(equalsToken, defaultValue)
}
}
}
@@ -0,0 +1,5 @@
// "Create actual interface for module testModule_JVM (JVM)" "true"
expect interface <caret>I {
fun f(p: Int = 1)
}
@@ -0,0 +1,5 @@
// "Create actual interface for module testModule_JVM (JVM)" "true"
expect interface I {
fun f(p: Int = 1)
}
@@ -0,0 +1 @@
// to be created
@@ -0,0 +1,4 @@
// to be created
actual interface I {
actual fun f(p: Int)
}
@@ -0,0 +1,5 @@
// "Create actual class for module testModule_JVM (JVM)" "true"
expect class <caret>C {
fun f(p: Int = 1)
}
@@ -0,0 +1,5 @@
// "Create actual class for module testModule_JVM (JVM)" "true"
expect class C {
fun f(p: Int = 1)
}
@@ -0,0 +1 @@
// to be created
@@ -0,0 +1,4 @@
// to be created
actual class C {
actual fun f(p: Int) {}
}
@@ -129,6 +129,16 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
runTest("idea/testData/multiModuleQuickFix/createVarInExpectClass/");
}
@TestMetadata("defaultParameterInExpected")
public void testDefaultParameterInExpected() throws Exception {
runTest("idea/testData/multiModuleQuickFix/defaultParameterInExpected/");
}
@TestMetadata("defaultParameterInExpectedClass")
public void testDefaultParameterInExpectedClass() throws Exception {
runTest("idea/testData/multiModuleQuickFix/defaultParameterInExpectedClass/");
}
@TestMetadata("deprecatedHeader")
public void testDeprecatedHeader() throws Exception {
runTest("idea/testData/multiModuleQuickFix/deprecatedHeader/");