diff --git a/compiler/fir/analysis-tests/testData/enhancement/jsr305/NonNullNever.fir.txt b/compiler/fir/analysis-tests/testData/enhancement/jsr305/NonNullNever.fir.txt index 161025c1fc1..69664307a80 100644 --- a/compiler/fir/analysis-tests/testData/enhancement/jsr305/NonNullNever.fir.txt +++ b/compiler/fir/analysis-tests/testData/enhancement/jsr305/NonNullNever.fir.txt @@ -1,4 +1,4 @@ -@R|java/lang/annotation/Documented|() @R|javax/annotation/meta/TypeQualifierNickname|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.NEVER|()) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) public abstract annotation class MyNullable : R|kotlin/Annotation| { +@R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/meta/TypeQualifierNickname|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.NEVER|()) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) public abstract annotation class MyNullable : R|kotlin/Annotation| { public constructor(): R|MyNullable| } diff --git a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/FieldsAreNullable.fir.txt b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/FieldsAreNullable.fir.txt index ad6909b7480..f2cde97ce47 100644 --- a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/FieldsAreNullable.fir.txt +++ b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/FieldsAreNullable.fir.txt @@ -10,7 +10,7 @@ public constructor(): R|A| } -@R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/CheckForNull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class FieldsAreNullable : R|kotlin/Annotation| { +@R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/CheckForNull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class FieldsAreNullable : R|kotlin/Annotation| { public constructor(): R|FieldsAreNullable| } diff --git a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/ForceFlexibility.fir.txt b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/ForceFlexibility.fir.txt index f62cdd4dae6..21a4a011736 100644 --- a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/ForceFlexibility.fir.txt +++ b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/ForceFlexibility.fir.txt @@ -6,19 +6,19 @@ public constructor(): R|A| } -@R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|spr/UnknownNullability|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class ForceFlexibility : R|kotlin/Annotation| { +@R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|spr/UnknownNullability|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class ForceFlexibility : R|kotlin/Annotation| { public constructor(): R|spr/ForceFlexibility| } -@R|java/lang/annotation/Target|(R|java/lang/annotation/ElementType.TYPE|()) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { +@R|kotlin/annotation/Target|((R|kotlin/annotation/AnnotationTarget.CLASS|(), R|kotlin/annotation/AnnotationTarget.FILE|())) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { public constructor(): R|spr/NonNullApi| } -@R|java/lang/annotation/Target|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.MAYBE|()) @R|javax/annotation/meta/TypeQualifierNickname|() public abstract annotation class Nullable : R|kotlin/Annotation| { +@R|kotlin/annotation/Target|((R|kotlin/annotation/AnnotationTarget.VALUE_PARAMETER|(), R|kotlin/annotation/AnnotationTarget.FUNCTION|(), R|kotlin/annotation/AnnotationTarget.PROPERTY_GETTER|(), R|kotlin/annotation/AnnotationTarget.PROPERTY_SETTER|())) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.MAYBE|()) @R|javax/annotation/meta/TypeQualifierNickname|() public abstract annotation class Nullable : R|kotlin/Annotation| { public constructor(): R|spr/Nullable| } -@R|java/lang/annotation/Documented|() @R|javax/annotation/meta/TypeQualifierNickname|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.UNKNOWN|()) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) public abstract annotation class UnknownNullability : R|kotlin/Annotation| { +@R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/meta/TypeQualifierNickname|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.UNKNOWN|()) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) public abstract annotation class UnknownNullability : R|kotlin/Annotation| { public constructor(): R|spr/UnknownNullability| } diff --git a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/ForceFlexibleOverOverrides.fir.txt b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/ForceFlexibleOverOverrides.fir.txt index 7baebbc698e..f8d445b6f1f 100644 --- a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/ForceFlexibleOverOverrides.fir.txt +++ b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/ForceFlexibleOverOverrides.fir.txt @@ -20,15 +20,15 @@ public abstract interface B : R|kotlin/Any| { public abstract fun foobar(@R|javax/annotation/Nonnull|() x: R|@EnhancedNullability kotlin/String|): R|kotlin/Unit| } -@R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|spr/UnknownNullability|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class ForceFlexibility : R|kotlin/Annotation| { +@R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|spr/UnknownNullability|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class ForceFlexibility : R|kotlin/Annotation| { public constructor(): R|spr/ForceFlexibility| } -@R|java/lang/annotation/Target|(R|java/lang/annotation/ElementType.TYPE|()) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { +@R|kotlin/annotation/Target|((R|kotlin/annotation/AnnotationTarget.CLASS|(), R|kotlin/annotation/AnnotationTarget.FILE|())) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { public constructor(): R|spr/NonNullApi| } -@R|java/lang/annotation/Documented|() @R|javax/annotation/meta/TypeQualifierNickname|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.UNKNOWN|()) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) public abstract annotation class UnknownNullability : R|kotlin/Annotation| { +@R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/meta/TypeQualifierNickname|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.UNKNOWN|()) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) public abstract annotation class UnknownNullability : R|kotlin/Annotation| { public constructor(): R|spr/UnknownNullability| } diff --git a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/NullabilityFromOverridden.fir.txt b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/NullabilityFromOverridden.fir.txt index 64945db905e..3b098a54002 100644 --- a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/NullabilityFromOverridden.fir.txt +++ b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/NullabilityFromOverridden.fir.txt @@ -54,11 +54,11 @@ public constructor(): R|C| } -@R|java/lang/annotation/Target|(R|java/lang/annotation/ElementType.TYPE|()) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|(), R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { +@R|kotlin/annotation/Target|((R|kotlin/annotation/AnnotationTarget.CLASS|(), R|kotlin/annotation/AnnotationTarget.FILE|())) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|(), R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { public constructor(): R|NonNullApi| } -@R|java/lang/annotation/Target|(R|java/lang/annotation/ElementType.TYPE|()) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/CheckForNull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|(), R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class NullableApi : R|kotlin/Annotation| { +@R|kotlin/annotation/Target|((R|kotlin/annotation/AnnotationTarget.CLASS|(), R|kotlin/annotation/AnnotationTarget.FILE|())) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/CheckForNull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|(), R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class NullableApi : R|kotlin/Annotation| { public constructor(): R|NullableApi| } diff --git a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/OverridingDefaultQualifier.fir.txt b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/OverridingDefaultQualifier.fir.txt index 5b850fc9c7c..fba1883e27f 100644 --- a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/OverridingDefaultQualifier.fir.txt +++ b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/OverridingDefaultQualifier.fir.txt @@ -12,15 +12,15 @@ public constructor(): R|A| } -@R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/CheckForNull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class FieldsAreNullable : R|kotlin/Annotation| { +@R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/CheckForNull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class FieldsAreNullable : R|kotlin/Annotation| { public constructor(): R|FieldsAreNullable| } -@R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|(), R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { +@R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|(), R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { public constructor(): R|NonNullApi| } -@R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/CheckForNull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|(), R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class NullableApi : R|kotlin/Annotation| { +@R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/CheckForNull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|(), R|java/lang/annotation/ElementType.FIELD|())) public abstract annotation class NullableApi : R|kotlin/Annotation| { public constructor(): R|NullableApi| } diff --git a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/SpringNullable.fir.txt b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/SpringNullable.fir.txt index 5568d4bb56f..05de5093d12 100644 --- a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/SpringNullable.fir.txt +++ b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/SpringNullable.fir.txt @@ -10,11 +10,11 @@ public constructor(): R|A| } -@R|java/lang/annotation/Target|(R|java/lang/annotation/ElementType.TYPE|()) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { +@R|kotlin/annotation/Target|((R|kotlin/annotation/AnnotationTarget.CLASS|(), R|kotlin/annotation/AnnotationTarget.FILE|())) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { public constructor(): R|spr/NonNullApi| } -@R|java/lang/annotation/Target|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.MAYBE|()) @R|javax/annotation/meta/TypeQualifierNickname|() public abstract annotation class Nullable : R|kotlin/Annotation| { +@R|kotlin/annotation/Target|((R|kotlin/annotation/AnnotationTarget.VALUE_PARAMETER|(), R|kotlin/annotation/AnnotationTarget.FUNCTION|(), R|kotlin/annotation/AnnotationTarget.PROPERTY_GETTER|(), R|kotlin/annotation/AnnotationTarget.PROPERTY_SETTER|())) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.MAYBE|()) @R|javax/annotation/meta/TypeQualifierNickname|() public abstract annotation class Nullable : R|kotlin/Annotation| { public constructor(): R|spr/Nullable| } diff --git a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/SpringNullablePackage.fir.txt b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/SpringNullablePackage.fir.txt index cbf1eb777ed..dab4e6f8265 100644 --- a/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/SpringNullablePackage.fir.txt +++ b/compiler/fir/analysis-tests/testData/enhancement/jsr305/typeQualifierDefault/SpringNullablePackage.fir.txt @@ -10,11 +10,11 @@ public open class A : R|kotlin/Any| { public constructor(): R|test/A| } -@R|java/lang/annotation/Target|(R|java/lang/annotation/ElementType.PACKAGE|()) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { +@R|kotlin/annotation/Target|(()) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/Nonnull|() @R|javax/annotation/meta/TypeQualifierDefault|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) public abstract annotation class NonNullApi : R|kotlin/Annotation| { public constructor(): R|spr/NonNullApi| } -@R|java/lang/annotation/Target|((R|java/lang/annotation/ElementType.METHOD|(), R|java/lang/annotation/ElementType.PARAMETER|())) @R|java/lang/annotation/Retention|(R|java/lang/annotation/RetentionPolicy.RUNTIME|()) @R|java/lang/annotation/Documented|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.MAYBE|()) @R|javax/annotation/meta/TypeQualifierNickname|() public abstract annotation class Nullable : R|kotlin/Annotation| { +@R|kotlin/annotation/Target|((R|kotlin/annotation/AnnotationTarget.VALUE_PARAMETER|(), R|kotlin/annotation/AnnotationTarget.FUNCTION|(), R|kotlin/annotation/AnnotationTarget.PROPERTY_GETTER|(), R|kotlin/annotation/AnnotationTarget.PROPERTY_SETTER|())) @R|kotlin/annotation/Retention|(R|kotlin/annotation/AnnotationRetention.RUNTIME|()) @R|kotlin/annotation/MustBeDocumented|() @R|javax/annotation/Nonnull|(R|javax/annotation/meta/When.MAYBE|()) @R|javax/annotation/meta/TypeQualifierNickname|() public abstract annotation class Nullable : R|kotlin/Annotation| { public constructor(): R|spr/Nullable| } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 4dad0e4eac1..6796fc5b928 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -121,6 +121,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/annotations/fileClassWithFileAnnotation.kt"); } + @TestMetadata("javaAnnotationOnProperty.kt") + public void testJavaAnnotationOnProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/javaAnnotationOnProperty.kt"); + } + @TestMetadata("jvmAnnotationFlags.kt") public void testJvmAnnotationFlags() throws Exception { runTest("compiler/testData/codegen/box/annotations/jvmAnnotationFlags.kt"); diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt index 2559a9b40ac..4d2a66e9394 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/JavaUtils.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.java +import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality @@ -43,9 +44,15 @@ import org.jetbrains.kotlin.load.java.structure.* import org.jetbrains.kotlin.load.java.structure.impl.JavaElementImpl import org.jetbrains.kotlin.load.java.typeEnhancement.TypeComponentPosition import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance.* import org.jetbrains.kotlin.utils.addToStdlib.runIf +import java.lang.Deprecated +import java.lang.annotation.Documented +import java.lang.annotation.Retention +import java.lang.annotation.Target +import java.util.* internal val JavaModifierListOwner.modality: Modality get() = when { @@ -421,52 +428,121 @@ private fun FirRegularClass.createRawArguments( computeRawProjection(session, typeParameter, position, erasedUpperBound) } -private fun FirAnnotationCallBuilder.buildArgumentMapping( +private fun buildEnumCall(session: FirSession, classId: ClassId?, entryName: Name?) = + buildFunctionCall { + val calleeReference = if (classId != null && entryName != null) { + session.firSymbolProvider.getClassDeclaredPropertySymbols(classId, entryName) + .firstOrNull()?.let { propertySymbol -> + buildResolvedNamedReference { + name = entryName + resolvedSymbol = propertySymbol + } + } + } else { + null + } + this.calleeReference = calleeReference + ?: buildErrorNamedReference { + diagnostic = ConeSimpleDiagnostic("Strange Java enum value: $classId.$entryName", DiagnosticKind.Java) + } + } + +private val JAVA_TARGET_CLASS_ID = ClassId.topLevel(FqName(Target::class.java.canonicalName)) +private val JAVA_RETENTION_CLASS_ID = ClassId.topLevel(FqName(Retention::class.java.canonicalName)) +private val JAVA_DEPRECATED_CLASS_ID = ClassId.topLevel(FqName(Deprecated::class.java.canonicalName)) +private val JAVA_DOCUMENTED_CLASS_ID = ClassId.topLevel(FqName(Documented::class.java.canonicalName)) +private val JAVA_REPEATABLE_CLASS_ID = ClassId.topLevel(FqName("java.lang.annotation.Repeatable")) // since Java 8 + +private val JAVA_TARGETS_TO_KOTLIN = mapOf( + "TYPE" to EnumSet.of(AnnotationTarget.CLASS, AnnotationTarget.FILE), + "ANNOTATION_TYPE" to EnumSet.of(AnnotationTarget.ANNOTATION_CLASS), + "TYPE_PARAMETER" to EnumSet.of(AnnotationTarget.TYPE_PARAMETER), + "FIELD" to EnumSet.of(AnnotationTarget.FIELD), + "LOCAL_VARIABLE" to EnumSet.of(AnnotationTarget.LOCAL_VARIABLE), + "PARAMETER" to EnumSet.of(AnnotationTarget.VALUE_PARAMETER), + "CONSTRUCTOR" to EnumSet.of(AnnotationTarget.CONSTRUCTOR), + "METHOD" to EnumSet.of(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER), + "TYPE_USE" to EnumSet.of(AnnotationTarget.TYPE) +) + +private fun List.mapJavaTargetArguments(session: FirSession): FirExpression? = + buildArrayOfCall { + argumentList = buildArgumentList { + val resultSet = EnumSet.noneOf(AnnotationTarget::class.java) + for (target in this@mapJavaTargetArguments) { + if (target !is JavaEnumValueAnnotationArgument) return null + resultSet.addAll(JAVA_TARGETS_TO_KOTLIN[target.entryName?.asString()] ?: continue) + } + val classId = ClassId.topLevel(StandardNames.FqNames.annotationTarget) + resultSet.mapTo(arguments) { buildEnumCall(session, classId, Name.identifier(it.name)) } + } + } + +private val JAVA_RETENTION_TO_KOTLIN = mapOf( + "RUNTIME" to AnnotationRetention.RUNTIME, + "CLASS" to AnnotationRetention.BINARY, + "SOURCE" to AnnotationRetention.SOURCE +) + +private fun JavaAnnotationArgument.mapJavaRetentionArgument(session: FirSession): FirExpression? = + JAVA_RETENTION_TO_KOTLIN[(this as? JavaEnumValueAnnotationArgument)?.entryName?.asString()]?.let { + buildEnumCall(session, ClassId.topLevel(StandardNames.FqNames.annotationRetention), Name.identifier(it.name)) + } + +private fun buildArgumentMapping( session: FirSession, javaTypeParameterStack: JavaTypeParameterStack, - classId: ClassId?, + lookupTag: ConeClassLikeLookupTagImpl, annotationArguments: Collection -): LinkedHashMap? { - if (classId == null) { - annotationTypeRef = buildErrorTypeRef { diagnostic = ConeUnresolvedReferenceError() } +): FirArgumentList? { + if (annotationArguments.none { it.name != null }) { return null } - val lookupTag = ConeClassLikeLookupTagImpl(classId) - annotationTypeRef = buildResolvedTypeRef { - type = ConeClassLikeTypeImpl(lookupTag, emptyArray(), isNullable = false) + val annotationClassSymbol = session.firSymbolProvider.getClassLikeSymbolByFqName(lookupTag.classId).also { + lookupTag.bindSymbolToLookupTag(session, it) + } ?: return null + val annotationConstructor = + (annotationClassSymbol.fir as FirRegularClass).declarations.filterIsInstance().first() + val mapping = annotationArguments.associateTo(linkedMapOf()) { argument -> + val parameter = annotationConstructor.valueParameters.find { it.name == (argument.name ?: JavaSymbolProvider.VALUE_METHOD_NAME) } + ?: return null + argument.toFirExpression(session, javaTypeParameterStack) to parameter } - if (annotationArguments.any { it.name != null }) { - val mapping = linkedMapOf() - val annotationClassSymbol = session.firSymbolProvider.getClassLikeSymbolByFqName(classId).also { - lookupTag.bindSymbolToLookupTag(session, it) - } - if (annotationClassSymbol != null) { - val annotationConstructor = - (annotationClassSymbol.fir as FirRegularClass).declarations.filterIsInstance().first() - for (argument in annotationArguments) { - mapping[argument.toFirExpression(session, javaTypeParameterStack)] = - annotationConstructor.valueParameters.find { it.name == (argument.name ?: JavaSymbolProvider.VALUE_METHOD_NAME) } - ?: return null - } - return mapping - } - } - return null + return buildResolvedArgumentList(mapping) } internal fun JavaAnnotation.toFirAnnotationCall( session: FirSession, javaTypeParameterStack: JavaTypeParameterStack ): FirAnnotationCall { return buildAnnotationCall { - val mapping = buildArgumentMapping(session, javaTypeParameterStack, classId, arguments) - argumentList = if (mapping != null) { - buildResolvedArgumentList(mapping) - } else { - buildArgumentList { - for (argument in this@toFirAnnotationCall.arguments) { - arguments += argument.toFirExpression(session, javaTypeParameterStack) - } + val lookupTag = when (classId) { + JAVA_TARGET_CLASS_ID -> ClassId.topLevel(StandardNames.FqNames.target) + JAVA_RETENTION_CLASS_ID -> ClassId.topLevel(StandardNames.FqNames.retention) + JAVA_REPEATABLE_CLASS_ID -> ClassId.topLevel(StandardNames.FqNames.repeatable) + JAVA_DOCUMENTED_CLASS_ID -> ClassId.topLevel(StandardNames.FqNames.mustBeDocumented) + JAVA_DEPRECATED_CLASS_ID -> ClassId.topLevel(StandardNames.FqNames.deprecated) + else -> classId + }?.let(::ConeClassLikeLookupTagImpl) + annotationTypeRef = if (lookupTag != null) { + buildResolvedTypeRef { + type = ConeClassLikeTypeImpl(lookupTag, emptyArray(), isNullable = false) } + } else { + buildErrorTypeRef { diagnostic = ConeUnresolvedReferenceError() } + } + argumentList = when (classId) { + JAVA_TARGET_CLASS_ID -> when (val argument = arguments.singleOrNull()) { + is JavaArrayAnnotationArgument -> argument.getElements().mapJavaTargetArguments(session)?.let(::buildUnaryArgumentList) + is JavaEnumValueAnnotationArgument -> listOf(argument).mapJavaTargetArguments(session)?.let(::buildUnaryArgumentList) + else -> null + } + JAVA_RETENTION_CLASS_ID -> arguments.singleOrNull()?.mapJavaRetentionArgument(session)?.let(::buildUnaryArgumentList) + JAVA_DEPRECATED_CLASS_ID -> + buildUnaryArgumentList(buildConstExpression(null, FirConstKind.String, "Deprecated in Java").setProperType(session)) + null -> null + else -> buildArgumentMapping(session, javaTypeParameterStack, lookupTag!!, arguments) + } ?: buildArgumentList { + this@toFirAnnotationCall.arguments.mapTo(arguments) { it.toFirExpression(session, javaTypeParameterStack) } } calleeReference = FirReferencePlaceholderForResolvedAnnotations } @@ -490,9 +566,7 @@ internal fun MutableList.addAnnotationsFrom( javaAnnotationOwner: JavaAnnotationOwner, javaTypeParameterStack: JavaTypeParameterStack ) { - for (annotation in javaAnnotationOwner.annotations) { - this += annotation.toFirAnnotationCall(session, javaTypeParameterStack) - } + javaAnnotationOwner.annotations.mapTo(this) { it.toFirAnnotationCall(session, javaTypeParameterStack) } } internal fun JavaValueParameter.toFirValueParameter( @@ -540,46 +614,18 @@ private fun JavaType?.toConeProjectionWithoutEnhancement( private fun JavaAnnotationArgument.toFirExpression( session: FirSession, javaTypeParameterStack: JavaTypeParameterStack ): FirExpression { - // TODO: this.name return when (this) { - is JavaLiteralAnnotationArgument -> { - value.createConstantOrError(session) - } + is JavaLiteralAnnotationArgument -> value.createConstantOrError(session) is JavaArrayAnnotationArgument -> buildArrayOfCall { argumentList = buildArgumentList { - for (element in getElements()) { - arguments += element.toFirExpression(session, javaTypeParameterStack) - } - } - } - is JavaEnumValueAnnotationArgument -> { - buildFunctionCall { - val classId = this@toFirExpression.enumClassId - val entryName = this@toFirExpression.entryName - val calleeReference = if (classId != null && entryName != null) { - val propertySymbol = session.firSymbolProvider.getClassDeclaredPropertySymbols( - classId, entryName - ).firstOrNull() - propertySymbol?.let { - buildResolvedNamedReference { - name = entryName - resolvedSymbol = it - } - } - } else { - null - } - this.calleeReference = calleeReference - ?: buildErrorNamedReference { - diagnostic = ConeSimpleDiagnostic("Strange Java enum value: $classId.$entryName", DiagnosticKind.Java) - } + getElements().mapTo(arguments) { it.toFirExpression(session, javaTypeParameterStack) } } } + is JavaEnumValueAnnotationArgument -> buildEnumCall(session, enumClassId, entryName) is JavaClassObjectAnnotationArgument -> buildGetClassCall { - val referencedType = getReferencedType() argumentList = buildUnaryArgumentList( buildClassReferenceExpression { - classTypeRef = referencedType.toFirResolvedTypeRef(session, javaTypeParameterStack) + classTypeRef = getReferencedType().toFirResolvedTypeRef(session, javaTypeParameterStack) } ) } diff --git a/compiler/testData/codegen/box/annotations/javaAnnotationOnProperty.kt b/compiler/testData/codegen/box/annotations/javaAnnotationOnProperty.kt new file mode 100644 index 00000000000..dd90a8b7781 --- /dev/null +++ b/compiler/testData/codegen/box/annotations/javaAnnotationOnProperty.kt @@ -0,0 +1,25 @@ +// WITH_REFLECT +// TARGET_BACKEND: JVM +// FILE: Ann1.java +import java.lang.annotation.*; + +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Ann1 {} + +// FILE: Ann2.java +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Ann2 {} + +// FILE: box.kt +class C { + @Ann1 @Ann2 val x = 1 +} + +fun box(): String { + require(C::class.java.getDeclaredField("x")?.getAnnotation(Ann1::class.java) != null) { "no Ann1 on field x" } + require(C::class.java.getDeclaredMethod("getX\$annotations")?.getAnnotation(Ann2::class.java) != null) { "no Ann2 on property x" } + return "OK" +} diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 4c23c7115b6..1a8ed41a92b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -121,6 +121,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/annotations/fileClassWithFileAnnotation.kt"); } + @TestMetadata("javaAnnotationOnProperty.kt") + public void testJavaAnnotationOnProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/javaAnnotationOnProperty.kt"); + } + @TestMetadata("jvmAnnotationFlags.kt") public void testJvmAnnotationFlags() throws Exception { runTest("compiler/testData/codegen/box/annotations/jvmAnnotationFlags.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 4e9d7f19813..c38c8b2a820 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -121,6 +121,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/annotations/fileClassWithFileAnnotation.kt"); } + @TestMetadata("javaAnnotationOnProperty.kt") + public void testJavaAnnotationOnProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/javaAnnotationOnProperty.kt"); + } + @TestMetadata("jvmAnnotationFlags.kt") public void testJvmAnnotationFlags() throws Exception { runTest("compiler/testData/codegen/box/annotations/jvmAnnotationFlags.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 71a78e1ba65..067da877c88 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -121,6 +121,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/annotations/fileClassWithFileAnnotation.kt"); } + @TestMetadata("javaAnnotationOnProperty.kt") + public void testJavaAnnotationOnProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/javaAnnotationOnProperty.kt"); + } + @TestMetadata("jvmAnnotationFlags.kt") public void testJvmAnnotationFlags() throws Exception { runTest("compiler/testData/codegen/box/annotations/jvmAnnotationFlags.kt"); diff --git a/idea/idea-frontend-fir/testData/memberScopeByFqName/java.lang.String.txt b/idea/idea-frontend-fir/testData/memberScopeByFqName/java.lang.String.txt index b40688f7b5d..1a965951b13 100644 --- a/idea/idea-frontend-fir/testData/memberScopeByFqName/java.lang.String.txt +++ b/idea/idea-frontend-fir/testData/memberScopeByFqName/java.lang.String.txt @@ -242,7 +242,7 @@ KtFirFunctionSymbol: visibility: PUBLIC KtFirFunctionSymbol: - annotations: [java/lang/Deprecated()] + annotations: [kotlin/Deprecated(message = Deprecated in Java)] callableIdIfNonLocal: java.lang.String.getBytes isExtension: false isExternal: false @@ -1166,7 +1166,7 @@ KtFirConstructorSymbol: visibility: PUBLIC KtFirConstructorSymbol: - annotations: [java/lang/Deprecated()] + annotations: [kotlin/Deprecated(message = Deprecated in Java)] containingClassIdIfNonLocal: java/lang/String isPrimary: false origin: JAVA @@ -1176,7 +1176,7 @@ KtFirConstructorSymbol: visibility: PUBLIC KtFirConstructorSymbol: - annotations: [java/lang/Deprecated()] + annotations: [kotlin/Deprecated(message = Deprecated in Java)] containingClassIdIfNonLocal: java/lang/String isPrimary: false origin: JAVA @@ -1276,7 +1276,7 @@ KtFirConstructorSymbol: visibility: UNKNOWN KtFirConstructorSymbol: - annotations: [java/lang/Deprecated()] + annotations: [kotlin/Deprecated(message = Deprecated in Java)] containingClassIdIfNonLocal: java/lang/String isPrimary: false origin: JAVA