Add unavailable stub to framework for Kotlin subclass of Obj-C class

To improve discoverability of the corresponding limitation
This commit is contained in:
Svyatoslav Scherbina
2018-12-03 13:19:22 +03:00
committed by SvyatoslavScherbina
parent 9e3a68f835
commit 49dc267eb4
2 changed files with 28 additions and 11 deletions
@@ -220,8 +220,8 @@ abstract class ObjCExportHeaderGenerator(
getContributedDescriptors() getContributedDescriptors()
.asSequence() .asSequence()
.filterIsInstance<ClassDescriptor>() .filterIsInstance<ClassDescriptor>()
.filter { mapper.shouldBeExposed(it) }
.forEach { .forEach {
if (mapper.shouldBeExposed(it)) {
if (it.isInterface) { if (it.isInterface) {
translateInterface(it) translateInterface(it)
} else { } else {
@@ -229,6 +229,10 @@ abstract class ObjCExportHeaderGenerator(
} }
it.unsubstitutedMemberScope.translateClasses() it.unsubstitutedMemberScope.translateClasses()
} else if (it.isKotlinObjCClass() && mapper.shouldBeVisible(it)) {
assert(!it.isInterface)
translateKotlinObjCClassAsUnavailableStub(it)
}
} }
} }
@@ -257,6 +261,16 @@ abstract class ObjCExportHeaderGenerator(
return stubs return stubs
} }
private fun translateKotlinObjCClassAsUnavailableStub(descriptor: ClassDescriptor) {
stubs.add(objCInterface(
namer.getClassOrProtocolName(descriptor),
descriptor = descriptor,
superClass = "NSObject",
attributes = listOf("unavailable(\"Kotlin subclass of Objective-C class can't be imported\")")
))
}
private fun genKotlinNumbers() { private fun genKotlinNumbers() {
val members = buildMembers { val members = buildMembers {
NSNumberKind.values().forEach { NSNumberKind.values().forEach {
@@ -54,7 +54,10 @@ internal fun ObjCExportMapper.shouldBeExposed(descriptor: CallableMemberDescript
descriptor.isEffectivelyPublicApi && !descriptor.isSuspend && !descriptor.isExpect descriptor.isEffectivelyPublicApi && !descriptor.isSuspend && !descriptor.isExpect
internal fun ObjCExportMapper.shouldBeExposed(descriptor: ClassDescriptor): Boolean = internal fun ObjCExportMapper.shouldBeExposed(descriptor: ClassDescriptor): Boolean =
descriptor.isEffectivelyPublicApi && !descriptor.defaultType.isObjCObjectType() && when (descriptor.kind) { shouldBeVisible(descriptor) && !descriptor.defaultType.isObjCObjectType()
internal fun ObjCExportMapper.shouldBeVisible(descriptor: ClassDescriptor): Boolean =
descriptor.isEffectivelyPublicApi && when (descriptor.kind) {
ClassKind.CLASS, ClassKind.INTERFACE, ClassKind.ENUM_CLASS, ClassKind.OBJECT -> true ClassKind.CLASS, ClassKind.INTERFACE, ClassKind.ENUM_CLASS, ClassKind.OBJECT -> true
ClassKind.ENUM_ENTRY, ClassKind.ANNOTATION_CLASS -> false ClassKind.ENUM_ENTRY, ClassKind.ANNOTATION_CLASS -> false
} && !descriptor.isExpect && !isSpecialMapped(descriptor) && !descriptor.isInlined() } && !descriptor.isExpect && !isSpecialMapped(descriptor) && !descriptor.isInlined()