Implement Abstract Member: Navigate to the generated declaration
#KT-12290 Fixed (cherry picked from commit 6274c6b)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
// DISABLE-ERRORS
|
||||
interface T<X> {
|
||||
fun <caret>foo(x: X): X
|
||||
fun foo(x: X): X
|
||||
}
|
||||
|
||||
enum class E : T<Int> {
|
||||
A, B, C;
|
||||
|
||||
override fun foo(x: Int): Int {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
<caret><selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
// DISABLE-ERRORS
|
||||
interface T<X> {
|
||||
fun <caret>foo(x: X): X
|
||||
fun foo(x: X): X
|
||||
}
|
||||
|
||||
enum class E : T<Int> {
|
||||
A, B, C;
|
||||
|
||||
override fun foo(x: Int): Int {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
<caret><selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
|
||||
}
|
||||
}
|
||||
Vendored
+2
-2
@@ -1,14 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
// DISABLE-ERRORS
|
||||
interface T<X> {
|
||||
fun <caret>foo(x: X): X
|
||||
fun foo(x: X): X
|
||||
}
|
||||
|
||||
enum class E : T<Int> {
|
||||
A, B, C;
|
||||
|
||||
override fun foo(x: Int): Int {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
<caret><selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
|
||||
}
|
||||
|
||||
val bar = 1
|
||||
|
||||
+2
-2
@@ -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.
|
||||
<caret><selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
|
||||
}
|
||||
};
|
||||
|
||||
abstract fun <caret>foo(x: Int): Int
|
||||
abstract fun foo(x: Int): Int
|
||||
}
|
||||
+2
-2
@@ -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.
|
||||
<caret><selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
|
||||
}
|
||||
};
|
||||
|
||||
abstract fun <caret>foo(x: Int): Int
|
||||
abstract fun foo(x: Int): Int
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// DISABLE-ERRORS
|
||||
interface T<X> {
|
||||
fun <caret>foo(x: X): X
|
||||
fun foo(x: X): X
|
||||
}
|
||||
|
||||
class U : T<String> {
|
||||
@@ -13,7 +13,7 @@ class U : T<String> {
|
||||
|
||||
class V : T<Int> {
|
||||
override fun foo(x: Int): Int {
|
||||
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
<caret><selection>throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.</selection>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
// DISABLE-ERRORS
|
||||
interface T<X> {
|
||||
val <caret>foo: X
|
||||
val foo: X
|
||||
}
|
||||
|
||||
enum class E : T<Int> {
|
||||
A, B, C;
|
||||
|
||||
override val foo: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
get() = <caret><selection>throw UnsupportedOperationException()</selection>
|
||||
}
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
// DISABLE-ERRORS
|
||||
interface T<X> {
|
||||
val <caret>foo: X
|
||||
val foo: X
|
||||
}
|
||||
|
||||
enum class E : T<Int> {
|
||||
A, B, C;
|
||||
|
||||
override val foo: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
get() = <caret><selection>throw UnsupportedOperationException()</selection>
|
||||
}
|
||||
Vendored
+2
-2
@@ -1,14 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
// DISABLE-ERRORS
|
||||
interface T<X> {
|
||||
val <caret>foo: X
|
||||
val foo: X
|
||||
}
|
||||
|
||||
enum class E : T<Int> {
|
||||
A, B, C;
|
||||
|
||||
override val foo: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
get() = <caret><selection>throw UnsupportedOperationException()</selection>
|
||||
|
||||
val bar = 1
|
||||
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ enum class E {
|
||||
get() = throw UnsupportedOperationException()
|
||||
}, C {
|
||||
override val foo: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
get() = <caret><selection>throw UnsupportedOperationException()</selection>
|
||||
};
|
||||
|
||||
abstract val <caret>foo: Int
|
||||
abstract val foo: Int
|
||||
}
|
||||
+2
-2
@@ -9,8 +9,8 @@ enum class E(n: Int) {
|
||||
get() = throw UnsupportedOperationException()
|
||||
}, C(3) {
|
||||
override val foo: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
get() = <caret><selection>throw UnsupportedOperationException()</selection>
|
||||
};
|
||||
|
||||
abstract val <caret>foo: Int
|
||||
abstract val foo: Int
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// DISABLE-ERRORS
|
||||
interface T<X> {
|
||||
val <caret>foo: X
|
||||
val foo: X
|
||||
}
|
||||
|
||||
class U : T<String> {
|
||||
@@ -12,7 +12,7 @@ class U : T<String> {
|
||||
|
||||
class V : T<Int> {
|
||||
override val foo: Int
|
||||
get() = throw UnsupportedOperationException()
|
||||
get() = <caret><selection>throw UnsupportedOperationException()</selection>
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user