diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/expectactual/ExpectActualUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/expectactual/ExpectActualUtils.kt index 5b13178915e..eef89ed2bfe 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/expectactual/ExpectActualUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/expectactual/ExpectActualUtils.kt @@ -217,32 +217,37 @@ private fun KtPsiFactory.repairSuperTypeList( context: BindingContext ): Collection { val superNames = linkedSetOf() - generated.superTypeListEntries.zip(original.superTypeListEntries).forEach { (generatedEntry, originalEntry) -> - val superType = context[BindingContext.TYPE, originalEntry.typeReference] - val superClassDescriptor = superType?.constructor?.declarationDescriptor as? ClassDescriptor ?: return@forEach - if (generateExpectClass && !checker.checkAccessibility(superType)) { - generatedEntry.delete() - return@forEach - } + val typeParametersFqName = context[BindingContext.DECLARATION_TO_DESCRIPTOR, original] + ?.safeAs() + ?.declaredTypeParameters?.mapNotNull { it.fqNameOrNull()?.asString() }.orEmpty() - superType.fqName?.shortName()?.asString()?.let { superNames += it } - if (generateExpectClass) { - if (generatedEntry !is KtSuperTypeCallEntry) return@forEach - } else { - if (generatedEntry !is KtSuperTypeEntry) return@forEach - } - - if (superClassDescriptor.kind == ClassKind.CLASS || superClassDescriptor.kind == ClassKind.ENUM_CLASS) { - val entryText = IdeDescriptorRenderers.SOURCE_CODE.renderType(superType) - val newGeneratedEntry = if (generateExpectClass) { - createSuperTypeEntry(entryText) - } else { - createSuperTypeCallEntry("$entryText()") + checker.runInContext(checker.existingTypeNames + typeParametersFqName) { + generated.superTypeListEntries.zip(original.superTypeListEntries).forEach { (generatedEntry, originalEntry) -> + val superType = context[BindingContext.TYPE, originalEntry.typeReference] + val superClassDescriptor = superType?.constructor?.declarationDescriptor as? ClassDescriptor ?: return@forEach + if (generateExpectClass && !checker.checkAccessibility(superType)) { + generatedEntry.delete() + return@forEach + } + + superType.fqName?.shortName()?.asString()?.let { superNames += it } + if (generateExpectClass) { + if (generatedEntry !is KtSuperTypeCallEntry) return@forEach + } else { + if (generatedEntry !is KtSuperTypeEntry) return@forEach + } + + if (superClassDescriptor.kind == ClassKind.CLASS || superClassDescriptor.kind == ClassKind.ENUM_CLASS) { + val entryText = IdeDescriptorRenderers.SOURCE_CODE.renderType(superType) + val newGeneratedEntry = if (generateExpectClass) { + createSuperTypeEntry(entryText) + } else { + createSuperTypeCallEntry("$entryText()") + } + generatedEntry.replace(newGeneratedEntry).safeAs()?.addToBeShortenedDescendantsToWaitingSet() } - generatedEntry.replace(newGeneratedEntry).safeAs()?.addToBeShortenedDescendantsToWaitingSet() } } - if (generated.superTypeListEntries.isEmpty()) generated.getSuperTypeList()?.delete() return superNames } diff --git a/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/header/My.kt b/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/header/My.kt new file mode 100644 index 00000000000..685508ae403 --- /dev/null +++ b/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/header/My.kt @@ -0,0 +1,7 @@ +// My: to be implemented +// DISABLE-ERRORS + +@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER) +annotation class SimpleA + +class Common \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/header/My.kt.after b/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/header/My.kt.after new file mode 100644 index 00000000000..226d241182c --- /dev/null +++ b/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/header/My.kt.after @@ -0,0 +1,8 @@ +// My: to be implemented +// DISABLE-ERRORS + +@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER) +annotation class SimpleA + +class Common +expect class My : Common<@SimpleA T> \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/jvm/My.kt b/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/jvm/My.kt new file mode 100644 index 00000000000..17383a4aae7 --- /dev/null +++ b/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/jvm/My.kt @@ -0,0 +1,4 @@ +// "Create expected class in common module testModule_Common" "true" +// DISABLE-ERRORS + +actual class My : Common<@SimpleA T>() \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/jvm/My.kt.after b/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/jvm/My.kt.after new file mode 100644 index 00000000000..8e64ab57f02 --- /dev/null +++ b/idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/jvm/My.kt.after @@ -0,0 +1,4 @@ +// "Create expected class in common module testModule_Common" "true" +// DISABLE-ERRORS + +actual class My : Common<@SimpleA T>() \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/SimpleA.kt b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/SimpleA.kt index 2fdd274a214..eb9f5cfc34e 100644 --- a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/SimpleA.kt +++ b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/SimpleA.kt @@ -1 +1,2 @@ +@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER) annotation class SimpleA \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/myExtension.kt.after b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/myExtension.kt.after index d9fb6aaaae0..9a9217beb69 100644 --- a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/myExtension.kt.after +++ b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/myExtension.kt.after @@ -1 +1 @@ -expect fun @receiver:SimpleA String.myExtension() \ No newline at end of file +expect fun >> @receiver:SimpleA String.myExtension(@SimpleA a: @SimpleA List<@SimpleA List<@SimpleA String>>) \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt index 8d33975dd82..7c08073afdc 100644 --- a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt +++ b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt @@ -1,4 +1,6 @@ // "Create expected function in common module testModule_Common" "true" // DISABLE-ERRORS -actual fun @receiver:SimpleA String.myExtension() { println(this) } \ No newline at end of file +actual fun >>@receiver:SimpleA String.myExtension(@SimpleA a: @SimpleA List<@SimpleA List<@SimpleA String>>) { + println(this) +} \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt.after b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt.after index 8d33975dd82..37017df2e68 100644 --- a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt.after +++ b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt.after @@ -1,4 +1,6 @@ // "Create expected function in common module testModule_Common" "true" // DISABLE-ERRORS -actual fun @receiver:SimpleA String.myExtension() { println(this) } \ No newline at end of file +actual fun >>@receiver:SimpleA String.myExtension(@SimpleA a: @SimpleA List<@SimpleA List<@SimpleA String>>) { + println(this) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java index 126c74901e9..55f8f5c6953 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java @@ -332,6 +332,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul runTest("idea/testData/multiModuleQuickFix/createExpect/class/"); } + @TestMetadata("classWithSuperClassAndTypeParameter") + public void testClassWithSuperClassAndTypeParameter() throws Exception { + runTest("idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/"); + } + @TestMetadata("classWithSuperTypeFromOtherPackage") public void testClassWithSuperTypeFromOtherPackage() throws Exception { runTest("idea/testData/multiModuleQuickFix/createExpect/classWithSuperTypeFromOtherPackage/");