From 6ef2340eb5a3e0878563fff885e98e05eda6b8e3 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 20 Apr 2015 19:58:02 +0300 Subject: [PATCH] Migrate type of `throws` parameter to KClass Change declaration, testData and codegen parts for `throws` --- .../src/org/jetbrains/kotlin/codegen/FunctionCodegen.java | 6 +++--- .../compileJavaAgainstKotlin/method/throws/ClassMembers.kt | 4 ++-- .../compileJavaAgainstKotlin/method/throws/Constructor.kt | 6 +++--- .../compileJavaAgainstKotlin/method/throws/DefaultArgs.kt | 6 +++--- .../compileJavaAgainstKotlin/method/throws/Delegation.kt | 4 ++-- .../method/throws/GenericSubstitution.kt | 2 +- .../compileJavaAgainstKotlin/method/throws/TopLevel.kt | 4 ++-- .../compileJavaAgainstKotlin/method/throws/TraitMembers.kt | 4 ++-- libraries/stdlib/src/kotlin/util/JLangJVM.kt | 5 +++-- 9 files changed, 21 insertions(+), 20 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 52ed957800e..56a79cea32e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -46,7 +46,7 @@ import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage; import org.jetbrains.kotlin.resolve.calls.CallResolverUtil; import org.jetbrains.kotlin.resolve.constants.ArrayValue; import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant; -import org.jetbrains.kotlin.resolve.constants.JavaClassValue; +import org.jetbrains.kotlin.resolve.constants.KClassValue; import org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage; import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind; @@ -545,8 +545,8 @@ public class FunctionCodegen { new Function, String>() { @Override public String fun(CompileTimeConstant constant) { - if (constant instanceof JavaClassValue) { - JavaClassValue classValue = (JavaClassValue) constant; + if (constant instanceof KClassValue) { + KClassValue classValue = (KClassValue) constant; ClassDescriptor classDescriptor = DescriptorUtils.getClassDescriptorForType(classValue.getValue()); return mapper.mapClass(classDescriptor).getInternalName(); } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt index 3082d0c3cba..e8b80ecf21b 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt @@ -7,9 +7,9 @@ class Test { throws() fun none() {} - throws(javaClass()) + throws(E1::class) fun one() {} - throws(javaClass(), javaClass()) + throws(E1::class, E2::class) fun two() {} } \ No newline at end of file diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt index 2dc8d185e7d..f1fbb48d89c 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt @@ -4,7 +4,7 @@ class E1: Exception() class E2: Exception() class None [throws()]() {} -class One [throws(javaClass())]() -class Two [throws(javaClass(), javaClass())]() +class One [throws(E1::class)]() +class Two [throws(E1::class, E2::class)]() -class OneWithParam [throws(javaClass())](a: Int) \ No newline at end of file +class OneWithParam [throws(E1::class)](a: Int) \ No newline at end of file diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.kt index ee669eadd51..95a789af816 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/DefaultArgs.kt @@ -2,10 +2,10 @@ package test class E1: Exception() -throws(javaClass()) overloads +throws(E1::class) overloads fun one(a: Int = 1) {} -class One [throws(javaClass())] (a: Int = 1) { - throws(javaClass()) +class One [throws(E1::class)] (a: Int = 1) { + throws(E1::class) fun one(a: Int = 1) {} } \ No newline at end of file diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt index 4d44f4d05f3..6d11ab9149d 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt @@ -7,10 +7,10 @@ trait Trait { throws() fun none() - throws(javaClass()) + throws(E1::class) fun one() - throws(javaClass(), javaClass()) + throws(E1::class, E2::class) fun two() } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt index 91d52577b60..27154abdc6e 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt @@ -3,7 +3,7 @@ package test class E1: Exception() trait Base { - throws(javaClass()) + throws(E1::class) fun one(t: T) {} } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt index abe9c217bb3..cdc427a4c7f 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt @@ -6,8 +6,8 @@ class E2: Exception() throws() fun none() {} -throws(javaClass()) +throws(E1::class) fun one() {} -throws(javaClass(), javaClass()) +throws(E1::class, E2::class) fun two() {} \ No newline at end of file diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt index b8e49210b7a..58f97b762dc 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt @@ -7,10 +7,10 @@ trait Trait { throws() fun none() {} - throws(javaClass()) + throws(E1::class) fun one() {} - throws(javaClass(), javaClass()) + throws(E1::class, E2::class) fun two() {} } diff --git a/libraries/stdlib/src/kotlin/util/JLangJVM.kt b/libraries/stdlib/src/kotlin/util/JLangJVM.kt index 9ef9af19db3..03631ace49c 100644 --- a/libraries/stdlib/src/kotlin/util/JLangJVM.kt +++ b/libraries/stdlib/src/kotlin/util/JLangJVM.kt @@ -4,6 +4,7 @@ import java.lang.annotation.Retention import java.lang.annotation.RetentionPolicy import kotlin.jvm.internal.unsafe.* import kotlin.jvm.internal.Intrinsic +import kotlin.reflect.KClass /** * This annotation indicates what exceptions should be declared by a function when compiled to a JVM method. @@ -11,7 +12,7 @@ import kotlin.jvm.internal.Intrinsic * Example: * * ``` - * throws(javaClass()) + * throws(IOException::class) * fun readFile(name: String): String {...} * ``` * @@ -24,7 +25,7 @@ import kotlin.jvm.internal.Intrinsic * @property exceptionClasses the list of checked exception classes that may be thrown by the function. */ Retention(RetentionPolicy.SOURCE) -public annotation class throws(public vararg val exceptionClasses: Class) +public annotation class throws(public vararg val exceptionClasses: KClass) /** * Returns the runtime Java class of this object.