[AA] KtAnnotationApplication: make index nullable
^KT-56046
This commit is contained in:
committed by
Space Team
parent
50711d5003
commit
379044f2c8
+5
-5
@@ -429,18 +429,18 @@ internal tailrec fun KotlinBuiltIns.areSameArrayTypeIgnoringProjections(left: Ko
|
||||
internal fun List<ConstantValue<*>>.expandArrayAnnotationValue(
|
||||
containingArrayType: KotlinType,
|
||||
analysisContext: Fe10AnalysisContext,
|
||||
): List<KtAnnotationValue> = flatMapIndexed { index: Int, constantValue: ConstantValue<*> ->
|
||||
): List<KtAnnotationValue> = flatMap { constantValue: ConstantValue<*> ->
|
||||
val constantType = constantValue.getType(analysisContext.resolveSession.moduleDescriptor)
|
||||
if (analysisContext.builtIns.areSameArrayTypeIgnoringProjections(containingArrayType, constantType)) {
|
||||
// If an element in the array has the same type as the containing array, it's a spread component that needs
|
||||
// to be expanded here. (It should have the array element type instead.)
|
||||
(constantValue as ArrayValue).value.expandArrayAnnotationValue(containingArrayType, analysisContext)
|
||||
} else {
|
||||
listOf(constantValue.toKtAnnotationValue(analysisContext, index))
|
||||
listOf(constantValue.toKtAnnotationValue(analysisContext))
|
||||
}
|
||||
}
|
||||
|
||||
internal fun ConstantValue<*>.toKtAnnotationValue(analysisContext: Fe10AnalysisContext, index: Int): KtAnnotationValue {
|
||||
internal fun ConstantValue<*>.toKtAnnotationValue(analysisContext: Fe10AnalysisContext): KtAnnotationValue {
|
||||
return when (this) {
|
||||
is ArrayValue -> {
|
||||
val arrayType = getType(analysisContext.resolveSession.moduleDescriptor)
|
||||
@@ -462,7 +462,7 @@ internal fun ConstantValue<*>.toKtAnnotationValue(analysisContext: Fe10AnalysisC
|
||||
psi = null,
|
||||
useSiteTarget = null,
|
||||
arguments = value.getKtNamedAnnotationArguments(analysisContext),
|
||||
index = index,
|
||||
index = null,
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -635,7 +635,7 @@ internal val AnnotationDescriptor.useSiteTarget: AnnotationUseSiteTarget?
|
||||
|
||||
internal fun AnnotationDescriptor.getKtNamedAnnotationArguments(analysisContext: Fe10AnalysisContext): List<KtNamedAnnotationValue> =
|
||||
allValueArguments.map { (name, value) ->
|
||||
KtNamedAnnotationValue(name, value.toKtAnnotationValue(analysisContext, index = -1))
|
||||
KtNamedAnnotationValue(name, value.toKtAnnotationValue(analysisContext))
|
||||
}
|
||||
|
||||
internal fun CallableDescriptor.createContextReceivers(
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ internal fun PrettyPrinter.renderFe10Annotations(
|
||||
printCollectionIfNotEmpty(valueArguments, separator = ", ", prefix = "(", postfix = ")") { (name, value) ->
|
||||
append(name.render())
|
||||
append(" = ")
|
||||
append(value.toKtAnnotationValue(analysisContext, -1).renderAsSourceCode())
|
||||
append(value.toKtAnnotationValue(analysisContext).renderAsSourceCode())
|
||||
}
|
||||
|
||||
append(separator)
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ internal object FirAnnotationValueConverter {
|
||||
psi as? KtCallElement,
|
||||
useSiteTarget = null,
|
||||
toNamedConstantValue(resultMap, session),
|
||||
index = -1,
|
||||
index = null,
|
||||
)
|
||||
)
|
||||
} else null
|
||||
|
||||
+5
-5
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.psi.KtCallElement
|
||||
* Some examples:
|
||||
* - For declarations: `@Deprecated("Should not be used") fun foo(){}`
|
||||
* - For types: `fun foo(x: List<@A Int>){}`
|
||||
* - Inside other annotation (`B` is annotation here): `@A(B()) fun foo(){}
|
||||
* - Inside another annotation (`B` is annotation here): `@A(B()) fun foo(){}
|
||||
*/
|
||||
public sealed interface KtAnnotationApplication {
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ public sealed interface KtAnnotationApplication {
|
||||
public val classId: ClassId?
|
||||
|
||||
/**
|
||||
* PsiElement which was used to apply annotation to declaration/type.
|
||||
* [com.intellij.psi.PsiElement] which was used to apply annotation to declaration/type.
|
||||
*
|
||||
* Present only for declarations from sources. For declarations from other places (libraries, stdlib) it's `null`
|
||||
*/
|
||||
@@ -33,7 +33,7 @@ public sealed interface KtAnnotationApplication {
|
||||
/**
|
||||
* [AnnotationUseSiteTarget] to which annotation was applied. May be not-null only for annotation applications for declarations.
|
||||
*
|
||||
* See in more details in [Kotlin Documentation](https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets) for more information about annotation targets.
|
||||
* See more details in [Kotlin Documentation](https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets) for more information about annotation targets.
|
||||
*/
|
||||
public val useSiteTarget: AnnotationUseSiteTarget?
|
||||
|
||||
@@ -43,7 +43,7 @@ public sealed interface KtAnnotationApplication {
|
||||
public val isCallWithArguments: Boolean
|
||||
|
||||
/**
|
||||
* An index of the annotation in an owner. Can be `-1` in case of annotation arguments
|
||||
* An index of the annotation in an owner. `null` for annotation arguments
|
||||
*/
|
||||
public val index: Int
|
||||
public val index: Int?
|
||||
}
|
||||
|
||||
+1
-24
@@ -10,39 +10,16 @@ import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
|
||||
/**
|
||||
* Overview of annotation to some declaration or type.
|
||||
* Info of annotation to some declaration or type.
|
||||
*
|
||||
* Some examples:
|
||||
* - For declarations: `@Deprecated("Should not be used") fun foo(){}`
|
||||
* - For types: `fun foo(x: List<@A Int>){}`
|
||||
*/
|
||||
public data class KtAnnotationApplicationInfo(
|
||||
/**
|
||||
* The [ClassId] of applied annotation. [ClassId] is a fully qualified name on annotation class.
|
||||
*/
|
||||
public override val classId: ClassId?,
|
||||
|
||||
/**
|
||||
* [com.intellij.psi.PsiElement] which was used to apply annotation to declaration/type.
|
||||
*
|
||||
* Present only for declarations from sources. For declarations from other places (libraries, stdlib) it's `null`
|
||||
*/
|
||||
public override val psi: KtCallElement?,
|
||||
|
||||
/**
|
||||
* [AnnotationUseSiteTarget] to which annotation was applied. May be not-null only for annotation applications for declarations.
|
||||
*
|
||||
* See in more details in [Kotlin Documentation](https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets) for more information about annotation targets.
|
||||
*/
|
||||
public override val useSiteTarget: AnnotationUseSiteTarget?,
|
||||
|
||||
/**
|
||||
* **true** if the annotation has any arguments
|
||||
*/
|
||||
public override val isCallWithArguments: Boolean,
|
||||
|
||||
/**
|
||||
* An index of the annotation in an owner
|
||||
*/
|
||||
public override val index: Int,
|
||||
) : KtAnnotationApplication
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public data class KtAnnotationApplicationWithArgumentsInfo(
|
||||
* A list of annotation arguments which were applied when constructing annotation. Every argument is [KtAnnotationValue]
|
||||
*/
|
||||
public val arguments: List<KtNamedAnnotationValue>,
|
||||
override val index: Int,
|
||||
override val index: Int?,
|
||||
) : KtAnnotationApplication {
|
||||
override val isCallWithArguments: Boolean get() = arguments.isNotEmpty()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user