From 4fdccb3b35fb63b971c56962c3e8aca2ad237d16 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 28 Jul 2020 12:09:37 +0300 Subject: [PATCH] JVM_IR: don't generate repeated ElementType values in @Target --- .../ir/FirBlackBoxCodegenTestGenerated.java | 5 ++++ .../AdditionalClassAnnotationLowering.kt | 2 +- .../box/annotations/annotationTargets.kt | 23 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 ++++ .../LightAnalysisModeTestGenerated.java | 5 ++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 ++++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/annotations/annotationTargets.kt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 3847803ec6a..52ad4b9e01a 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -61,6 +61,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/annotations/annotationProperty.kt"); } + @TestMetadata("annotationTargets.kt") + public void testAnnotationTargets() throws Exception { + runTest("compiler/testData/codegen/box/annotations/annotationTargets.kt"); + } + @TestMetadata("annotationWithKotlinProperty.kt") public void testAnnotationWithKotlinProperty() throws Exception { runTest("compiler/testData/codegen/box/annotations/annotationWithKotlinProperty.kt"); diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AdditionalClassAnnotationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AdditionalClassAnnotationLowering.kt index ac8e1af477c..1d10f7a411c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AdditionalClassAnnotationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AdditionalClassAnnotationLowering.kt @@ -192,7 +192,7 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC ?: throw AssertionError("No annotation target map for JVM target $jvmTarget") val targets = irClass.applicableTargetSet() ?: return - val javaTargets = targets.mapNotNull { annotationTargetMap[it] } + val javaTargets = targets.mapNotNull { annotationTargetMap[it] }.toSet() val vararg = IrVarargImpl( UNDEFINED_OFFSET, UNDEFINED_OFFSET, diff --git a/compiler/testData/codegen/box/annotations/annotationTargets.kt b/compiler/testData/codegen/box/annotations/annotationTargets.kt new file mode 100644 index 00000000000..65eaf2a613f --- /dev/null +++ b/compiler/testData/codegen/box/annotations/annotationTargets.kt @@ -0,0 +1,23 @@ +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// FULL_JDK + +@Target( + AnnotationTarget.FUNCTION, AnnotationTarget.FIELD, + AnnotationTarget.PROPERTY, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER +) +public annotation class TestAnn + +fun box(): String { + val testAnnClass = TestAnn::class.java + val targetAnn = testAnnClass.getAnnotation(java.lang.annotation.Target::class.java) + val targets = targetAnn.value + if (targets.size != 2) { + return targets.toList().toString() + } + if (targets.toSet() != setOf(java.lang.annotation.ElementType.FIELD, java.lang.annotation.ElementType.METHOD)) { + return targets.toList().toString() + } + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 37e07672a7d..4b677f600ab 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -61,6 +61,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/annotations/annotationProperty.kt"); } + @TestMetadata("annotationTargets.kt") + public void testAnnotationTargets() throws Exception { + runTest("compiler/testData/codegen/box/annotations/annotationTargets.kt"); + } + @TestMetadata("annotationWithKotlinProperty.kt") public void testAnnotationWithKotlinProperty() throws Exception { runTest("compiler/testData/codegen/box/annotations/annotationWithKotlinProperty.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index bb2b2a184b2..319f5485ca3 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -61,6 +61,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/annotations/annotationProperty.kt"); } + @TestMetadata("annotationTargets.kt") + public void testAnnotationTargets() throws Exception { + runTest("compiler/testData/codegen/box/annotations/annotationTargets.kt"); + } + @TestMetadata("annotationWithKotlinProperty.kt") public void testAnnotationWithKotlinProperty() throws Exception { runTest("compiler/testData/codegen/box/annotations/annotationWithKotlinProperty.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 6cade59e648..b0b0c3e05bc 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -61,6 +61,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/annotations/annotationProperty.kt"); } + @TestMetadata("annotationTargets.kt") + public void testAnnotationTargets() throws Exception { + runTest("compiler/testData/codegen/box/annotations/annotationTargets.kt"); + } + @TestMetadata("annotationWithKotlinProperty.kt") public void testAnnotationWithKotlinProperty() throws Exception { runTest("compiler/testData/codegen/box/annotations/annotationWithKotlinProperty.kt");