[ULC] Fix invalid primitive type annotating
Fixed #KT-45417
This commit is contained in:
@@ -191,7 +191,8 @@ private fun annotateByKotlinType(
|
||||
kotlinType: KotlinType,
|
||||
psiContext: PsiElement,
|
||||
ultraLightSupport: KtUltraLightSupport
|
||||
) {
|
||||
): PsiType {
|
||||
|
||||
fun KotlinType.getAnnotationsSequence(): Sequence<List<PsiAnnotation>> =
|
||||
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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user