From 0833719a79986462f01f18de4904f65fab91f539 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Fri, 27 Nov 2020 11:54:23 +0300 Subject: [PATCH] Support annotations on array types ^KT-24392 Fixed ^KT-18768 Fixed --- .../kotlin/load/java/lazy/types/JavaTypeResolver.kt | 12 +++++++++--- .../jetbrains/kotlin/builtins/KotlinBuiltIns.java | 9 +++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt index 42a53d7ac78..2bdc2baecda 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/lazy/types/JavaTypeResolver.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.load.java.lazy.types import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMapper import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.load.java.components.TypeUsage import org.jetbrains.kotlin.load.java.components.TypeUsage.COMMON import org.jetbrains.kotlin.load.java.components.TypeUsage.SUPERTYPE @@ -61,8 +62,13 @@ class JavaTypeResolver( fun transformArrayType(arrayType: JavaArrayType, attr: JavaTypeAttributes, isVararg: Boolean = false): KotlinType { val javaComponentType = arrayType.componentType val primitiveType = (javaComponentType as? JavaPrimitiveType)?.type + val annotations = LazyJavaAnnotations(c, arrayType) + if (primitiveType != null) { val jetType = c.module.builtIns.getPrimitiveArrayKotlinType(primitiveType) + + jetType.replaceAnnotations(Annotations.create(annotations + jetType.annotations)) + return if (attr.isForAnnotationParameter) jetType else KotlinTypeFactory.flexibleType(jetType, jetType.makeNullableAsSpecified(true)) @@ -75,12 +81,12 @@ class JavaTypeResolver( if (attr.isForAnnotationParameter) { val projectionKind = if (isVararg) OUT_VARIANCE else INVARIANT - return c.module.builtIns.getArrayType(projectionKind, componentType) + return c.module.builtIns.getArrayType(projectionKind, componentType, annotations) } return KotlinTypeFactory.flexibleType( - c.module.builtIns.getArrayType(INVARIANT, componentType), - c.module.builtIns.getArrayType(OUT_VARIANCE, componentType).makeNullableAsSpecified(true) + c.module.builtIns.getArrayType(INVARIANT, componentType, annotations), + c.module.builtIns.getArrayType(OUT_VARIANCE, componentType, annotations).makeNullableAsSpecified(true) ) } diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index d0bfb5fcaf8..8c65ca36014 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -653,9 +653,14 @@ public abstract class KotlinBuiltIns { } @NotNull - public SimpleType getArrayType(@NotNull Variance projectionType, @NotNull KotlinType argument) { + public SimpleType getArrayType(@NotNull Variance projectionType, @NotNull KotlinType argument, @NotNull Annotations annotations) { List types = Collections.singletonList(new TypeProjectionImpl(projectionType, argument)); - return KotlinTypeFactory.simpleNotNullType(Annotations.Companion.getEMPTY(), getArray(), types); + return KotlinTypeFactory.simpleNotNullType(annotations, getArray(), types); + } + + @NotNull + public SimpleType getArrayType(@NotNull Variance projectionType, @NotNull KotlinType argument) { + return getArrayType(projectionType, argument, Annotations.Companion.getEMPTY()); } @NotNull