diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index c0e4a77fcef..0480a27a6b3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -522,7 +522,11 @@ public class FunctionCodegen { @NotNull public static String[] getThrownExceptions(@NotNull FunctionDescriptor function, @NotNull final JetTypeMapper mapper) { - AnnotationDescriptor annotation = function.getAnnotations().findAnnotation(new FqName("kotlin.Throws")); + AnnotationDescriptor annotation = function.getAnnotations().findAnnotation(new FqName("kotlin.throws")); + if (annotation == null) { + annotation = function.getAnnotations().findAnnotation(new FqName("kotlin.jvm.Throws")); + } + if (annotation == null) return ArrayUtil.EMPTY_STRING_ARRAY; Collection> values = annotation.getAllValueArguments().values(); diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/decapitalized.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/decapitalized.kt index ccd1eba5aab..a076a659c4f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/decapitalized.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/decapitalized.kt @@ -7,7 +7,7 @@ class A { @jvmStatic fun bar() {} } - throws(java.lang.RuntimeException::class) + throws(java.lang.RuntimeException::class) synchronized fun baz() { @suppress("UNCHECKED_CAST") (1 as T) diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/decapitalized.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/decapitalized.txt index bf88d070489..3c49fba5487 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/decapitalized.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/decapitalized.txt @@ -4,7 +4,7 @@ kotlin.jvm.Strictfp() public fun bar(/*0*/ x: kotlin.Deprecated): @[kotlin.Exten public final class A { public constructor A() - kotlin.Throws(exceptionClasses = {java.lang.RuntimeException::class}) kotlin.jvm.Synchronized() public final fun baz(): kotlin.Unit + kotlin.throws(exceptionClasses = {java.lang.RuntimeException::class}) kotlin.jvm.Synchronized() public final fun baz(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean kotlin.Deprecated(value = "") public final fun foo(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/DecapitalizedAnnotationScope.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/DecapitalizedAnnotationScope.kt index 43edc71d483..9ddc3d5ba50 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/DecapitalizedAnnotationScope.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/DecapitalizedAnnotationScope.kt @@ -25,7 +25,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe val DECAPITALIZED_DEPRECATED_ANNOTATIONS = arrayOf( - "Deprecated", "Extension", "Suppress", "Throws", + "Deprecated", "Extension", "Suppress", "jvm.Volatile", "jvm.Transient", "jvm.Strictfp", "jvm.Synchronized", "jvm.JvmOverloads", "jvm.JvmName", "jvm.JvmStatic", "annotation.Target" ).map { FqName("kotlin.$it") }.toSet() diff --git a/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt b/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt index 76f51207250..1e52a82d23f 100644 --- a/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt +++ b/libraries/stdlib/src/kotlin/jvm/JvmPlatformAnnotations.kt @@ -16,6 +16,8 @@ package kotlin.jvm +import kotlin.reflect.KClass + /** * Instructs the Kotlin compiler to generate overloads for this function that substitute default parameter values. * @@ -64,4 +66,25 @@ public annotation class JvmMultifileClass @Target(AnnotationTarget.FIELD) @Retention(AnnotationRetention.SOURCE) @MustBeDocumented -public annotation class publicField \ No newline at end of file +public annotation class publicField + +/** + * This annotation indicates what exceptions should be declared by a function when compiled to a JVM method. + * + * Example: + * + * ``` + * throws(IOException::class) + * fun readFile(name: String): String {...} + * ``` + * + * will be translated to + * + * ``` + * String readFile(String name) throws IOException {...} + * ``` + * + * @property exceptionClasses the list of checked exception classes that may be thrown by the function. + */ +@Retention(AnnotationRetention.SOURCE) +public annotation class Throws(public vararg val exceptionClasses: KClass) diff --git a/libraries/stdlib/src/kotlin/util/JLangJVM.kt b/libraries/stdlib/src/kotlin/util/JLangJVM.kt index 450a6522b65..7d8ff4a93d9 100644 --- a/libraries/stdlib/src/kotlin/util/JLangJVM.kt +++ b/libraries/stdlib/src/kotlin/util/JLangJVM.kt @@ -23,7 +23,8 @@ import kotlin.reflect.KClass * @property exceptionClasses the list of checked exception classes that may be thrown by the function. */ @Retention(AnnotationRetention.SOURCE) -public annotation class Throws(public vararg val exceptionClasses: KClass) +@Deprecated("Use 'kotlin.jvm.Throws' instead", ReplaceWith("kotlin.jvm.Throws")) +public annotation class throws(public vararg val exceptionClasses: KClass) /** * Returns the runtime Java class of this object.