diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/RepeatableAnnotationChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/RepeatableAnnotationChecker.kt index d049b5ceb12..3014402a271 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/RepeatableAnnotationChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/RepeatableAnnotationChecker.kt @@ -103,10 +103,10 @@ class RepeatableAnnotationChecker( ) if (nestedClassNamedContainer != null) { trace.report( - select( - ErrorsJvm.REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER, - ErrorsJvm.REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER_ERROR - ).on(kotlinRepeatable.entry) + ErrorsJvm.REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER.on( + languageVersionSettings, + kotlinRepeatable.entry + ) ) } } @@ -170,16 +170,14 @@ class RepeatableAnnotationChecker( if (value == null || !KotlinBuiltIns.isArray(value.type) || value.type.arguments.single().type.constructor.declarationDescriptor != annotationClass ) { - return select( - ErrorsJvm.REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY, ErrorsJvm.REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY_ERROR - ).on(reportOn, containerClass.fqNameSafe, annotationClass.fqNameSafe) + return ErrorsJvm.REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY + .on(languageVersionSettings, reportOn, containerClass.fqNameSafe, annotationClass.fqNameSafe) } val otherNonDefault = containerCtor.valueParameters.find { it.name.asString() != "value" && !it.declaresDefaultValue() } if (otherNonDefault != null) { - return select( - ErrorsJvm.REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER, ErrorsJvm.REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER_ERROR - ).on(reportOn, containerClass.fqNameSafe, otherNonDefault) + return ErrorsJvm.REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER + .on(languageVersionSettings, reportOn, containerClass.fqNameSafe, otherNonDefault) } return null @@ -193,9 +191,15 @@ class RepeatableAnnotationChecker( val annotationRetention = annotationClass.getAnnotationRetention() ?: KotlinRetention.RUNTIME val containerRetention = containerClass.getAnnotationRetention() ?: KotlinRetention.RUNTIME if (containerRetention > annotationRetention) { - return select( - ErrorsJvm.REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION, ErrorsJvm.REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION_ERROR - ).on(reportOn, containerClass.fqNameSafe, containerRetention.name, annotationClass.fqNameSafe, annotationRetention.name) + return ErrorsJvm.REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION + .on( + languageVersionSettings, + reportOn, + containerClass.fqNameSafe, + containerRetention.name, + annotationClass.fqNameSafe, + annotationRetention.name + ) } return null } @@ -224,21 +228,14 @@ class RepeatableAnnotationChecker( else -> false } if (!ok) { - return select( - ErrorsJvm.REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET, ErrorsJvm.REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET_ERROR - ).on(reportOn, containerClass.fqNameSafe, annotationClass.fqNameSafe) + return ErrorsJvm.REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET + .on(languageVersionSettings, reportOn, containerClass.fqNameSafe, annotationClass.fqNameSafe) } } return null } - private fun select(warning: D, error: D): D = - if (languageVersionSettings.supportsFeature(LanguageFeature.RepeatableAnnotationContainerConstraints)) - error - else - warning - private fun isRepeatableAnnotation(classDescriptor: ClassDescriptor): Boolean = classDescriptor.isAnnotatedWithKotlinRepeatable() || platformAnnotationFeaturesSupport.isRepeatableAnnotationClass(classDescriptor) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java index a60c8af155e..557b38c6557 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java @@ -76,15 +76,10 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension { MAP.put(ANNOTATION_IS_NOT_APPLICABLE_TO_MULTIFILE_CLASSES, "Annotation ''@{0}'' is not applicable to the multi-file classes", TO_STRING); MAP.put(REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY, "Container annotation ''{0}'' must have a property ''value'' of type ''Array<{1}>''. This code will be prohibited in Kotlin 1.6", TO_STRING, TO_STRING); - MAP.put(REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY_ERROR, "Container annotation ''{0}'' must have a property ''value'' of type ''Array<{1}>''", TO_STRING, TO_STRING); MAP.put(REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER, "Container annotation ''{0}'' does not have a default value for ''{1}''. This code will be prohibited in Kotlin 1.6", TO_STRING, NAME); - MAP.put(REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER_ERROR, "Container annotation ''{0}'' does not have a default value for ''{1}''", TO_STRING, NAME); MAP.put(REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION, "Container annotation ''{0}'' has shorter retention (''{1}'') than the repeatable annotation ''{2}'' (''{3}''). This code will be prohibited in Kotlin 1.6", TO_STRING, TO_STRING, TO_STRING, TO_STRING); - MAP.put(REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION_ERROR, "Container annotation ''{0}'' has shorter retention (''{1}'') than the repeatable annotation ''{2}'' (''{3}'')", TO_STRING, TO_STRING, TO_STRING, TO_STRING); MAP.put(REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET, "Target set of container annotation ''{0}'' must be a subset of the target set of contained annotation ''{1}''. This code will be prohibited in Kotlin 1.6", TO_STRING, TO_STRING); - MAP.put(REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET_ERROR, "Target set of container annotation ''{0}'' must be a subset of the target set of contained annotation ''{1}''", TO_STRING, TO_STRING); MAP.put(REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER, "Repeatable annotation cannot have a nested class named 'Container'. This name is reserved for auto-generated container class"); - MAP.put(REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER_ERROR, "Repeatable annotation cannot have a nested class named 'Container'. This name is reserved for auto-generated container class"); MAP.put(JVM_PACKAGE_NAME_CANNOT_BE_EMPTY, "''@JvmPackageName'' annotation value cannot be empty"); MAP.put(JVM_PACKAGE_NAME_MUST_BE_VALID_NAME, "''@JvmPackageName'' annotation value must be a valid dot-qualified name of a package"); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java index fc7256346e3..8196dd37e2c 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java @@ -75,16 +75,11 @@ public interface ErrorsJvm { DiagnosticFactory0 REPEATED_ANNOTATION_TARGET6 = DiagnosticFactory0.create(ERROR); DiagnosticFactory2 REPEATED_ANNOTATION_WITH_CONTAINER = DiagnosticFactory2.create(ERROR); - DiagnosticFactory2 REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY = DiagnosticFactory2.create(WARNING); - DiagnosticFactory2 REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY_ERROR = DiagnosticFactory2.create(ERROR); - DiagnosticFactory2 REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER = DiagnosticFactory2.create(WARNING); - DiagnosticFactory2 REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER_ERROR = DiagnosticFactory2.create(ERROR); - DiagnosticFactory4 REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION = DiagnosticFactory4.create(WARNING); - DiagnosticFactory4 REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION_ERROR = DiagnosticFactory4.create(ERROR); - DiagnosticFactory2 REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET = DiagnosticFactory2.create(WARNING); - DiagnosticFactory2 REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET_ERROR = DiagnosticFactory2.create(ERROR); - DiagnosticFactory0 REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER = DiagnosticFactory0.create(WARNING); - DiagnosticFactory0 REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER_ERROR = DiagnosticFactory0.create(WARNING); + DiagnosticFactoryForDeprecation2 REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY = DiagnosticFactoryForDeprecation2.create(LanguageFeature.RepeatableAnnotationContainerConstraints); + DiagnosticFactoryForDeprecation2 REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER = DiagnosticFactoryForDeprecation2.create(LanguageFeature.RepeatableAnnotationContainerConstraints); + DiagnosticFactoryForDeprecation4 REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION = DiagnosticFactoryForDeprecation4.create(LanguageFeature.RepeatableAnnotationContainerConstraints); + DiagnosticFactoryForDeprecation2 REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET = DiagnosticFactoryForDeprecation2.create(LanguageFeature.RepeatableAnnotationContainerConstraints); + DiagnosticFactoryForDeprecation0 REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER = DiagnosticFactoryForDeprecation0.create(LanguageFeature.RepeatableAnnotationContainerConstraints); DiagnosticFactory1 ANNOTATION_IS_NOT_APPLICABLE_TO_MULTIFILE_CLASSES = DiagnosticFactory1.create(ERROR); diff --git a/compiler/testData/diagnostics/tests/annotations/repeatable/containerArguments_1_5.kt b/compiler/testData/diagnostics/tests/annotations/repeatable/containerArguments_1_5.kt index e9ae5028c0d..9ef38567382 100644 --- a/compiler/testData/diagnostics/tests/annotations/repeatable/containerArguments_1_5.kt +++ b/compiler/testData/diagnostics/tests/annotations/repeatable/containerArguments_1_5.kt @@ -3,27 +3,27 @@ import java.lang.annotation.Repeatable as R -@R(C1::class) +@R(C1::class) annotation class A1 annotation class C1 -@R(C2::class) +@R(C2::class) annotation class A2 annotation class C2(val value: A2) -@R(C3::class) +@R(C3::class) annotation class A3 annotation class C3(val value: Array) -@R(C4::class) +@R(C4::class) annotation class A4 annotation class C4(val notValue: Array) -@R(C5::class) +@R(C5::class) annotation class A5 annotation class C5(val value: Array, val irrelevant: String) -@R(C6::class) +@R(C6::class) annotation class A6 annotation class C6(val irrelevant: Double, val value: Array = []) diff --git a/compiler/testData/diagnostics/tests/annotations/repeatable/containerRetention_1_5.kt b/compiler/testData/diagnostics/tests/annotations/repeatable/containerRetention_1_5.kt index 3b83f655f40..079f6563014 100644 --- a/compiler/testData/diagnostics/tests/annotations/repeatable/containerRetention_1_5.kt +++ b/compiler/testData/diagnostics/tests/annotations/repeatable/containerRetention_1_5.kt @@ -4,19 +4,19 @@ import java.lang.annotation.Repeatable as R import kotlin.annotation.AnnotationRetention.* -@R(C1::class) +@R(C1::class) @Retention(RUNTIME) annotation class A1 @Retention(BINARY) annotation class C1(val value: Array) -@R(C2::class) +@R(C2::class) @Retention(BINARY) annotation class A2 @Retention(SOURCE) annotation class C2(val value: Array) -@R(C3::class) +@R(C3::class) annotation class A3 @Retention(SOURCE) annotation class C3(val value: Array) diff --git a/compiler/testData/diagnostics/tests/annotations/repeatable/nestedClassContainer_1_5.kt b/compiler/testData/diagnostics/tests/annotations/repeatable/nestedClassContainer_1_5.kt index 2ad24687db3..5da4525c51a 100644 --- a/compiler/testData/diagnostics/tests/annotations/repeatable/nestedClassContainer_1_5.kt +++ b/compiler/testData/diagnostics/tests/annotations/repeatable/nestedClassContainer_1_5.kt @@ -1,7 +1,7 @@ // !LANGUAGE: -RepeatableAnnotations -RepeatableAnnotationContainerConstraints // FULL_JDK -@Repeatable +@Repeatable annotation class A1 { class Container }