Implement members: fix it works correctly if primary constructor has implemented member
#KT-37312 Fixed
This commit is contained in:
committed by
Ilya Kirillov
parent
5eabc1117f
commit
e455e926aa
+2
-1
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.prevSiblingOfSameType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
@@ -147,7 +148,7 @@ abstract class OverrideImplementMembersHandler : LanguageCodeInsightActionHandle
|
||||
fun ClassDescriptor.findElement(memberDescriptor: CallableMemberDescriptor): KtDeclaration? {
|
||||
return implementedElements[memberDescriptor]
|
||||
?: (findCallableMemberBySignature(memberDescriptor)?.source?.getPsi() as? KtDeclaration)
|
||||
?.takeIf { it != classOrObject }
|
||||
?.takeIf { it != classOrObject && it !is KtParameter }
|
||||
?.also { implementedElements[memberDescriptor] = it }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Implement members" "true"
|
||||
// WITH_RUNTIME
|
||||
abstract class B {
|
||||
abstract val p: String?
|
||||
abstract fun test()
|
||||
}
|
||||
|
||||
<caret>class MyImpl(
|
||||
override val p: String? = null
|
||||
) : B()
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Implement members" "true"
|
||||
// WITH_RUNTIME
|
||||
abstract class B {
|
||||
abstract val p: String?
|
||||
abstract fun test()
|
||||
}
|
||||
|
||||
class MyImpl(
|
||||
override val p: String? = null
|
||||
) : B() {
|
||||
override fun test() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Implement members" "true"
|
||||
// WITH_RUNTIME
|
||||
abstract class B {
|
||||
abstract val p: String?
|
||||
abstract fun test()
|
||||
}
|
||||
|
||||
<caret>class MyImpl2(
|
||||
override val p: String? = null
|
||||
) : B() {
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Implement members" "true"
|
||||
// WITH_RUNTIME
|
||||
abstract class B {
|
||||
abstract val p: String?
|
||||
abstract fun test()
|
||||
}
|
||||
|
||||
class MyImpl2(
|
||||
override val p: String? = null
|
||||
) : B() {
|
||||
override fun test() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Implement members" "true"
|
||||
// WITH_RUNTIME
|
||||
abstract class C {
|
||||
abstract val p: String?
|
||||
abstract val q: Int
|
||||
abstract fun test()
|
||||
}
|
||||
|
||||
<caret>class MyImpl3(
|
||||
override val p: String? = null
|
||||
) : C() {
|
||||
override val q: Int = 0
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Implement members" "true"
|
||||
// WITH_RUNTIME
|
||||
abstract class C {
|
||||
abstract val p: String?
|
||||
abstract val q: Int
|
||||
abstract fun test()
|
||||
}
|
||||
|
||||
class MyImpl3(
|
||||
override val p: String? = null
|
||||
) : C() {
|
||||
override val q: Int = 0
|
||||
override fun test() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
@@ -7714,6 +7714,21 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
runTest("idea/testData/quickfix/implement/finalClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("hasImplementedInPrimaryConstructor.kt")
|
||||
public void testHasImplementedInPrimaryConstructor() throws Exception {
|
||||
runTest("idea/testData/quickfix/implement/hasImplementedInPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("hasImplementedInPrimaryConstructor2.kt")
|
||||
public void testHasImplementedInPrimaryConstructor2() throws Exception {
|
||||
runTest("idea/testData/quickfix/implement/hasImplementedInPrimaryConstructor2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("hasImplementedInPrimaryConstructor3.kt")
|
||||
public void testHasImplementedInPrimaryConstructor3() throws Exception {
|
||||
runTest("idea/testData/quickfix/implement/hasImplementedInPrimaryConstructor3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inCompanion.kt")
|
||||
public void testInCompanion() throws Exception {
|
||||
runTest("idea/testData/quickfix/implement/inCompanion.kt");
|
||||
|
||||
Reference in New Issue
Block a user