From aece29a95b55a1a1f5ae01beb4a8c22eef6c736c Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 16 May 2018 11:57:52 +0200 Subject: [PATCH] Properly generate annotation classes --- .../jetbrains/kotlin/backend/jvm/JvmLower.kt | 1 + .../backend/jvm/codegen/FunctionCodegen.kt | 4 ++-- .../backend/jvm/lower/AnnotationLowering.kt | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AnnotationLowering.kt diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt index 405bc56dff0..f3f4f5e2d62 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt @@ -36,6 +36,7 @@ class JvmLower(val context: JvmBackendContext) { ConstAndJvmFieldPropertiesLowering().lower(irFile) PropertiesLowering().lower(irFile) + AnnotationLowering().runOnFilePostfix(irFile) //should be run before defaults lowering //Should be before interface lowering DefaultArgumentStubGenerator(context, false).runOnFilePostfix(irFile) 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 78856567486..4bf38688471 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 @@ -84,9 +84,9 @@ open class FunctionCodegen(private val irFunction: IrFunction, private val class val deprecation = 0 //TODO val bridgeFlag = 0 //TODO val modalityFlag = when ((irFunction as? IrSimpleFunction)?.modality) { - Modality.FINAL -> if (!classCodegen.irClass.isAnnotationClass) Opcodes.ACC_FINAL else 0 + Modality.FINAL -> if (!classCodegen.irClass.isAnnotationClass) Opcodes.ACC_FINAL else Opcodes.ACC_ABSTRACT Modality.ABSTRACT -> Opcodes.ACC_ABSTRACT - else -> if (classCodegen.irClass.isJvmInterface) Opcodes.ACC_ABSTRACT else 0 //TODO transform interface modality on lowering to DefaultImpls + else -> if (classCodegen.irClass.isJvmInterface && irFunction.body == null) Opcodes.ACC_ABSTRACT else 0 //TODO transform interface modality on lowering to DefaultImpls } val nativeFlag = if (irFunction.isExternal) Opcodes.ACC_NATIVE else 0 diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AnnotationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AnnotationLowering.kt new file mode 100644 index 00000000000..fef15a35b22 --- /dev/null +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AnnotationLowering.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.backend.jvm.lower + +import org.jetbrains.kotlin.backend.common.ClassLoweringPass +import org.jetbrains.kotlin.ir.declarations.IrClass +import org.jetbrains.kotlin.ir.declarations.IrConstructor +import org.jetbrains.kotlin.ir.util.isAnnotationClass + +class AnnotationLowering : ClassLoweringPass { + + override fun lower(irClass: IrClass) { + if (!irClass.isAnnotationClass) return + irClass.declarations.removeIf { + it is IrConstructor + } + } +} \ No newline at end of file