From b7de3709e46eb073303a1e8aac4c22656e4f2863 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Wed, 28 Feb 2024 09:14:35 +0100 Subject: [PATCH] [ObjCExport] Document getObjCClassOrProtocolName ^KT-65670 Fixed --- .../objcexport/getObjCClassOrProtocolName.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/native/objcexport-header-generator/impl/analysis-api/src/org/jetbrains/kotlin/objcexport/getObjCClassOrProtocolName.kt b/native/objcexport-header-generator/impl/analysis-api/src/org/jetbrains/kotlin/objcexport/getObjCClassOrProtocolName.kt index 47fe1ceaf3d..235e54f14e5 100644 --- a/native/objcexport-header-generator/impl/analysis-api/src/org/jetbrains/kotlin/objcexport/getObjCClassOrProtocolName.kt +++ b/native/objcexport-header-generator/impl/analysis-api/src/org/jetbrains/kotlin/objcexport/getObjCClassOrProtocolName.kt @@ -10,6 +10,25 @@ import org.jetbrains.kotlin.analysis.api.symbols.* import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportClassOrProtocolName import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly +/** + * Constructs the name of the given [KtClassLikeSymbol] by composing + * ``` + * {Current Framework Name}{Additional Module Prefix}{ObjC Class or Protocol Name} + * (1) (2) (3) + * ``` + * + * 1) Current Framework Name: See [KtObjCExportConfiguration.frameworkName] + * 2) Additional Module Prefix: Dependency modules that are not directly exported will add the prefix to distinguish from which + * dependency module a symbol came from. Note: This module name can be abbreviated e.g. `LongModuleName` will be `LMN` + * 3) ObjC Class or Protocol Name: This is either the name of the symbol, or the defined name in the `ObjCName` annotation + * (see [resolveObjCNameAnnotation]): e.g. + * ``` + * @ObjCName("ObjCFoo") + * class Foo + * ``` + * will use `ObjCFoo` instead of the class name `Foo` + * + */ context(KtAnalysisSession, KtObjCExportSession) fun KtClassLikeSymbol.getObjCClassOrProtocolName(): ObjCExportClassOrProtocolName { val resolvedObjCNameAnnotation = resolveObjCNameAnnotation() @@ -118,7 +137,7 @@ context(KtAnalysisSession, KtObjCExportSession) private fun KtSymbol.getObjCModuleNamePrefix(): String? { val module = getContainingModule() val moduleName = module.getObjCKotlinModuleName() ?: return null - if(moduleName == "stdlib" || moduleName == "kotlin-stdlib-common") return "Kotlin" + if (moduleName == "stdlib" || moduleName == "kotlin-stdlib-common") return "Kotlin" if (moduleName in configuration.exportedModuleNames) return null return abbreviateModuleName(moduleName) }