Migrate type of throws parameter to KClass

Change declaration, testData and codegen parts for `throws`
This commit is contained in:
Denis Zharkov
2015-04-20 19:58:02 +03:00
parent e1dfdc582d
commit 6ef2340eb5
9 changed files with 21 additions and 20 deletions
@@ -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<CompileTimeConstant<?>, 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();
}
@@ -7,9 +7,9 @@ class Test {
throws()
fun none() {}
throws(javaClass<E1>())
throws(E1::class)
fun one() {}
throws(javaClass<E1>(), javaClass<E2>())
throws(E1::class, E2::class)
fun two() {}
}
@@ -4,7 +4,7 @@ class E1: Exception()
class E2: Exception()
class None [throws()]() {}
class One [throws(javaClass<E1>())]()
class Two [throws(javaClass<E1>(), javaClass<E2>())]()
class One [throws(E1::class)]()
class Two [throws(E1::class, E2::class)]()
class OneWithParam [throws(javaClass<E1>())](a: Int)
class OneWithParam [throws(E1::class)](a: Int)
@@ -2,10 +2,10 @@ package test
class E1: Exception()
throws(javaClass<E1>()) overloads
throws(E1::class) overloads
fun one(a: Int = 1) {}
class One [throws(javaClass<E1>())] (a: Int = 1) {
throws(javaClass<E1>())
class One [throws(E1::class)] (a: Int = 1) {
throws(E1::class)
fun one(a: Int = 1) {}
}
@@ -7,10 +7,10 @@ trait Trait {
throws()
fun none()
throws(javaClass<E1>())
throws(E1::class)
fun one()
throws(javaClass<E1>(), javaClass<E2>())
throws(E1::class, E2::class)
fun two()
}
@@ -3,7 +3,7 @@ package test
class E1: Exception()
trait Base<T> {
throws(javaClass<E1>())
throws(E1::class)
fun one(t: T) {}
}
@@ -6,8 +6,8 @@ class E2: Exception()
throws()
fun none() {}
throws(javaClass<E1>())
throws(E1::class)
fun one() {}
throws(javaClass<E1>(), javaClass<E2>())
throws(E1::class, E2::class)
fun two() {}
@@ -7,10 +7,10 @@ trait Trait {
throws()
fun none() {}
throws(javaClass<E1>())
throws(E1::class)
fun one() {}
throws(javaClass<E1>(), javaClass<E2>())
throws(E1::class, E2::class)
fun two() {}
}
+3 -2
View File
@@ -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<IOException>())
* 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<out Throwable>)
public annotation class throws(public vararg val exceptionClasses: KClass<out Throwable>)
/**
* Returns the runtime Java class of this object.