[ObjCExport] AA: Enable generation of base declarations
^KT-65738 Fixed
This commit is contained in:
committed by
Space Team
parent
2ae2f09fee
commit
e53e94516f
+7
-1
@@ -21,5 +21,11 @@ data class KtObjCExportConfiguration(
|
||||
* - [org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportNamingHelper.canBeSwiftOuter]
|
||||
* - [org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportNamingHelper.canBeSwiftInner]
|
||||
*/
|
||||
val objcGenerics: Boolean = true
|
||||
val objcGenerics: Boolean = true,
|
||||
|
||||
/**
|
||||
* Flag to enable/disable the emission of 'base declarations'
|
||||
* (see [org.jetbrains.kotlin.objcexport.objCBaseDeclarations]).
|
||||
*/
|
||||
val generateBaseDeclarationStubs: Boolean = true,
|
||||
)
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.objcexport
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCTopLevel
|
||||
import org.jetbrains.kotlin.backend.konan.objcexport.objCBaseDeclarations
|
||||
import org.jetbrains.kotlin.objcexport.analysisApiUtils.getDefaultSuperClassOrProtocolName
|
||||
|
||||
context(KtObjCExportSession)
|
||||
internal fun objCBaseDeclarations(): List<ObjCTopLevel> {
|
||||
return objCBaseDeclarations(
|
||||
topLevelNamePrefix = configuration.frameworkName.orEmpty(),
|
||||
objCNameOfAny = getDefaultSuperClassOrProtocolName(),
|
||||
objCNameOfNumber = "Number".getObjCKotlinStdlibClassOrProtocolName(),
|
||||
objCNameOfMutableMap = "MutableDictionary".getObjCKotlinStdlibClassOrProtocolName(),
|
||||
objCNameOfMutableSet = "MutableSet".getObjCKotlinStdlibClassOrProtocolName(),
|
||||
objCNameForNumberBox = { classId -> classId.shortClassName.asString().getObjCKotlinStdlibClassOrProtocolName() }
|
||||
)
|
||||
}
|
||||
+4
@@ -127,6 +127,10 @@ fun translateToObjCHeader(files: List<KtFile>): ObjCHeader {
|
||||
classForwardDeclarations.add(errorForwardClass)
|
||||
}
|
||||
|
||||
if (configuration.generateBaseDeclarationStubs) {
|
||||
stubs.addAll(0, objCBaseDeclarations())
|
||||
}
|
||||
|
||||
return ObjCHeader(
|
||||
stubs = stubs,
|
||||
classForwardDeclarations = classForwardDeclarations,
|
||||
|
||||
+6
-1
@@ -7,6 +7,9 @@ package org.jetbrains.kotlin.objcexport.testUtils
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCTopLevel
|
||||
import org.jetbrains.kotlin.backend.konan.tests.ObjCExportBaseDeclarationsTest
|
||||
import org.jetbrains.kotlin.objcexport.KtObjCExportConfiguration
|
||||
import org.jetbrains.kotlin.objcexport.KtObjCExportSession
|
||||
import org.jetbrains.kotlin.objcexport.objCBaseDeclarations
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
import org.junit.jupiter.api.extension.ParameterContext
|
||||
import org.junit.jupiter.api.extension.ParameterResolver
|
||||
@@ -23,6 +26,8 @@ class AnalysisApiBaseDeclarationsGeneratorExtension : ParameterResolver {
|
||||
|
||||
object AnalysisApiBaseDeclarationsGenerator : ObjCExportBaseDeclarationsTest.BaseDeclarationsGenerator {
|
||||
override fun invoke(topLevelPrefix: String): List<ObjCTopLevel> {
|
||||
TODO("Analysis Api based 'base declaration generation' in not yet implemented")
|
||||
return KtObjCExportSession(KtObjCExportConfiguration(topLevelPrefix)) {
|
||||
objCBaseDeclarations()
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -32,7 +32,12 @@ object AnalysisApiHeaderGenerator : HeaderGenerator {
|
||||
val session = createStandaloneAnalysisApiSession(root.listFiles().orEmpty().filter { it.extension == "kt" })
|
||||
val (module, files) = session.modulesWithFiles.entries.single()
|
||||
return analyze(module) {
|
||||
KtObjCExportSession(KtObjCExportConfiguration(frameworkName = configuration.frameworkName)) {
|
||||
KtObjCExportSession(
|
||||
KtObjCExportConfiguration(
|
||||
frameworkName = configuration.frameworkName,
|
||||
generateBaseDeclarationStubs = configuration.generateBaseDeclarationStubs
|
||||
)
|
||||
) {
|
||||
translateToObjCHeader(files.map { it as KtFile })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user