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,15 +220,19 @@ abstract class ObjCExportHeaderGenerator(
getContributedDescriptors()
.asSequence()
.filterIsInstance<ClassDescriptor>()
.filter { mapper.shouldBeExposed(it) }
.forEach {
if (it.isInterface) {
translateInterface(it)
} else {
translateClass(it)
}
if (mapper.shouldBeExposed(it)) {
if (it.isInterface) {
translateInterface(it)
} else {
translateClass(it)
}
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
}
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() {
val members = buildMembers {
NSNumberKind.values().forEach {
@@ -54,10 +54,13 @@ internal fun ObjCExportMapper.shouldBeExposed(descriptor: CallableMemberDescript
descriptor.isEffectivelyPublicApi && !descriptor.isSuspend && !descriptor.isExpect
internal fun ObjCExportMapper.shouldBeExposed(descriptor: ClassDescriptor): Boolean =
descriptor.isEffectivelyPublicApi && !descriptor.defaultType.isObjCObjectType() && when (descriptor.kind) {
ClassKind.CLASS, ClassKind.INTERFACE, ClassKind.ENUM_CLASS, ClassKind.OBJECT -> true
ClassKind.ENUM_ENTRY, ClassKind.ANNOTATION_CLASS -> false
} && !descriptor.isExpect && !isSpecialMapped(descriptor) && !descriptor.isInlined()
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.ENUM_ENTRY, ClassKind.ANNOTATION_CLASS -> false
} && !descriptor.isExpect && !isSpecialMapped(descriptor) && !descriptor.isInlined()
private fun ObjCExportMapper.isBase(descriptor: CallableMemberDescriptor): Boolean =
descriptor.overriddenDescriptors.all { !shouldBeExposed(it) }