From 7d8cace8bdc38063cb9a7af00dd63375a8304db4 Mon Sep 17 00:00:00 2001 From: Jiaxiang Chen Date: Mon, 28 Nov 2022 18:40:55 -0800 Subject: [PATCH] AA: Handle AnnotationTarget.VALUE_PARAMETER for property declarations. --- .../impl/symbol/kotlin/KSPropertyDeclarationImpl.kt | 13 ++++++++++++- .../ksp/impl/symbol/kotlin/KSValueArgumentImpl.kt | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyDeclarationImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyDeclarationImpl.kt index 8f03e326d1..2ba87469bc 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyDeclarationImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSPropertyDeclarationImpl.kt @@ -40,6 +40,16 @@ class KSPropertyDeclarationImpl private constructor(internal val ktPropertySymbo ktPropertySymbol.annotations.asSequence() .filter { !it.isUseSiteTargetAnnotation() } .map { KSAnnotationImpl.getCached(it) } + .filterNot { valueParameterAnnotation -> + valueParameterAnnotation.annotationType.resolve().declaration.annotations.any { metaAnnotation -> + metaAnnotation.annotationType.resolve().declaration.qualifiedName + ?.asString() == "kotlin.annotation.Target" && + (metaAnnotation.arguments.singleOrNull()?.value as? ArrayList<*>)?.any { + (it as? KSClassDeclaration)?.qualifiedName + ?.asString() == "kotlin.annotation.AnnotationTarget.VALUE_PARAMETER" + } ?: false + } + } } override val getter: KSPropertyGetter? by lazy { @@ -99,7 +109,8 @@ internal fun KtAnnotationApplication.isUseSiteTargetAnnotation(): Boolean { return this.useSiteTarget?.let { it == AnnotationUseSiteTarget.PROPERTY_GETTER || it == AnnotationUseSiteTarget.PROPERTY_SETTER || - it == AnnotationUseSiteTarget.SETTER_PARAMETER + it == AnnotationUseSiteTarget.SETTER_PARAMETER || + it == AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER } ?: false } diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSValueArgumentImpl.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSValueArgumentImpl.kt index 0c2be02c5f..782969fe0a 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSValueArgumentImpl.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSValueArgumentImpl.kt @@ -66,6 +66,7 @@ class KSValueArgumentImpl private constructor( private fun KtAnnotationValue.toValue(): Any? = when (this) { is KtArrayAnnotationValue -> this.values.map { it.toValue() } is KtAnnotationApplicationValue -> KSAnnotationImpl.getCached(this.annotationValue) + // TODO: Enum entry should return a type, use declaration as a placeholder. is KtEnumEntryAnnotationValue -> this.callableId?.classId?.let { analyze { it.toKtClassSymbol()?.let {