Support annotations on array types
^KT-24392 Fixed ^KT-18768 Fixed
This commit is contained in:
+9
-3
@@ -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)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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<TypeProjectionImpl> 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
|
||||
|
||||
Reference in New Issue
Block a user