Remove mapping of java.Repeatable to kotlin.Repeatable in JavaAnnotationMapper

The main motivation for this change is that
java.lang.annotation.Repeatable has a parameter for the container
annotation, which is lost during conversion to
kotlin.annotation.Repeatable. To support j.l.a.Repeatable in backend
properly, it's absolutely necessary to be able to load the container
annotation for any repeatable annotation class, so the original
j.l.a.Repeatable needs to be stored in the descriptor and accessible
from the backend.

Instead of mapping j.l.a.Repeatable -> k.a.Repeatable, add a frontend
service PlatformAnnotationFeaturesSupport that will determine if an
annotation is repeatable "according to the platform rules", which for
JVM means that it's annotated with j.l.a.Repeatable.

Some effects of this change include:
- Usages of j.l.a.Repeatable are no longer reported as "deprecated", the
  corresponding test is deleted
- Usages of repeatable annotations declared in Java with non-SOURCE
  retention with LV 1.5 and earlier will now result in a slightly
  different error (REPEATED_ANNOTATION instead of
  NON_SOURCE_REPEATED_ANNOTATION)

 #KT-12794
This commit is contained in:
Alexander Udalov
2021-07-20 18:08:10 +02:00
parent ebf837c135
commit f723389565
15 changed files with 64 additions and 90 deletions
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.types.SimpleType
import java.util.*
object JavaAnnotationMapper {
// Java8-specific thing
internal val DEPRECATED_ANNOTATION_MESSAGE = Name.identifier("message")
internal val TARGET_ANNOTATION_ALLOWED_TARGETS = Name.identifier("allowedTargets")
internal val RETENTION_ANNOTATION_VALUE = Name.identifier("value")
@@ -52,7 +51,6 @@ object JavaAnnotationMapper {
when (annotation.classId) {
ClassId.topLevel(TARGET_ANNOTATION) -> JavaTargetAnnotationDescriptor(annotation, c)
ClassId.topLevel(RETENTION_ANNOTATION) -> JavaRetentionAnnotationDescriptor(annotation, c)
ClassId.topLevel(REPEATABLE_ANNOTATION) -> JavaAnnotationDescriptor(c, annotation, StandardNames.FqNames.repeatable)
ClassId.topLevel(DOCUMENTED_ANNOTATION) -> JavaAnnotationDescriptor(c, annotation, StandardNames.FqNames.mustBeDocumented)
ClassId.topLevel(DEPRECATED_ANNOTATION) -> null
else -> LazyJavaAnnotationDescriptor(c, annotation, isFreshlySupportedAnnotation)
@@ -76,12 +74,10 @@ object JavaAnnotationMapper {
}
}
// kotlin.annotation.annotation is treated separately
private val kotlinToJavaNameMap: Map<FqName, FqName> =
mapOf(
StandardNames.FqNames.target to TARGET_ANNOTATION,
StandardNames.FqNames.retention to RETENTION_ANNOTATION,
StandardNames.FqNames.repeatable to REPEATABLE_ANNOTATION,
StandardNames.FqNames.mustBeDocumented to DOCUMENTED_ANNOTATION
)
@@ -90,7 +86,6 @@ object JavaAnnotationMapper {
TARGET_ANNOTATION to StandardNames.FqNames.target,
RETENTION_ANNOTATION to StandardNames.FqNames.retention,
DEPRECATED_ANNOTATION to StandardNames.FqNames.deprecated,
REPEATABLE_ANNOTATION to StandardNames.FqNames.repeatable,
DOCUMENTED_ANNOTATION to StandardNames.FqNames.mustBeDocumented
)
}