From 680fec06d3740cfaad5f4cc37e6612ed24f5197d Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Mon, 4 Jul 2022 14:24:21 +0000 Subject: [PATCH] Add note comment for protected properties ^KT-51593 Fixed Merge-request: KT-MR-6593 Merged-by: Vladimir Sukharev --- .../objcexport/ObjCExportHeaderGenerator.kt | 16 +++++++++++----- .../tests/objcexport/expectedLazy.h | 6 +++++- .../objcexport/expectedLazyLegacySuspendUnit.h | 6 +++++- .../tests/objcexport/expectedLazyNoGenerics.h | 6 +++++- .../backend.native/tests/objcexport/kt51593.kt | 3 ++- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt index b4bc19e425d..1dd012740ec 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExportHeaderGenerator.kt @@ -614,7 +614,9 @@ internal class ObjCExportTranslatorImpl( val declarationAttributes = mutableListOf(swiftNameAttribute(name)) declarationAttributes.addIfNotNull(mapper.getDeprecation(property)?.toDeprecationAttribute()) - val commentOrNull = objCCommentOrNull(mustBeDocumentedAttributeList(property.annotations)) + val visibilityComments = visibilityComments(property.visibility, "property") + + val commentOrNull = objCCommentOrNull(mustBeDocumentedAttributeList(property.annotations) + visibilityComments) return ObjCProperty(name, property, type, attributes, setterName, getterName, declarationAttributes, commentOrNull) } @@ -770,10 +772,7 @@ internal class ObjCExportTranslatorImpl( } } else emptyList() - val visibilityComments = when (method.visibility) { - DescriptorVisibilities.PROTECTED -> listOf("@note This method has protected visibility in Kotlin source and is intended only for use by subclasses.") - else -> emptyList() - } + val visibilityComments = visibilityComments(method.visibility, "method") val paramComments = parameters.flatMap { parameter -> parameter.descriptor?.let { mustBeDocumentedParamAttributeList(parameter, descriptor = it) } ?: emptyList() } @@ -781,6 +780,13 @@ internal class ObjCExportTranslatorImpl( return objCCommentOrNull(annotationsComments + paramComments + throwsComments + visibilityComments) } + private fun visibilityComments(visibility: DescriptorVisibility, kind: String): List { + return when (visibility) { + DescriptorVisibilities.PROTECTED -> listOf("@note This $kind has protected visibility in Kotlin source and is intended only for use by subclasses.") + else -> emptyList() + } + } + private fun mustBeDocumentedParamAttributeList(parameter: ObjCParameter, descriptor: ParameterDescriptor): List { val mbdAnnotations = mustBeDocumentedAnnotations(descriptor.annotations).joinToString(" ") return if (mbdAnnotations.isNotEmpty()) listOf("@param ${parameter.name} annotations $mbdAnnotations") else emptyList() diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazy.h b/kotlin-native/backend.native/tests/objcexport/expectedLazy.h index 8176fda254c..d49ed5e6458 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazy.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazy.h @@ -1020,7 +1020,6 @@ __attribute__((swift_name("Bar"))) * @note This method has protected visibility in Kotlin source and is intended only for use by subclasses. */ - (void)bazNodocParam:(int32_t)nodocParam fooParam:(int32_t)fooParam completionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("baz(nodocParam:fooParam:completionHandler:)"))) __attribute__((deprecated("warning"))); -- (void)notKDoc __attribute__((swift_name("notKDoc()"))); /** My property *** @@ -1031,6 +1030,11 @@ __attribute__((swift_name("Bar"))) * BugReport(assignedTo="me", status="open") */ @property (readonly) NSString *greeting __attribute__((swift_name("greeting"))); + +/** + * @note This property has protected visibility in Kotlin source and is intended only for use by subclasses. +*/ +@property (readonly) NSString *farewell __attribute__((swift_name("farewell"))); @end __attribute__((objc_subclassing_restricted)) diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h b/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h index 8850c9dd114..116d16f4dcc 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazyLegacySuspendUnit.h @@ -958,7 +958,6 @@ __attribute__((swift_name("Bar"))) * @note This method has protected visibility in Kotlin source and is intended only for use by subclasses. */ - (void)bazNodocParam:(int32_t)nodocParam fooParam:(int32_t)fooParam completionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("baz(nodocParam:fooParam:completionHandler:)"))) __attribute__((deprecated("warning"))); -- (void)notKDoc __attribute__((swift_name("notKDoc()"))); /** * @note annotations @@ -966,6 +965,11 @@ __attribute__((swift_name("Bar"))) * BugReport(assignedTo="me", status="open") */ @property (readonly) NSString *greeting __attribute__((swift_name("greeting"))); + +/** + * @note This property has protected visibility in Kotlin source and is intended only for use by subclasses. +*/ +@property (readonly) NSString *farewell __attribute__((swift_name("farewell"))); @end __attribute__((objc_subclassing_restricted)) diff --git a/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h b/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h index 4c33c1d1515..a7ab15a2aa5 100644 --- a/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h +++ b/kotlin-native/backend.native/tests/objcexport/expectedLazyNoGenerics.h @@ -958,7 +958,6 @@ __attribute__((swift_name("Bar"))) * @note This method has protected visibility in Kotlin source and is intended only for use by subclasses. */ - (void)bazNodocParam:(int32_t)nodocParam fooParam:(int32_t)fooParam completionHandler:(void (^)(KtInt * _Nullable, NSError * _Nullable))completionHandler __attribute__((swift_name("baz(nodocParam:fooParam:completionHandler:)"))) __attribute__((deprecated("warning"))); -- (void)notKDoc __attribute__((swift_name("notKDoc()"))); /** * @note annotations @@ -966,6 +965,11 @@ __attribute__((swift_name("Bar"))) * BugReport(assignedTo="me", status="open") */ @property (readonly) NSString *greeting __attribute__((swift_name("greeting"))); + +/** + * @note This property has protected visibility in Kotlin source and is intended only for use by subclasses. +*/ +@property (readonly) NSString *farewell __attribute__((swift_name("farewell"))); @end __attribute__((objc_subclassing_restricted)) diff --git a/kotlin-native/backend.native/tests/objcexport/kt51593.kt b/kotlin-native/backend.native/tests/objcexport/kt51593.kt index 659960d1c8b..1477c6642ab 100644 --- a/kotlin-native/backend.native/tests/objcexport/kt51593.kt +++ b/kotlin-native/backend.native/tests/objcexport/kt51593.kt @@ -49,5 +49,6 @@ class Bar { } // Not a kDoc-formatted comment - fun notKDoc() {} + protected val farewell: String + get() { return "Bye bye!" } }