diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightUtils.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightUtils.kt index 4894638e9f5..ca15bfabda0 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightUtils.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightUtils.kt @@ -191,7 +191,8 @@ private fun annotateByKotlinType( kotlinType: KotlinType, psiContext: PsiElement, ultraLightSupport: KtUltraLightSupport -) { +): PsiType { + fun KotlinType.getAnnotationsSequence(): Sequence> = sequence { yield(annotations.mapNotNull { it.toLightAnnotation(ultraLightSupport, psiContext) }) @@ -201,11 +202,20 @@ private fun annotateByKotlinType( } val annotationsIterator = kotlinType.getAnnotationsSequence().iterator() + if (!annotationsIterator.hasNext()) return psiType + + if (psiType is PsiPrimitiveType) { + val annotation = annotationsIterator.next() + val provider = TypeAnnotationProvider.Static.create(annotation.toTypedArray()) + return psiType.annotate(provider) + } fun recursiveAnnotator(psiType: PsiType) { if (!annotationsIterator.hasNext()) return val typeAnnotations = annotationsIterator.next() + if (psiType is PsiPrimitiveType) return //Primitive type cannot be type parameter so we skip it + if (psiType is PsiClassType) { for (parameterType in psiType.parameters) { recursiveAnnotator(parameterType) @@ -217,11 +227,11 @@ private fun annotateByKotlinType( if (typeAnnotations.isEmpty()) return val provider = TypeAnnotationProvider.Static.create(typeAnnotations.toTypedArray()) - setPsiTypeAnnotationProvider(psiType, provider) } recursiveAnnotator(psiType) + return psiType } internal fun KtUltraLightSupport.mapType( @@ -246,10 +256,7 @@ private fun KtUltraLightSupport.createTypeFromCanonicalText( val typeText = TypeInfo.createTypeText(typeInfo) ?: return PsiType.NULL val typeElement = ClsTypeElementImpl(psiContext, typeText, '\u0000') - val type = typeElement.type - if (kotlinType != null) { - annotateByKotlinType(type, kotlinType, typeElement, this) - } + val type = if (kotlinType != null) annotateByKotlinType(typeElement.type, kotlinType, typeElement, this) else typeElement.type if (type is PsiArrayType && psiContext is KtUltraLightParameter && psiContext.isVarArgs) { return PsiEllipsisType(type.componentType, type.annotationProvider) diff --git a/compiler/testData/asJava/ultraLightClasses/typeAnnotations.java b/compiler/testData/asJava/ultraLightClasses/typeAnnotations.java index d5473375e39..9ba413b41d9 100644 --- a/compiler/testData/asJava/ultraLightClasses/typeAnnotations.java +++ b/compiler/testData/asJava/ultraLightClasses/typeAnnotations.java @@ -54,9 +54,19 @@ public final class Y /* Y*/ { } public final class klass /* klass*/ { + @org.jetbrains.annotations.Nullable() + private final java.util.List<@A0() java.lang.Integer> y; + + private final @A0() int x; + @org.jetbrains.annotations.NotNull() public final @A6() X annotatedMethod(@org.jetbrains.annotations.NotNull() @A0() P<@A1() X, P<@A2() @A3() X, @A4() Y>>, @org.jetbrains.annotations.NotNull() @A5() Y[]);// annotatedMethod(@A0() P<@A1() X, P<@A2() @A3() X, @A4() Y>>, @A5() Y[]) + @org.jetbrains.annotations.Nullable() + public final java.util.List<@A0() java.lang.Integer> getY();// getY() + public klass();// .ctor() + public final @A0() int getX();// getX() + } \ No newline at end of file diff --git a/compiler/testData/asJava/ultraLightClasses/typeAnnotations.kt b/compiler/testData/asJava/ultraLightClasses/typeAnnotations.kt index 110b5ea7144..0705dc6bff5 100644 --- a/compiler/testData/asJava/ultraLightClasses/typeAnnotations.kt +++ b/compiler/testData/asJava/ultraLightClasses/typeAnnotations.kt @@ -23,4 +23,7 @@ class klass { fun annotatedMethod(x: @A0 P<@A1 X, P<@A2 @A3 X, @A4 Y>>, y: Array<@A5 Y>): @A6 X { return "" } + + val x: @A0 Int = 2 + val y: List<@A0 Int>? = null }