Use deprecation type for some REPEATABLE_* diagnostics

This commit is contained in:
Ivan Kochurkin
2021-09-02 02:21:20 +03:00
committed by TeamCityServer
parent f414a91c66
commit 6fa1c0353c
6 changed files with 34 additions and 47 deletions
@@ -103,10 +103,10 @@ class RepeatableAnnotationChecker(
) )
if (nestedClassNamedContainer != null) { if (nestedClassNamedContainer != null) {
trace.report( trace.report(
select( ErrorsJvm.REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER.on(
ErrorsJvm.REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER, languageVersionSettings,
ErrorsJvm.REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER_ERROR kotlinRepeatable.entry
).on(kotlinRepeatable.entry) )
) )
} }
} }
@@ -170,16 +170,14 @@ class RepeatableAnnotationChecker(
if (value == null || !KotlinBuiltIns.isArray(value.type) || if (value == null || !KotlinBuiltIns.isArray(value.type) ||
value.type.arguments.single().type.constructor.declarationDescriptor != annotationClass value.type.arguments.single().type.constructor.declarationDescriptor != annotationClass
) { ) {
return select( return ErrorsJvm.REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY
ErrorsJvm.REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY, ErrorsJvm.REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY_ERROR .on(languageVersionSettings, reportOn, containerClass.fqNameSafe, annotationClass.fqNameSafe)
).on(reportOn, containerClass.fqNameSafe, annotationClass.fqNameSafe)
} }
val otherNonDefault = containerCtor.valueParameters.find { it.name.asString() != "value" && !it.declaresDefaultValue() } val otherNonDefault = containerCtor.valueParameters.find { it.name.asString() != "value" && !it.declaresDefaultValue() }
if (otherNonDefault != null) { if (otherNonDefault != null) {
return select( return ErrorsJvm.REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER
ErrorsJvm.REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER, ErrorsJvm.REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER_ERROR .on(languageVersionSettings, reportOn, containerClass.fqNameSafe, otherNonDefault)
).on(reportOn, containerClass.fqNameSafe, otherNonDefault)
} }
return null return null
@@ -193,9 +191,15 @@ class RepeatableAnnotationChecker(
val annotationRetention = annotationClass.getAnnotationRetention() ?: KotlinRetention.RUNTIME val annotationRetention = annotationClass.getAnnotationRetention() ?: KotlinRetention.RUNTIME
val containerRetention = containerClass.getAnnotationRetention() ?: KotlinRetention.RUNTIME val containerRetention = containerClass.getAnnotationRetention() ?: KotlinRetention.RUNTIME
if (containerRetention > annotationRetention) { if (containerRetention > annotationRetention) {
return select( return ErrorsJvm.REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION
ErrorsJvm.REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION, ErrorsJvm.REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION_ERROR .on(
).on(reportOn, containerClass.fqNameSafe, containerRetention.name, annotationClass.fqNameSafe, annotationRetention.name) languageVersionSettings,
reportOn,
containerClass.fqNameSafe,
containerRetention.name,
annotationClass.fqNameSafe,
annotationRetention.name
)
} }
return null return null
} }
@@ -224,21 +228,14 @@ class RepeatableAnnotationChecker(
else -> false else -> false
} }
if (!ok) { if (!ok) {
return select( return ErrorsJvm.REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET
ErrorsJvm.REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET, ErrorsJvm.REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET_ERROR .on(languageVersionSettings, reportOn, containerClass.fqNameSafe, annotationClass.fqNameSafe)
).on(reportOn, containerClass.fqNameSafe, annotationClass.fqNameSafe)
} }
} }
return null return null
} }
private fun <D> select(warning: D, error: D): D =
if (languageVersionSettings.supportsFeature(LanguageFeature.RepeatableAnnotationContainerConstraints))
error
else
warning
private fun isRepeatableAnnotation(classDescriptor: ClassDescriptor): Boolean = private fun isRepeatableAnnotation(classDescriptor: ClassDescriptor): Boolean =
classDescriptor.isAnnotatedWithKotlinRepeatable() || platformAnnotationFeaturesSupport.isRepeatableAnnotationClass(classDescriptor) classDescriptor.isAnnotatedWithKotlinRepeatable() || platformAnnotationFeaturesSupport.isRepeatableAnnotationClass(classDescriptor)
@@ -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(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, "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, "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, "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, "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, "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_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"); MAP.put(JVM_PACKAGE_NAME_MUST_BE_VALID_NAME, "''@JvmPackageName'' annotation value must be a valid dot-qualified name of a package");
@@ -75,16 +75,11 @@ public interface ErrorsJvm {
DiagnosticFactory0<KtAnnotationEntry> REPEATED_ANNOTATION_TARGET6 = DiagnosticFactory0.create(ERROR); DiagnosticFactory0<KtAnnotationEntry> REPEATED_ANNOTATION_TARGET6 = DiagnosticFactory0.create(ERROR);
DiagnosticFactory2<KtAnnotationEntry, FqName, FqName> REPEATED_ANNOTATION_WITH_CONTAINER = DiagnosticFactory2.create(ERROR); DiagnosticFactory2<KtAnnotationEntry, FqName, FqName> REPEATED_ANNOTATION_WITH_CONTAINER = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<KtAnnotationEntry, FqName, FqName> REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY = DiagnosticFactory2.create(WARNING); DiagnosticFactoryForDeprecation2<KtAnnotationEntry, FqName, FqName> REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY = DiagnosticFactoryForDeprecation2.create(LanguageFeature.RepeatableAnnotationContainerConstraints);
DiagnosticFactory2<KtAnnotationEntry, FqName, FqName> REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY_ERROR = DiagnosticFactory2.create(ERROR); DiagnosticFactoryForDeprecation2<KtAnnotationEntry, FqName, Named> REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER = DiagnosticFactoryForDeprecation2.create(LanguageFeature.RepeatableAnnotationContainerConstraints);
DiagnosticFactory2<KtAnnotationEntry, FqName, Named> REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER = DiagnosticFactory2.create(WARNING); DiagnosticFactoryForDeprecation4<KtAnnotationEntry, FqName, String, FqName, String> REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION = DiagnosticFactoryForDeprecation4.create(LanguageFeature.RepeatableAnnotationContainerConstraints);
DiagnosticFactory2<KtAnnotationEntry, FqName, Named> REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER_ERROR = DiagnosticFactory2.create(ERROR); DiagnosticFactoryForDeprecation2<KtAnnotationEntry, FqName, FqName> REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET = DiagnosticFactoryForDeprecation2.create(LanguageFeature.RepeatableAnnotationContainerConstraints);
DiagnosticFactory4<KtAnnotationEntry, FqName, String, FqName, String> REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION = DiagnosticFactory4.create(WARNING); DiagnosticFactoryForDeprecation0<KtAnnotationEntry> REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER = DiagnosticFactoryForDeprecation0.create(LanguageFeature.RepeatableAnnotationContainerConstraints);
DiagnosticFactory4<KtAnnotationEntry, FqName, String, FqName, String> REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION_ERROR = DiagnosticFactory4.create(ERROR);
DiagnosticFactory2<KtAnnotationEntry, FqName, FqName> REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET = DiagnosticFactory2.create(WARNING);
DiagnosticFactory2<KtAnnotationEntry, FqName, FqName> REPEATABLE_CONTAINER_TARGET_SET_NOT_A_SUBSET_ERROR = DiagnosticFactory2.create(ERROR);
DiagnosticFactory0<KtAnnotationEntry> REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<KtAnnotationEntry> REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER_ERROR = DiagnosticFactory0.create(WARNING);
DiagnosticFactory1<KtAnnotationEntry, FqName> ANNOTATION_IS_NOT_APPLICABLE_TO_MULTIFILE_CLASSES = DiagnosticFactory1.create(ERROR); DiagnosticFactory1<KtAnnotationEntry, FqName> ANNOTATION_IS_NOT_APPLICABLE_TO_MULTIFILE_CLASSES = DiagnosticFactory1.create(ERROR);
@@ -3,27 +3,27 @@
import java.lang.annotation.Repeatable as R import java.lang.annotation.Repeatable as R
<!REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY!>@R(C1::class)<!> <!REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY_WARNING!>@R(C1::class)<!>
annotation class A1 annotation class A1
annotation class C1 annotation class C1
<!REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY!>@R(C2::class)<!> <!REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY_WARNING!>@R(C2::class)<!>
annotation class A2 annotation class A2
annotation class C2(val value: A2) annotation class C2(val value: A2)
<!REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY!>@R(C3::class)<!> <!REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY_WARNING!>@R(C3::class)<!>
annotation class A3 annotation class A3
annotation class C3(val value: Array<String>) annotation class C3(val value: Array<String>)
<!REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY!>@R(C4::class)<!> <!REPEATABLE_CONTAINER_MUST_HAVE_VALUE_ARRAY_WARNING!>@R(C4::class)<!>
annotation class A4 annotation class A4
annotation class C4(val notValue: Array<A4>) annotation class C4(val notValue: Array<A4>)
<!REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER!>@R(C5::class)<!> <!REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER_WARNING!>@R(C5::class)<!>
annotation class A5 annotation class A5
annotation class C5(val value: Array<A5>, val irrelevant: String) annotation class C5(val value: Array<A5>, val irrelevant: String)
<!REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER!>@R(C6::class)<!> <!REPEATABLE_CONTAINER_HAS_NON_DEFAULT_PARAMETER_WARNING!>@R(C6::class)<!>
annotation class A6 annotation class A6
annotation class C6(val irrelevant: Double, val value: Array<A6> = []) annotation class C6(val irrelevant: Double, val value: Array<A6> = [])
@@ -4,19 +4,19 @@
import java.lang.annotation.Repeatable as R import java.lang.annotation.Repeatable as R
import kotlin.annotation.AnnotationRetention.* import kotlin.annotation.AnnotationRetention.*
<!REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION!>@R(C1::class)<!> <!REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION_WARNING!>@R(C1::class)<!>
@Retention(RUNTIME) @Retention(RUNTIME)
annotation class A1 annotation class A1
@Retention(BINARY) @Retention(BINARY)
annotation class C1(val value: Array<A1>) annotation class C1(val value: Array<A1>)
<!REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION!>@R(C2::class)<!> <!REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION_WARNING!>@R(C2::class)<!>
@Retention(BINARY) @Retention(BINARY)
annotation class A2 annotation class A2
@Retention(SOURCE) @Retention(SOURCE)
annotation class C2(val value: Array<A2>) annotation class C2(val value: Array<A2>)
<!REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION!>@R(C3::class)<!> <!REPEATABLE_CONTAINER_HAS_SHORTER_RETENTION_WARNING!>@R(C3::class)<!>
annotation class A3 annotation class A3
@Retention(SOURCE) @Retention(SOURCE)
annotation class C3(val value: Array<A3>) annotation class C3(val value: Array<A3>)
@@ -1,7 +1,7 @@
// !LANGUAGE: -RepeatableAnnotations -RepeatableAnnotationContainerConstraints // !LANGUAGE: -RepeatableAnnotations -RepeatableAnnotationContainerConstraints
// FULL_JDK // FULL_JDK
<!REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER!>@Repeatable<!> <!REPEATABLE_ANNOTATION_HAS_NESTED_CLASS_NAMED_CONTAINER_WARNING!>@Repeatable<!>
annotation class A1 { annotation class A1 {
class Container class Container
} }