[ObjCExport] Add extras to ObjCExportStub for proper @Throws translation
KT-66239
This commit is contained in:
committed by
Space Team
parent
42d8db1c52
commit
ac1f664a65
+15
@@ -0,0 +1,15 @@
|
||||
package org.jetbrains.kotlin.objcexport.extras
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportStub
|
||||
import org.jetbrains.kotlin.tooling.core.Extras
|
||||
import org.jetbrains.kotlin.tooling.core.MutableExtras
|
||||
import org.jetbrains.kotlin.tooling.core.mutableExtrasOf
|
||||
|
||||
internal object ObjCExportStubExtrasBuilderContext
|
||||
|
||||
/**
|
||||
* Convenience function for building extras for [ObjCExportStub]
|
||||
*/
|
||||
internal fun objCExportStubExtras(builder: context(ObjCExportStubExtrasBuilderContext) MutableExtras.() -> Unit): Extras {
|
||||
return mutableExtrasOf().also { extras -> builder(ObjCExportStubExtrasBuilderContext, extras) }
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package org.jetbrains.kotlin.objcexport.extras
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportStub
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.tooling.core.MutableExtras
|
||||
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
|
||||
|
||||
private val throwsAnnotationClassIdsKey = extrasKeyOf<List<ClassId>?>()
|
||||
|
||||
/**
|
||||
* Functions and constructors can have [Throws] annotations which lists exceptions.
|
||||
* This lists of exceptions needs to be translated and forwarded as dependencies
|
||||
*/
|
||||
internal val ObjCExportStub.throwsAnnotationClassIds: List<ClassId>?
|
||||
get() {
|
||||
extras[throwsAnnotationClassIdsKey]?.let { return it }
|
||||
return null
|
||||
}
|
||||
|
||||
context(ObjCExportStubExtrasBuilderContext)
|
||||
internal var MutableExtras.throwsAnnotationClassIds: List<ClassId>?
|
||||
get() = this[throwsAnnotationClassIdsKey]
|
||||
set(value) {
|
||||
this[throwsAnnotationClassIdsKey] = value
|
||||
}
|
||||
+6
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.objcexport.KtObjCExportHeaderGenerator.QueueElement
|
||||
import org.jetbrains.kotlin.objcexport.analysisApiUtils.*
|
||||
import org.jetbrains.kotlin.objcexport.extras.originClassId
|
||||
import org.jetbrains.kotlin.objcexport.extras.requiresForwardDeclaration
|
||||
import org.jetbrains.kotlin.objcexport.extras.throwsAnnotationClassIds
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
|
||||
@@ -181,6 +182,11 @@ private class KtObjCExportHeaderGenerator {
|
||||
* and `Array` has to be registered as forward declaration.
|
||||
*/
|
||||
private fun enqueueDependencyClasses(stub: ObjCExportStub) {
|
||||
|
||||
symbolDeque += stub.closureSequence()
|
||||
.flatMap { child -> child.throwsAnnotationClassIds.orEmpty() }
|
||||
.map { QueueElement.Class(it) }
|
||||
|
||||
symbolDeque += stub.closureSequence()
|
||||
.mapNotNull { child ->
|
||||
when (child) {
|
||||
|
||||
+8
-3
@@ -13,6 +13,8 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.objcexport.Predefined.anyMethodSelectors
|
||||
import org.jetbrains.kotlin.objcexport.Predefined.anyMethodSwiftNames
|
||||
import org.jetbrains.kotlin.objcexport.analysisApiUtils.*
|
||||
import org.jetbrains.kotlin.objcexport.extras.objCExportStubExtras
|
||||
import org.jetbrains.kotlin.objcexport.extras.throwsAnnotationClassIds
|
||||
|
||||
internal val KtCallableSymbol.isConstructor: Boolean
|
||||
get() = this is KtConstructorSymbol
|
||||
@@ -50,7 +52,8 @@ internal fun KtFunctionLikeSymbol.buildObjCMethod(
|
||||
val swiftName = getSwiftName(bridge)
|
||||
val attributes = mutableListOf<String>()
|
||||
val returnBridge = bridge.returnBridge
|
||||
val comment = this.translateToObjCComment(bridge, parameters)
|
||||
val comment = translateToObjCComment(bridge, parameters)
|
||||
val throws = definedThrows.map { it }.toList()
|
||||
|
||||
attributes += getSwiftPrivateAttribute() ?: swiftNameAttribute(swiftName)
|
||||
|
||||
@@ -81,7 +84,10 @@ internal fun KtFunctionLikeSymbol.buildObjCMethod(
|
||||
returnType = returnType,
|
||||
selectors = selectors,
|
||||
parameters = parameters,
|
||||
attributes = attributes
|
||||
attributes = attributes,
|
||||
extras = objCExportStubExtras {
|
||||
throwsAnnotationClassIds = throws
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -257,7 +263,6 @@ fun MethodBridge.valueParametersAssociated(
|
||||
function: KtFunctionLikeSymbol,
|
||||
): List<Pair<MethodBridgeValueParameter, KtValueParameterSymbol?>> {
|
||||
val allParameters = function.valueParameters
|
||||
if (allParameters.isEmpty()) return emptyList()
|
||||
|
||||
return this.valueParameters.mapIndexed { index, valueParameterBridge ->
|
||||
when (valueParameterBridge) {
|
||||
|
||||
Reference in New Issue
Block a user