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 e5439ce6c32..f57a26fccec 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 @@ -133,11 +133,9 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC } private fun generateDocumentedAnnotation(irClass: IrClass) { - if (irClass.hasAnnotation(KotlinBuiltIns.FQ_NAMES.mustBeDocumented) && - !irClass.hasAnnotation(FqName("java.lang.annotation.Documented")) - ) { - return - } + if (!irClass.hasAnnotation(KotlinBuiltIns.FQ_NAMES.mustBeDocumented) || + irClass.hasAnnotation(FqName("java.lang.annotation.Documented")) + ) return irClass.annotations.add( IrConstructorCallImpl.fromSymbolOwner( diff --git a/compiler/testData/codegen/box/annotations/mustBeDocumented.kt b/compiler/testData/codegen/box/annotations/mustBeDocumented.kt new file mode 100644 index 00000000000..38d6f819441 --- /dev/null +++ b/compiler/testData/codegen/box/annotations/mustBeDocumented.kt @@ -0,0 +1,30 @@ +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// FULL_JDK + +import java.lang.annotation.Documented + +annotation class NoDocumented + +@MustBeDocumented +annotation class ExplicitMustBeDocumented + +@Documented +annotation class ExplicitJavaDocumented + +@MustBeDocumented +@Documented +annotation class ExplicitBoth + +inline fun isDocumented(): Boolean = + A::class.java.getDeclaredAnnotation(Documented::class.java) != null + +fun box(): String { + if (isDocumented()) return "Fail NoDocumented" + if (!isDocumented()) return "Fail ExplicitMustBeDocumented" + if (!isDocumented()) return "Fail ExplicitJavaDocumented" + if (!isDocumented()) return "Fail ExplicitBoth" + + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index d253181bc17..da6c8b8a884 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -136,6 +136,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/annotations/kt10136.kt"); } + @TestMetadata("mustBeDocumented.kt") + public void testMustBeDocumented() throws Exception { + runTest("compiler/testData/codegen/box/annotations/mustBeDocumented.kt"); + } + @TestMetadata("nestedAnnotation.kt") public void testNestedAnnotation() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 01f0ca05260..790508895c4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -141,6 +141,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/annotations/kt10136.kt"); } + @TestMetadata("mustBeDocumented.kt") + public void testMustBeDocumented() throws Exception { + runTest("compiler/testData/codegen/box/annotations/mustBeDocumented.kt"); + } + @TestMetadata("nestedAnnotation.kt") public void testNestedAnnotation() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 3023d317b18..e41e4db6985 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -136,6 +136,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/annotations/kt10136.kt"); } + @TestMetadata("mustBeDocumented.kt") + public void testMustBeDocumented() throws Exception { + runTest("compiler/testData/codegen/box/annotations/mustBeDocumented.kt"); + } + @TestMetadata("nestedAnnotation.kt") public void testNestedAnnotation() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 4f2c3361664..174749c3a51 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -136,6 +136,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/annotations/kt10136.kt"); } + @TestMetadata("mustBeDocumented.kt") + public void testMustBeDocumented() throws Exception { + runTest("compiler/testData/codegen/box/annotations/mustBeDocumented.kt"); + } + @TestMetadata("nestedAnnotation.kt") public void testNestedAnnotation() throws Exception { runTest("compiler/testData/codegen/box/annotations/nestedAnnotation.kt");