From 7ec19d015c5ef304541e45beaa45674b1e53e670 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Thu, 10 Feb 2022 10:42:17 +0100 Subject: [PATCH] KAPT+IR: Properly process repeatable annotation ~review fix --- .../jvm/lower/RepeatedAnnotationLowering.kt | 1 + .../testData/converter/annotations3.kt | 1 - .../testData/converter/annotations3_ir.txt | 102 ++++++++++++++++++ .../converter/repeatableAnnotations.kt | 1 - 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 plugins/kapt3/kapt3-compiler/testData/converter/annotations3_ir.txt diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/RepeatedAnnotationLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/RepeatedAnnotationLowering.kt index 6170ac0136d..60e66d5dfb5 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/RepeatedAnnotationLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/RepeatedAnnotationLowering.kt @@ -63,6 +63,7 @@ class RepeatedAnnotationLowering(private val context: JvmBackendContext) : FileL } private fun transformAnnotations(annotations: List): List { + if (!context.state.classBuilderMode.generateBodies) return annotations if (annotations.size < 2) return annotations val annotationsByClass = annotations.groupByTo(mutableMapOf()) { it.symbol.owner.constructedClass } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/annotations3.kt b/plugins/kapt3/kapt3-compiler/testData/converter/annotations3.kt index 0d7f164211b..77fa5dfcfb0 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/annotations3.kt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/annotations3.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // WITH_STDLIB interface Parceler diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/annotations3_ir.txt b/plugins/kapt3/kapt3-compiler/testData/converter/annotations3_ir.txt new file mode 100644 index 00000000000..288e254eabd --- /dev/null +++ b/plugins/kapt3/kapt3-compiler/testData/converter/annotations3_ir.txt @@ -0,0 +1,102 @@ +import java.lang.System; + +@kotlin.Metadata() +public final class B { + + public B() { + super(); + } +} + +//////////////////// + + +import java.lang.System; + +@kotlin.Metadata() +public final class BParceler implements Parceler { + @org.jetbrains.annotations.NotNull() + public static final BParceler INSTANCE = null; + + private BParceler() { + super(); + } +} + +//////////////////// + + +import java.lang.System; + +@kotlin.Metadata() +public final class C { + + public C() { + super(); + } +} + +//////////////////// + + +import java.lang.System; + +@kotlin.Metadata() +public final class CParceler implements Parceler { + @org.jetbrains.annotations.NotNull() + public static final CParceler INSTANCE = null; + + private CParceler() { + super(); + } +} + +//////////////////// + + +import java.lang.System; + +@kotlin.Metadata() +public abstract interface Parceler { +} + +//////////////////// + + +import java.lang.System; + +@TypeParceler() +@TypeParceler() +@kotlin.Metadata() +public final class Test { + + public Test() { + super(); + } +} + +//////////////////// + + +import java.lang.System; + +@kotlin.Metadata() +@java.lang.annotation.Repeatable(value = TypeParceler.Container.class) +@java.lang.annotation.Target(value = {java.lang.annotation.ElementType.TYPE}) +@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.SOURCE) +@kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.CLASS, kotlin.annotation.AnnotationTarget.PROPERTY}) +@kotlin.annotation.Repeatable() +@kotlin.annotation.Retention(value = kotlin.annotation.AnnotationRetention.SOURCE) +public abstract @interface TypeParceler> extends java.lang.annotation.Annotation { + + @kotlin.Metadata() + @java.lang.annotation.Target(value = {java.lang.annotation.ElementType.TYPE}) + @java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.SOURCE) + @kotlin.jvm.internal.RepeatableContainer() + @kotlin.annotation.Target(allowedTargets = {kotlin.annotation.AnnotationTarget.CLASS, kotlin.annotation.AnnotationTarget.PROPERTY}) + @kotlin.annotation.Retention(value = kotlin.annotation.AnnotationRetention.SOURCE) + public static abstract @interface Container { + + public abstract TypeParceler[] value(); + } +} \ No newline at end of file diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/repeatableAnnotations.kt b/plugins/kapt3/kapt3-compiler/testData/converter/repeatableAnnotations.kt index 00cb90da691..b34147ab815 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/repeatableAnnotations.kt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/repeatableAnnotations.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // FILE: lib/Anno.java package lib; public @interface Anno {