diff --git a/ChangeLog.md b/ChangeLog.md index e967f37805c..eef7eabedf5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -207,6 +207,7 @@ - [`KT-12284`](https://youtrack.jetbrains.com/issue/KT-12284) Too wide applicability range for "Add braces to else" intention - [`KT-11975`](https://youtrack.jetbrains.com/issue/KT-11975) "Invert if-condition" intention does not simplify `is` expression - [`KT-12437`](https://youtrack.jetbrains.com/issue/KT-12437) "Replace explicit parameter" intention is suggested for parameter of inner lambda in presence of `it` from outer lambda +- [`KT-12290`](https://youtrack.jetbrains.com/issue/KT-12290) Navigate to the generated declaration when using "Implement abstract member" intention - [`KT-12376`](https://youtrack.jetbrains.com/issue/KT-12376) Don't show "Package directive doesn't match file location" in injected code - [`KT-12777`](https://youtrack.jetbrains.com/issue/KT-12777) Fix exception in "Create class" quickfix applied to unresolved references in type arguments diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt index 34fb2536d70..8e1582611a0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ImplementAbstractMemberIntention.kt @@ -24,6 +24,8 @@ import com.intellij.ide.util.PsiElementListCellRenderer import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.Editor +import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.fileEditor.OpenFileDescriptor import com.intellij.openapi.ui.popup.PopupChooserBuilder import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiClass @@ -126,7 +128,7 @@ abstract class ImplementAbstractMemberIntentionBase : protected abstract val preferConstructorParameters: Boolean - private fun implementInKotlinClass(member: KtNamedDeclaration, targetClass: KtClassOrObject) { + private fun implementInKotlinClass(editor: Editor?, member: KtNamedDeclaration, targetClass: KtClassOrObject) { val subClassDescriptor = targetClass.resolveToDescriptorIfAny() as? ClassDescriptor ?: return val superMemberDescriptor = member.resolveToDescriptorIfAny() as? CallableMemberDescriptor ?: return val superClassDescriptor = superMemberDescriptor.containingDeclaration as? ClassDescriptor ?: return @@ -138,7 +140,7 @@ abstract class ImplementAbstractMemberIntentionBase : descriptorToImplement, OverrideMemberChooserObject.BodyType.EMPTY, preferConstructorParameters) - OverrideImplementMembersHandler.generateMembers(null, targetClass, chooserObject.singletonList(), false) + OverrideImplementMembersHandler.generateMembers(editor, targetClass, chooserObject.singletonList(), false) } private fun implementInJavaClass(member: KtNamedDeclaration, targetClass: PsiClass) { @@ -152,9 +154,11 @@ abstract class ImplementAbstractMemberIntentionBase : runWriteAction { for (targetClass in targetClasses) { try { + val descriptor = OpenFileDescriptor(project, targetClass.containingFile.virtualFile) + val targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true)!! when (targetClass) { - is KtLightClass -> targetClass.kotlinOrigin?.let { implementInKotlinClass(member, it) } - is KtEnumEntry -> implementInKotlinClass(member, targetClass) + is KtLightClass -> targetClass.kotlinOrigin?.let { implementInKotlinClass(targetEditor, member, it) } + is KtEnumEntry -> implementInKotlinClass(targetEditor, member, targetClass) is PsiClass -> implementInJavaClass(member, targetClass) } } diff --git a/idea/testData/intentions/implementAbstractMember/function/enumClass.kt.after b/idea/testData/intentions/implementAbstractMember/function/enumClass.kt.after index 2010fe132e8..139b1eba9ce 100644 --- a/idea/testData/intentions/implementAbstractMember/function/enumClass.kt.after +++ b/idea/testData/intentions/implementAbstractMember/function/enumClass.kt.after @@ -1,13 +1,13 @@ // WITH_RUNTIME // DISABLE-ERRORS interface T { - fun foo(x: X): X + fun foo(x: X): X } enum class E : T { A, B, C; override fun foo(x: Int): Int { - throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. } } \ No newline at end of file diff --git a/idea/testData/intentions/implementAbstractMember/function/enumClassWithSemicolon.kt.after b/idea/testData/intentions/implementAbstractMember/function/enumClassWithSemicolon.kt.after index 2010fe132e8..139b1eba9ce 100644 --- a/idea/testData/intentions/implementAbstractMember/function/enumClassWithSemicolon.kt.after +++ b/idea/testData/intentions/implementAbstractMember/function/enumClassWithSemicolon.kt.after @@ -1,13 +1,13 @@ // WITH_RUNTIME // DISABLE-ERRORS interface T { - fun foo(x: X): X + fun foo(x: X): X } enum class E : T { A, B, C; override fun foo(x: Int): Int { - throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. } } \ No newline at end of file diff --git a/idea/testData/intentions/implementAbstractMember/function/enumClassWithSemicolonAndMembers.kt.after b/idea/testData/intentions/implementAbstractMember/function/enumClassWithSemicolonAndMembers.kt.after index e26767eaf9e..22c122847e7 100644 --- a/idea/testData/intentions/implementAbstractMember/function/enumClassWithSemicolonAndMembers.kt.after +++ b/idea/testData/intentions/implementAbstractMember/function/enumClassWithSemicolonAndMembers.kt.after @@ -1,14 +1,14 @@ // WITH_RUNTIME // DISABLE-ERRORS interface T { - fun foo(x: X): X + fun foo(x: X): X } enum class E : T { A, B, C; override fun foo(x: Int): Int { - throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. } val bar = 1 diff --git a/idea/testData/intentions/implementAbstractMember/function/enumEntries.kt.after b/idea/testData/intentions/implementAbstractMember/function/enumEntries.kt.after index 56f8ec4e634..0e8efeb9c24 100644 --- a/idea/testData/intentions/implementAbstractMember/function/enumEntries.kt.after +++ b/idea/testData/intentions/implementAbstractMember/function/enumEntries.kt.after @@ -11,9 +11,9 @@ enum class E { } }, C { override fun foo(x: Int): Int { - throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. } }; - abstract fun foo(x: Int): Int + abstract fun foo(x: Int): Int } \ No newline at end of file diff --git a/idea/testData/intentions/implementAbstractMember/function/enumEntriesWithArgs.kt.after b/idea/testData/intentions/implementAbstractMember/function/enumEntriesWithArgs.kt.after index e92ca79a0cc..efbf2719420 100644 --- a/idea/testData/intentions/implementAbstractMember/function/enumEntriesWithArgs.kt.after +++ b/idea/testData/intentions/implementAbstractMember/function/enumEntriesWithArgs.kt.after @@ -11,9 +11,9 @@ enum class E(n: Int) { } }, C(3) { override fun foo(x: Int): Int { - throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. } }; - abstract fun foo(x: Int): Int + abstract fun foo(x: Int): Int } \ No newline at end of file diff --git a/idea/testData/intentions/implementAbstractMember/function/implementAll.kt.after b/idea/testData/intentions/implementAbstractMember/function/implementAll.kt.after index 35b607a7055..be51b47b826 100644 --- a/idea/testData/intentions/implementAbstractMember/function/implementAll.kt.after +++ b/idea/testData/intentions/implementAbstractMember/function/implementAll.kt.after @@ -1,7 +1,7 @@ // WITH_RUNTIME // DISABLE-ERRORS interface T { - fun foo(x: X): X + fun foo(x: X): X } class U : T { @@ -13,7 +13,7 @@ class U : T { class V : T { override fun foo(x: Int): Int { - throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. } } diff --git a/idea/testData/intentions/implementAbstractMember/property/enumClass.kt.after b/idea/testData/intentions/implementAbstractMember/property/enumClass.kt.after index 4f16ab4e0c4..c666bbea2c2 100644 --- a/idea/testData/intentions/implementAbstractMember/property/enumClass.kt.after +++ b/idea/testData/intentions/implementAbstractMember/property/enumClass.kt.after @@ -1,12 +1,12 @@ // WITH_RUNTIME // DISABLE-ERRORS interface T { - val foo: X + val foo: X } enum class E : T { A, B, C; override val foo: Int - get() = throw UnsupportedOperationException() + get() = throw UnsupportedOperationException() } \ No newline at end of file diff --git a/idea/testData/intentions/implementAbstractMember/property/enumClassWithSemicolon.kt.after b/idea/testData/intentions/implementAbstractMember/property/enumClassWithSemicolon.kt.after index 4f16ab4e0c4..c666bbea2c2 100644 --- a/idea/testData/intentions/implementAbstractMember/property/enumClassWithSemicolon.kt.after +++ b/idea/testData/intentions/implementAbstractMember/property/enumClassWithSemicolon.kt.after @@ -1,12 +1,12 @@ // WITH_RUNTIME // DISABLE-ERRORS interface T { - val foo: X + val foo: X } enum class E : T { A, B, C; override val foo: Int - get() = throw UnsupportedOperationException() + get() = throw UnsupportedOperationException() } \ No newline at end of file diff --git a/idea/testData/intentions/implementAbstractMember/property/enumClassWithSemicolonAndMembers.kt.after b/idea/testData/intentions/implementAbstractMember/property/enumClassWithSemicolonAndMembers.kt.after index d4d29eed592..9dd8c910f53 100644 --- a/idea/testData/intentions/implementAbstractMember/property/enumClassWithSemicolonAndMembers.kt.after +++ b/idea/testData/intentions/implementAbstractMember/property/enumClassWithSemicolonAndMembers.kt.after @@ -1,14 +1,14 @@ // WITH_RUNTIME // DISABLE-ERRORS interface T { - val foo: X + val foo: X } enum class E : T { A, B, C; override val foo: Int - get() = throw UnsupportedOperationException() + get() = throw UnsupportedOperationException() val bar = 1 diff --git a/idea/testData/intentions/implementAbstractMember/property/enumEntries.kt.after b/idea/testData/intentions/implementAbstractMember/property/enumEntries.kt.after index a5e1f6290ad..5cfc7f4a0f8 100644 --- a/idea/testData/intentions/implementAbstractMember/property/enumEntries.kt.after +++ b/idea/testData/intentions/implementAbstractMember/property/enumEntries.kt.after @@ -9,8 +9,8 @@ enum class E { get() = throw UnsupportedOperationException() }, C { override val foo: Int - get() = throw UnsupportedOperationException() + get() = throw UnsupportedOperationException() }; - abstract val foo: Int + abstract val foo: Int } \ No newline at end of file diff --git a/idea/testData/intentions/implementAbstractMember/property/enumEntriesWithArgs.kt.after b/idea/testData/intentions/implementAbstractMember/property/enumEntriesWithArgs.kt.after index ef1cc54e48e..683d006bac1 100644 --- a/idea/testData/intentions/implementAbstractMember/property/enumEntriesWithArgs.kt.after +++ b/idea/testData/intentions/implementAbstractMember/property/enumEntriesWithArgs.kt.after @@ -9,8 +9,8 @@ enum class E(n: Int) { get() = throw UnsupportedOperationException() }, C(3) { override val foo: Int - get() = throw UnsupportedOperationException() + get() = throw UnsupportedOperationException() }; - abstract val foo: Int + abstract val foo: Int } \ No newline at end of file diff --git a/idea/testData/intentions/implementAbstractMember/property/implementAll.kt.after b/idea/testData/intentions/implementAbstractMember/property/implementAll.kt.after index 4a670cfc3a3..1ace2941432 100644 --- a/idea/testData/intentions/implementAbstractMember/property/implementAll.kt.after +++ b/idea/testData/intentions/implementAbstractMember/property/implementAll.kt.after @@ -1,7 +1,7 @@ // WITH_RUNTIME // DISABLE-ERRORS interface T { - val foo: X + val foo: X } class U : T { @@ -12,7 +12,7 @@ class U : T { class V : T { override val foo: Int - get() = throw UnsupportedOperationException() + get() = throw UnsupportedOperationException() }