KT-21698 Create interface shouldn't suggest to declare it inside a class which implements it
This commit is contained in:
committed by
Dmitry Jemerov
parent
1deed28464
commit
411feab9ae
+8
-2
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
||||
import java.util.*
|
||||
|
||||
enum class ClassKind(val keyword: String, val description: String) {
|
||||
@@ -101,14 +102,19 @@ open class CreateClassFromUsageFix<E : KtElement> protected constructor (
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
if (editor == null) return
|
||||
|
||||
val applicableParents = if (classInfo.kind == ClassKind.INTERFACE)
|
||||
classInfo.applicableParents.filter { it != element?.containingClass() }
|
||||
else
|
||||
classInfo.applicableParents
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
val targetParent = classInfo.applicableParents.firstOrNull {
|
||||
val targetParent = applicableParents.firstOrNull {
|
||||
it.allChildren.any { it is PsiComment && it.text == "// TARGET_PARENT:" }
|
||||
} ?: classInfo.applicableParents.last()
|
||||
return doInvoke(targetParent, editor, file)
|
||||
}
|
||||
|
||||
chooseContainerElementIfNecessary(classInfo.applicableParents, editor, "Choose class container", true, { it }) {
|
||||
chooseContainerElementIfNecessary(applicableParents, editor, "Choose class container", true, { it }) {
|
||||
doInvoke(it, editor, file)
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Create interface 'A'" "true"
|
||||
package p
|
||||
|
||||
// TARGET_PARENT:
|
||||
class Foo: <caret>A {
|
||||
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Create interface 'A'" "true"
|
||||
package p
|
||||
|
||||
// TARGET_PARENT:
|
||||
class Foo: A {
|
||||
|
||||
}
|
||||
|
||||
interface A {
|
||||
|
||||
}
|
||||
@@ -2225,6 +2225,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/traitDelegatorToSuperclass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("traitDelegatorToSuperclass2.kt")
|
||||
public void testTraitDelegatorToSuperclass2() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/traitDelegatorToSuperclass2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/createFromUsage/createClass/importDirective")
|
||||
|
||||
Reference in New Issue
Block a user