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