Simplify support for importing Objective-C properties

This commit is contained in:
Svyatoslav Scherbina
2019-03-14 11:38:02 +03:00
committed by SvyatoslavScherbina
parent 4d17460e75
commit 0ff1209d0a
3 changed files with 10 additions and 4 deletions
@@ -100,7 +100,7 @@ external fun getReceiverOrSuper(receiver: NativePtr, superClass: NativePtr): COp
@Retention(AnnotationRetention.BINARY)
annotation class ExternalObjCClass(val protocolGetter: String = "", val binaryName: String = "")
@Target(AnnotationTarget.FUNCTION)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
@Retention(AnnotationRetention.BINARY)
annotation class ObjCMethod(val selector: String, val bridge: String)
@@ -74,7 +74,7 @@ class ObjCMethodStub(private val stubGenerator: StubGenerator,
override fun generate(context: StubGenerationContext): Sequence<String> =
if (context.nativeBridges.isSupported(this)) {
val result = mutableListOf<String>()
result.add("@ObjCMethod".applyToStrings(method.selector, bridgeName))
result.add(objCMethodAnnotation)
if (method.nsConsumesSelf) result.add("@CCall.ConsumesReceiver")
if (method.nsReturnsRetained) result.add("@CCall.ReturnsRetained")
result.add(header)
@@ -167,6 +167,7 @@ class ObjCMethodStub(private val stubGenerator: StubGenerator,
private val implementationTemplate: String?
internal val bridgeName: String
private val bridgeHeader: String
internal val objCMethodAnnotation: String
init {
val bodyGenerator = KotlinCodeBuilder(scope = stubGenerator.kotlinFile)
@@ -253,6 +254,7 @@ class ObjCMethodStub(private val stubGenerator: StubGenerator,
this.bodyLines = bodyGenerator.build()
bridgeName = "objcKniBridge${stubGenerator.nextUniqueId()}"
objCMethodAnnotation = "@ObjCMethod".applyToStrings(method.selector, bridgeName)
this.bridgeHeader = buildString {
append("internal fun ")
@@ -711,11 +713,11 @@ class ObjCPropertyStub(
}
val result = mutableListOf(
"$modifiers$kind $receiver${property.name.asSimpleName()}: $kotlinType",
" get() = ${getterStub.bridgeName}(nativeNullPtr, this.objcPtr())"
" ${getterStub.objCMethodAnnotation} external get"
)
property.setter?.let {
result.add(" set(value) = ${setterStub!!.bridgeName}(nativeNullPtr, this.objcPtr(), value)")
result.add(" ${setterStub!!.objCMethodAnnotation} external set")
}
return result.asSequence()
@@ -102,6 +102,10 @@ object KonanMangler : KotlinManglerImpl() {
append(it.selector)
if (this@platformSpecificFunctionName is IrConstructor && this@platformSpecificFunctionName.isObjCConstructor) append("#Constructor")
if ((this@platformSpecificFunctionName as? IrSimpleFunction)?.correspondingProperty != null) {
append("#Accessor")
}
// We happen to have the clashing combinations such as
//@ObjCMethod("issueChallengeToPlayers:message:", "objcKniBridge1165")
//external fun GKScore.issueChallengeToPlayers(playerIDs: List<*>?, message: String?): Unit