ExpectActualUtils: repairSuperTypeList should consider type parameters
This commit is contained in:
@@ -217,32 +217,37 @@ private fun KtPsiFactory.repairSuperTypeList(
|
|||||||
context: BindingContext
|
context: BindingContext
|
||||||
): Collection<String> {
|
): Collection<String> {
|
||||||
val superNames = linkedSetOf<String>()
|
val superNames = linkedSetOf<String>()
|
||||||
generated.superTypeListEntries.zip(original.superTypeListEntries).forEach { (generatedEntry, originalEntry) ->
|
val typeParametersFqName = context[BindingContext.DECLARATION_TO_DESCRIPTOR, original]
|
||||||
val superType = context[BindingContext.TYPE, originalEntry.typeReference]
|
?.safeAs<ClassDescriptor>()
|
||||||
val superClassDescriptor = superType?.constructor?.declarationDescriptor as? ClassDescriptor ?: return@forEach
|
?.declaredTypeParameters?.mapNotNull { it.fqNameOrNull()?.asString() }.orEmpty()
|
||||||
if (generateExpectClass && !checker.checkAccessibility(superType)) {
|
|
||||||
generatedEntry.delete()
|
|
||||||
return@forEach
|
|
||||||
}
|
|
||||||
|
|
||||||
superType.fqName?.shortName()?.asString()?.let { superNames += it }
|
checker.runInContext(checker.existingTypeNames + typeParametersFqName) {
|
||||||
if (generateExpectClass) {
|
generated.superTypeListEntries.zip(original.superTypeListEntries).forEach { (generatedEntry, originalEntry) ->
|
||||||
if (generatedEntry !is KtSuperTypeCallEntry) return@forEach
|
val superType = context[BindingContext.TYPE, originalEntry.typeReference]
|
||||||
} else {
|
val superClassDescriptor = superType?.constructor?.declarationDescriptor as? ClassDescriptor ?: return@forEach
|
||||||
if (generatedEntry !is KtSuperTypeEntry) return@forEach
|
if (generateExpectClass && !checker.checkAccessibility(superType)) {
|
||||||
}
|
generatedEntry.delete()
|
||||||
|
return@forEach
|
||||||
if (superClassDescriptor.kind == ClassKind.CLASS || superClassDescriptor.kind == ClassKind.ENUM_CLASS) {
|
}
|
||||||
val entryText = IdeDescriptorRenderers.SOURCE_CODE.renderType(superType)
|
|
||||||
val newGeneratedEntry = if (generateExpectClass) {
|
superType.fqName?.shortName()?.asString()?.let { superNames += it }
|
||||||
createSuperTypeEntry(entryText)
|
if (generateExpectClass) {
|
||||||
} else {
|
if (generatedEntry !is KtSuperTypeCallEntry) return@forEach
|
||||||
createSuperTypeCallEntry("$entryText()")
|
} 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<KtElement>()?.addToBeShortenedDescendantsToWaitingSet()
|
||||||
}
|
}
|
||||||
generatedEntry.replace(newGeneratedEntry).safeAs<KtElement>()?.addToBeShortenedDescendantsToWaitingSet()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generated.superTypeListEntries.isEmpty()) generated.getSuperTypeList()?.delete()
|
if (generated.superTypeListEntries.isEmpty()) generated.getSuperTypeList()?.delete()
|
||||||
return superNames
|
return superNames
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
// My: to be implemented
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER)
|
||||||
|
annotation class SimpleA
|
||||||
|
|
||||||
|
class Common<T>
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// My: to be implemented
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER)
|
||||||
|
annotation class SimpleA
|
||||||
|
|
||||||
|
class Common<T>
|
||||||
|
expect class My<T> : Common<@SimpleA T>
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
// "Create expected class in common module testModule_Common" "true"
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
actual class <caret>My<T> : Common<@SimpleA T>()
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
// "Create expected class in common module testModule_Common" "true"
|
||||||
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
|
actual class My<T> : Common<@SimpleA T>()
|
||||||
Vendored
+1
@@ -1 +1,2 @@
|
|||||||
|
@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER)
|
||||||
annotation class SimpleA
|
annotation class SimpleA
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
expect fun @receiver:SimpleA String.myExtension()
|
expect fun <T : @SimpleA List<@SimpleA List<@SimpleA String>>> @receiver:SimpleA String.myExtension(@SimpleA a: @SimpleA List<@SimpleA List<@SimpleA String>>)
|
||||||
Vendored
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
// "Create expected function in common module testModule_Common" "true"
|
// "Create expected function in common module testModule_Common" "true"
|
||||||
// DISABLE-ERRORS
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
actual fun @receiver:SimpleA String.<caret>myExtension() { println(this) }
|
actual fun <T : @SimpleA List<@SimpleA List<@SimpleA String>>>@receiver:SimpleA String.<caret>myExtension(@SimpleA a: @SimpleA List<@SimpleA List<@SimpleA String>>) {
|
||||||
|
println(this)
|
||||||
|
}
|
||||||
Vendored
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
// "Create expected function in common module testModule_Common" "true"
|
// "Create expected function in common module testModule_Common" "true"
|
||||||
// DISABLE-ERRORS
|
// DISABLE-ERRORS
|
||||||
|
|
||||||
actual fun @receiver:SimpleA String.<caret>myExtension() { println(this) }
|
actual fun <T : @SimpleA List<@SimpleA List<@SimpleA String>>>@receiver:SimpleA String.myExtension(@SimpleA a: @SimpleA List<@SimpleA List<@SimpleA String>>) {
|
||||||
|
println(this)
|
||||||
|
}
|
||||||
+5
@@ -332,6 +332,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
|
|||||||
runTest("idea/testData/multiModuleQuickFix/createExpect/class/");
|
runTest("idea/testData/multiModuleQuickFix/createExpect/class/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classWithSuperClassAndTypeParameter")
|
||||||
|
public void testClassWithSuperClassAndTypeParameter() throws Exception {
|
||||||
|
runTest("idea/testData/multiModuleQuickFix/createExpect/classWithSuperClassAndTypeParameter/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("classWithSuperTypeFromOtherPackage")
|
@TestMetadata("classWithSuperTypeFromOtherPackage")
|
||||||
public void testClassWithSuperTypeFromOtherPackage() throws Exception {
|
public void testClassWithSuperTypeFromOtherPackage() throws Exception {
|
||||||
runTest("idea/testData/multiModuleQuickFix/createExpect/classWithSuperTypeFromOtherPackage/");
|
runTest("idea/testData/multiModuleQuickFix/createExpect/classWithSuperTypeFromOtherPackage/");
|
||||||
|
|||||||
Reference in New Issue
Block a user