Add actual: handle parameters with val/var as compatible with property

So #KT-23762 Fixed
This commit is contained in:
Mikhail Glukhikh
2018-06-27 19:15:13 +03:00
parent dd0b267531
commit 0fb183e302
7 changed files with 34 additions and 1 deletions
@@ -48,7 +48,9 @@ class AddActualFix(
val factory = KtPsiFactory(element)
val pureActualClass = factory.generateClassOrObjectByExpectedClass(
project, expectedClass, actualNeeded = true,
existingDeclarations = element.declarations + listOfNotNull(element.primaryConstructor)
existingDeclarations = element.declarations +
element.primaryConstructor?.valueParameters?.filter { it.hasValOrVar() }.orEmpty() +
listOfNotNull(element.primaryConstructor)
)
for (declaration in pureActualClass.declarations) {
element.addDeclaration(declaration)
@@ -230,6 +230,7 @@ internal fun KtPsiFactory.generateClassOrObjectByExpectedClass(
name == it.name && when (this) {
is KtConstructor<*> -> it is KtConstructor<*> && areCompatible(this, it)
is KtNamedFunction -> it is KtNamedFunction && areCompatible(this, it)
is KtProperty -> it is KtProperty || it is KtParameter && it.hasValOrVar()
else -> this.javaClass == it.javaClass
}
}
@@ -0,0 +1,7 @@
// DISABLE-ERRORS
expect class My {
val name: String
val age: String
}
@@ -0,0 +1,7 @@
// DISABLE-ERRORS
expect class My {
val name: String
val age: String
}
@@ -0,0 +1,4 @@
// "Add missing actual members" "true"
// DISABLE-ERRORS
actual class <caret>My(actual val name: String)
@@ -0,0 +1,7 @@
// "Add missing actual members" "true"
// DISABLE-ERRORS
actual class <caret>My(actual val name: String) {
actual val age: String
get() = TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -99,6 +99,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
runTest("idea/testData/multiModuleQuickFix/classOverloadedFunction/");
}
@TestMetadata("classPropertyInConstructor")
public void testClassPropertyInConstructor() throws Exception {
runTest("idea/testData/multiModuleQuickFix/classPropertyInConstructor/");
}
@TestMetadata("classSomeProperties")
public void testClassSomeProperties() throws Exception {
runTest("idea/testData/multiModuleQuickFix/classSomeProperties/");