Fix "Create expect function" for primary constructor

#KT-31518 Fixed
This commit is contained in:
Dmitry Gridin
2019-05-21 10:42:23 +07:00
parent b575ed390a
commit 47e3a26749
6 changed files with 21 additions and 1 deletions
@@ -77,7 +77,12 @@ abstract class AbstractCreateDeclarationFix<D : KtNamedDeclaration>(
}
}
val generatedDeclaration = when {
targetClass != null -> targetClass.addDeclaration(generated as KtNamedDeclaration)
targetClass != null -> {
if (generated is KtPrimaryConstructor && targetClass is KtClass)
targetClass.createPrimaryConstructorIfAbsent().replace(generated)
else
targetClass.addDeclaration(generated as KtNamedDeclaration)
}
else -> targetFile.add(generated) as KtElement
}
val reformatted = CodeStyleManager.getInstance(project).reformat(generatedDeclaration)
@@ -0,0 +1 @@
expect class <caret>A()
@@ -0,0 +1 @@
expect class A
@@ -0,0 +1,4 @@
// "Create expected class in common module testModule_Common" "true"
// DISABLE-ERRORS
actual class A actual constructor()
@@ -0,0 +1,4 @@
// "Create expected function in common module testModule_Common" "true"
// DISABLE-ERRORS
actual class A actual <caret>constructor()
@@ -434,6 +434,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
runTest("idea/testData/multiModuleQuickFix/expectNestedClass/");
}
@TestMetadata("expectPrimaryConstructor")
public void testExpectPrimaryConstructor() throws Exception {
runTest("idea/testData/multiModuleQuickFix/expectPrimaryConstructor/");
}
@TestMetadata("expectProperty")
public void testExpectProperty() throws Exception {
runTest("idea/testData/multiModuleQuickFix/expectProperty/");