From d105ce8681025c2dd568d886852110d2d34b8480 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Fri, 13 Jan 2023 12:01:09 +0200 Subject: [PATCH] [FIR] Support typealiases to java Repeatable --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++++ .../FirRepeatableAnnotationChecker.kt | 4 ++-- .../repeatable/javaRepeatableInKotlin.kt | 13 ++++++++++ .../repeatable/javaRepeatableInKotlin.txt | 24 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ 7 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 35ea39e7be8..7eefcfa99a3 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -2371,6 +2371,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/annotations/repeatable/containerTarget_1_6.kt"); } + @Test + @TestMetadata("javaRepeatableInKotlin.kt") + public void testJavaRepeatableInKotlin() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.kt"); + } + @Test @TestMetadata("javaRepeatableJvmTarget6.kt") public void testJavaRepeatableJvmTarget6() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 7458207fc13..e90f86e5820 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -2377,6 +2377,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/annotations/repeatable/containerTarget_1_6.kt"); } + @Test + @TestMetadata("javaRepeatableInKotlin.kt") + public void testJavaRepeatableInKotlin() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.kt"); + } + @Test @TestMetadata("javaRepeatableJvmTarget6.kt") public void testJavaRepeatableJvmTarget6() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index df337400f9d..ef88d2e3e61 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -2371,6 +2371,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/annotations/repeatable/containerTarget_1_6.kt"); } + @Test + @TestMetadata("javaRepeatableInKotlin.kt") + public void testJavaRepeatableInKotlin() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.kt"); + } + @Test @TestMetadata("javaRepeatableJvmTarget6.kt") public void testJavaRepeatableJvmTarget6() throws Exception { diff --git a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt index a7077976a55..5679ba86165 100644 --- a/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt +++ b/compiler/fir/checkers/checkers.jvm/src/org/jetbrains/kotlin/fir/analysis/jvm/checkers/declaration/FirRepeatableAnnotationChecker.kt @@ -87,11 +87,11 @@ object FirRepeatableAnnotationChecker : FirBasicDeclarationChecker() { } if (declaration is FirRegularClass) { - val javaRepeatable = annotations.find { it.unexpandedClassId == StandardClassIds.Annotations.Java.Repeatable } + val javaRepeatable = annotations.getAnnotationByClassId(StandardClassIds.Annotations.Java.Repeatable, session) if (javaRepeatable != null) { checkJavaRepeatableAnnotationDeclaration(javaRepeatable, declaration, context, reporter) } else { - val kotlinRepeatable = annotations.find { it.toAnnotationClassId(session) == StandardClassIds.Annotations.Repeatable } + val kotlinRepeatable = annotations.getAnnotationByClassId(StandardClassIds.Annotations.Repeatable, session) if (kotlinRepeatable != null) { checkKotlinRepeatableAnnotationDeclaration(kotlinRepeatable, declaration, context, reporter) } diff --git a/compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.kt b/compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.kt new file mode 100644 index 00000000000..4ff05d52cc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +// FULL_JDK +// !LANGUAGE: +RepeatableAnnotations + +//import java.lang.annotation.* + +typealias Rep = java.lang.annotation.Repeatable + +@Rep(RepeatableAnnotationContainer::class) +annotation class RepeatableAnnotation +annotation class RepeatableAnnotationContainer + +@RepeatableAnnotation class Annotated diff --git a/compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.txt b/compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.txt new file mode 100644 index 00000000000..c2524d67bc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.txt @@ -0,0 +1,24 @@ +package + +@RepeatableAnnotation public final class Annotated { + public constructor Annotated() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@Rep /* = java.lang.annotation.Repeatable */(value = RepeatableAnnotationContainer::class) public final annotation class RepeatableAnnotation : kotlin.Annotation { + public constructor RepeatableAnnotation() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final annotation class RepeatableAnnotationContainer : kotlin.Annotation { + public constructor RepeatableAnnotationContainer() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} +public typealias Rep = java.lang.annotation.Repeatable + diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 3d65b5ad072..d05a466970b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -2377,6 +2377,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/annotations/repeatable/containerTarget_1_6.kt"); } + @Test + @TestMetadata("javaRepeatableInKotlin.kt") + public void testJavaRepeatableInKotlin() throws Exception { + runTest("compiler/testData/diagnostics/tests/annotations/repeatable/javaRepeatableInKotlin.kt"); + } + @Test @TestMetadata("javaRepeatableJvmTarget6.kt") public void testJavaRepeatableJvmTarget6() throws Exception {