Fix "Create expect function" for primary constructor
#KT-31518 Fixed
This commit is contained in:
+6
-1
@@ -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()
|
||||
+5
@@ -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/");
|
||||
|
||||
Reference in New Issue
Block a user