Create actual fix: handle companions correctly #KT-21114 Fixed

This commit is contained in:
Mikhail Glukhikh
2017-12-29 20:06:44 +03:00
parent f46fa263ef
commit 5abb9dd23e
7 changed files with 48 additions and 2 deletions
@@ -179,7 +179,11 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m
}
fun createCompanionObject(): KtObjectDeclaration {
return createClass("class A {\n companion object{\n}\n}").companionObjects.first()
return createCompanionObject("companion object {\n}")
}
fun createCompanionObject(text: String): KtObjectDeclaration {
return createClass("class A {\n $text\n}").companionObjects.first()
}
fun createFileAnnotation(annotationText: String): KtAnnotationEntry {
@@ -225,7 +225,15 @@ internal fun KtPsiFactory.generateClassOrObjectByExpectedClass(
}
val expectedText = expectedClass.text
val actualClass = if (expectedClass is KtObjectDeclaration) createObject(expectedText) else createClass(expectedText)
val actualClass = if (expectedClass is KtObjectDeclaration) {
if (expectedClass.isCompanion()) {
createCompanionObject(expectedText)
} else {
createObject(expectedText)
}
} else {
createClass(expectedText)
}
val isInterface = expectedClass is KtClass && expectedClass.isInterface()
actualClass.declarations.forEach {
if (it.exists()) {
@@ -0,0 +1,7 @@
// DISABLE-ERRORS
expect class WithCompanion {
companion object {
fun foo()
}
}
@@ -0,0 +1,7 @@
// DISABLE-ERRORS
expect class WithCompanion {
companion object {
fun foo()
}
}
@@ -0,0 +1,6 @@
// "Add missing actual members" "true"
// DISABLE-ERRORS
actual class <caret>WithCompanion {
}
@@ -0,0 +1,9 @@
// "Add missing actual members" "true"
// DISABLE-ERRORS
actual class WithCompanion {
actual companion object {
actual fun foo() {}
}
}
@@ -74,6 +74,11 @@ class QuickFixMultiModuleTest : AbstractQuickFixMultiModuleTest() {
doMultiPlatformTest()
}
@Test
fun testCompanionAbsence() {
doMultiPlatformTest()
}
@Test
fun testDeprecatedHeader() {
doMultiPlatformTest()