Implement members: fix it works correctly for data class

#KT-36686 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-02-22 10:20:33 +09:00
committed by Vladimir Dolzhenko
parent fe009ac695
commit 62e335ac88
8 changed files with 75 additions and 3 deletions
@@ -146,9 +146,9 @@ abstract class OverrideImplementMembersHandler : LanguageCodeInsightActionHandle
fun ClassDescriptor.findElement(memberDescriptor: CallableMemberDescriptor): KtDeclaration? {
return implementedElements[memberDescriptor]
?: (findCallableMemberBySignature(memberDescriptor)?.source?.getPsi() as? KtDeclaration)?.also {
implementedElements[memberDescriptor] = it
}
?: (findCallableMemberBySignature(memberDescriptor)?.source?.getPsi() as? KtDeclaration)
?.takeIf { it != classOrObject }
?.also { implementedElements[memberDescriptor] = it }
}
fun getAnchor(selectedElement: KtDeclaration): PsiElement? {
+7
View File
@@ -0,0 +1,7 @@
// "Implement members" "true"
// WITH_RUNTIME
interface I {
fun foo()
}
data <caret>class C(val i: Int) : I
+11
View File
@@ -0,0 +1,11 @@
// "Implement members" "true"
// WITH_RUNTIME
interface I {
fun foo()
}
data class C(val i: Int) : I {
override fun foo() {
TODO("Not yet implemented")
}
}
+7
View File
@@ -0,0 +1,7 @@
// "Implement members" "true"
// WITH_RUNTIME
interface I {
fun foo()
}
data <caret>class C(val i: Int) : I {}
+11
View File
@@ -0,0 +1,11 @@
// "Implement members" "true"
// WITH_RUNTIME
interface I {
fun foo()
}
data class C(val i: Int) : I {
override fun foo() {
TODO("Not yet implemented")
}
}
+9
View File
@@ -0,0 +1,9 @@
// "Implement members" "true"
// WITH_RUNTIME
interface I {
fun foo()
}
data <caret>class C(val i: Int) : I {
fun bar() {}
}
+12
View File
@@ -0,0 +1,12 @@
// "Implement members" "true"
// WITH_RUNTIME
interface I {
fun foo()
}
data class C(val i: Int) : I {
fun bar() {}
override fun foo() {
TODO("Not yet implemented")
}
}
@@ -7669,6 +7669,21 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/implement/annotation.kt");
}
@TestMetadata("dataClass.kt")
public void testDataClass() throws Exception {
runTest("idea/testData/quickfix/implement/dataClass.kt");
}
@TestMetadata("dataClass2.kt")
public void testDataClass2() throws Exception {
runTest("idea/testData/quickfix/implement/dataClass2.kt");
}
@TestMetadata("dataClass3.kt")
public void testDataClass3() throws Exception {
runTest("idea/testData/quickfix/implement/dataClass3.kt");
}
@TestMetadata("doNotAddExpectForVal.kt")
public void testDoNotAddExpectForVal() throws Exception {
runTest("idea/testData/quickfix/implement/doNotAddExpectForVal.kt");