Create Class from Usage: Filter out usages in super type entry list
#KT-22918 Fixed
This commit is contained in:
+10
-11
@@ -46,12 +46,8 @@ import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
|||||||
import org.jetbrains.kotlin.idea.util.projectStructure.module
|
import org.jetbrains.kotlin.idea.util.projectStructure.module
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtClass
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
|
||||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -117,17 +113,20 @@ open class CreateClassFromUsageFix<E : KtElement> protected constructor (
|
|||||||
if (editor == null) return
|
if (editor == null) return
|
||||||
|
|
||||||
val applicableParents = SmartList<PsiElement>().also { parents ->
|
val applicableParents = SmartList<PsiElement>().also { parents ->
|
||||||
if (classInfo.kind == ClassKind.INTERFACE)
|
classInfo.applicableParents.filterNotTo(parents) {
|
||||||
classInfo.applicableParents.filterTo(parents) { it != element?.containingClass() }
|
it is KtClassOrObject && it.superTypeListEntries.any {
|
||||||
else
|
when (it) {
|
||||||
parents += classInfo.applicableParents
|
is KtDelegatedSuperTypeEntry, is KtSuperTypeEntry -> it.typeAsUserType == element
|
||||||
|
is KtSuperTypeCallEntry -> it == element
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (classInfo.kind != ClassKind.ENUM_ENTRY) {
|
if (classInfo.kind != ClassKind.ENUM_ENTRY) {
|
||||||
parents += SeparateFileWrapper(PsiManager.getInstance(project))
|
parents += SeparateFileWrapper(PsiManager.getInstance(project))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||||
val targetParent = applicableParents.firstOrNull {
|
val targetParent = applicableParents.firstOrNull {
|
||||||
it.allChildren.any { it is PsiComment && it.text == "// TARGET_PARENT:" }
|
it.allChildren.any { it is PsiComment && it.text == "// TARGET_PARENT:" }
|
||||||
|
|||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// "Create class 'A'" "true"
|
||||||
|
package p
|
||||||
|
|
||||||
|
// TARGET_PARENT:
|
||||||
|
class Foo: <caret>A() {
|
||||||
|
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// "Create class 'A'" "true"
|
||||||
|
package p
|
||||||
|
|
||||||
|
// TARGET_PARENT:
|
||||||
|
class Foo: A() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
<caret>open class A {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2286,6 +2286,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/classDelegatorToSuperclass.kt");
|
runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/classDelegatorToSuperclass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("createSuperclassInsideSubclass.kt")
|
||||||
|
public void testCreateSuperclassInsideSubclass() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/createSuperclassInsideSubclass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("delegatorToSupercallNoReceiver.kt")
|
@TestMetadata("delegatorToSupercallNoReceiver.kt")
|
||||||
public void testDelegatorToSupercallNoReceiver() throws Exception {
|
public void testDelegatorToSupercallNoReceiver() throws Exception {
|
||||||
runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/delegatorToSupercallNoReceiver.kt");
|
runTest("idea/testData/quickfix/createFromUsage/createClass/delegationSpecifier/delegatorToSupercallNoReceiver.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user