From 57dca2ada574dc5f3cb2b957b3c114beb3ea0565 Mon Sep 17 00:00:00 2001 From: pyos Date: Thu, 11 Apr 2019 15:55:37 +0200 Subject: [PATCH] JVM_IR: generate exception specifications --- .../kotlin/backend/jvm/codegen/FunctionCodegen.kt | 14 ++++++++++---- .../method/throws/ClassMembers.kt | 1 - .../method/throws/Constructor.kt | 1 - .../method/throws/Delegation.kt | 1 - .../method/throws/GenericSubstitution.kt | 1 - .../method/throws/TopLevel.kt | 1 - .../method/throws/TraitMembers.kt | 1 - 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index 2cbfeb6a7bc..33784786050 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -14,9 +14,8 @@ import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.types.toKotlinType -import org.jetbrains.kotlin.ir.util.dump -import org.jetbrains.kotlin.ir.util.hasAnnotation -import org.jetbrains.kotlin.ir.util.isAnnotationClass +import org.jetbrains.kotlin.ir.util.* +import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind @@ -98,12 +97,19 @@ open class FunctionCodegen( } protected open fun createMethod(flags: Int, signature: JvmMethodGenericSignature): MethodVisitor { + // @Throws(vararg exceptionClasses: KClass) + val exceptions = irFunction.getAnnotation(FqName("kotlin.jvm.Throws"))?.getValueArgument(0)?.let { + (it as IrVararg).elements.map { exceptionClass -> + classCodegen.typeMapper.mapType((exceptionClass as IrClassReference).classType.toKotlinType()).internalName + }.toTypedArray() + } + return classCodegen.visitor.newMethod( irFunction.OtherOrigin, flags, signature.asmMethod.name, signature.asmMethod.descriptor, if (irFunction.origin == IrDeclarationOrigin.BRIDGE) null else signature.genericsSignature, - null/*TODO support exception*/ + exceptions ) } diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt index b32fb9f5552..b052f2489d9 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/ClassMembers.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR package test class E1: Exception() diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt index b17950b6982..54c26c4fac2 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/Constructor.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR package test class E1: Exception() diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt index 0e5c3476404..e2793ccbecd 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/Delegation.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR package test class E1: Exception() diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt index fdcb471c316..86410a26fd0 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/GenericSubstitution.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR package test class E1: Exception() diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt index 93be86d7040..3bc77076f4b 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/TopLevel.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR package test class E1: Exception() diff --git a/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt b/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt index 7cb8d4aa816..b965f26ad08 100644 --- a/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt +++ b/compiler/testData/compileJavaAgainstKotlin/method/throws/TraitMembers.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR package test class E1: Exception()