From 29aa2a75f9cd611c7af7a8c7f48816f38952cf00 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 16 Apr 2020 00:31:27 +0300 Subject: [PATCH] Common kotlin.Throws annotation Leave kotlin.native.Throws as a deprecated typealias #KT-34848 (cherry picked from commit 10fac5c96f915e0e008504a211ee70a3e1c9bdea) --- .../kotlin/backend/konan/KonanFqNames.kt | 2 +- runtime/src/main/kotlin/kotlin/Annotations.kt | 22 ++++++++++++++++++- .../main/kotlin/kotlin/native/Annotations.kt | 21 +++--------------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanFqNames.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanFqNames.kt index ce306653895..038dfce4097 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanFqNames.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanFqNames.kt @@ -21,7 +21,7 @@ object KonanFqNames { val nativePtr = internalPackageName.child(Name.identifier(NATIVE_PTR_NAME)).toUnsafe() val nonNullNativePtr = internalPackageName.child(Name.identifier(NON_NULL_NATIVE_PTR_NAME)).toUnsafe() val Vector128 = packageName.child(Name.identifier(VECTOR128)) - val throws = FqName("kotlin.native.Throws") + val throws = FqName("kotlin.Throws") val threadLocal = FqName("kotlin.native.concurrent.ThreadLocal") val sharedImmutable = FqName("kotlin.native.concurrent.SharedImmutable") val frozen = FqName("kotlin.native.internal.Frozen") diff --git a/runtime/src/main/kotlin/kotlin/Annotations.kt b/runtime/src/main/kotlin/kotlin/Annotations.kt index b52e88b0b06..2a908fb2ce2 100644 --- a/runtime/src/main/kotlin/kotlin/Annotations.kt +++ b/runtime/src/main/kotlin/kotlin/Annotations.kt @@ -8,6 +8,7 @@ package kotlin import kotlin.annotation.AnnotationRetention.BINARY import kotlin.annotation.AnnotationRetention.SOURCE import kotlin.annotation.AnnotationTarget.* +import kotlin.reflect.KClass /** * Marks the annotated declaration as deprecated. @@ -148,4 +149,23 @@ public annotation class DslMarker @Retention(AnnotationRetention.BINARY) @MustBeDocumented @SinceKotlin("1.1") -public annotation class PublishedApi \ No newline at end of file +public annotation class PublishedApi + +/** + * This annotation indicates what exceptions should be declared by a function when compiled to a platform method. + * + * When compiling to Objective-C/Swift framework, functions having or inheriting + * this annotation are represented as `NSError*`-producing methods in Objective-C + * and as `throws` methods in Swift. + * + * When Kotlin function called from Swift/Objective-C code throws an exception + * which is an instance of one of the [exceptionClasses] or their subclasses, + * it is propagated as `NSError`. Other Kotlin exceptions reaching Swift/Objective-C + * are considered unhandled and cause program termination. + * + * @property exceptionClasses the list of checked exception classes that may be thrown by the function. + */ +@SinceKotlin("1.4") +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR) +@Retention(AnnotationRetention.BINARY) +public actual annotation class Throws(actual vararg val exceptionClasses: KClass) diff --git a/runtime/src/main/kotlin/kotlin/native/Annotations.kt b/runtime/src/main/kotlin/kotlin/native/Annotations.kt index 77f4985e03c..cf8897d623a 100644 --- a/runtime/src/main/kotlin/kotlin/native/Annotations.kt +++ b/runtime/src/main/kotlin/kotlin/native/Annotations.kt @@ -32,24 +32,9 @@ public annotation class Retain public annotation class RetainForTarget(val target: String) -// TODO: merge with [kotlin.jvm.Throws] -/** - * This annotation indicates what exceptions should be declared by a function when compiled to a platform method. - * - * When compiling to Objective-C/Swift framework, functions having or inheriting - * this annotation are represented as `NSError*`-producing methods in Objective-C - * and as `throws` methods in Swift. - * - * When Kotlin function called from Swift/Objective-C code throws an exception - * which is an instance of one of the [exceptionClasses] or their subclasses, - * it is propagated as `NSError`. Other Kotlin exceptions reaching Swift/Objective-C - * are considered unhandled and cause program termination. - * - * @property exceptionClasses the list of checked exception classes that may be thrown by the function. - */ -@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR) -@Retention(AnnotationRetention.BINARY) -public annotation class Throws(vararg val exceptionClasses: KClass) +/** @suppress */ +@Deprecated("Use common kotlin.Throws annotation instead.", ReplaceWith("kotlin.Throws"), DeprecationLevel.WARNING) +public typealias Throws = kotlin.Throws public typealias ThreadLocal = kotlin.native.concurrent.ThreadLocal