From 16878ca20db9ad91b8bed769be96103b10fdfb64 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Wed, 28 Feb 2024 22:40:06 +0100 Subject: [PATCH] [LL FIR] FirElementBuilder: support KtAnnotation in file annotations ^KT-65780 --- .../low/level/api/fir/element/builder/FirElementBuilder.kt | 6 +++--- .../testData/getOrBuildFir/annotations/fileAnnotation2.txt | 2 +- .../getOrBuildFir/annotations/fileAnnotation2Script.txt | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/element/builder/FirElementBuilder.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/element/builder/FirElementBuilder.kt index 9589b925d6b..f0f3cd1e2b4 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/element/builder/FirElementBuilder.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/element/builder/FirElementBuilder.kt @@ -159,10 +159,10 @@ internal class FirElementBuilder(private val moduleComponents: LLFirModuleResolv return findElementInside(firElement = anchorFir, element = element, stopAt = anchorElement) } - private fun KtAnnotationEntry.owner(): KtAnnotated? { + private fun PsiElement.annotationOwner(): KtAnnotated? { val modifierList = when (val parent = parent) { is KtModifierList -> parent - is KtAnnotation -> parent.parent as? KtModifierList + is KtAnnotation -> return parent.annotationOwner() is KtFileAnnotationList -> return parent.parent as? KtFile else -> null } @@ -175,7 +175,7 @@ internal class FirElementBuilder(private val moduleComponents: LLFirModuleResolv ): FirElement? = getFirForNonBodyElement( element = element, anchorElementProvider = { it.parentOfType(withSelf = true) }, - elementOwnerProvider = { it.owner() }, + elementOwnerProvider = { it.annotationOwner() }, resolveAndFindFirForAnchor = { declaration, anchor -> declaration.resolveAndFindAnnotation(anchor, goDeep = true) }, ) diff --git a/analysis/low-level-api-fir/testData/getOrBuildFir/annotations/fileAnnotation2.txt b/analysis/low-level-api-fir/testData/getOrBuildFir/annotations/fileAnnotation2.txt index 7fa9151c5c4..570fd55deca 100644 --- a/analysis/low-level-api-fir/testData/getOrBuildFir/annotations/fileAnnotation2.txt +++ b/analysis/low-level-api-fir/testData/getOrBuildFir/annotations/fileAnnotation2.txt @@ -6,5 +6,5 @@ FIR element rendered: @FILE:R|kotlin/Suppress|[Types](names = vararg(String())) FIR FILE: -FILE: [ResolvedTo(BODY_RESOLVE)] fileAnnotation2.kt +FILE: [ResolvedTo(ANNOTATION_ARGUMENTS)] fileAnnotation2.kt @FILE:R|kotlin/Suppress|[Types](names = vararg(String())) diff --git a/analysis/low-level-api-fir/testData/getOrBuildFir/annotations/fileAnnotation2Script.txt b/analysis/low-level-api-fir/testData/getOrBuildFir/annotations/fileAnnotation2Script.txt index a06fde6b882..5342c43230f 100644 --- a/analysis/low-level-api-fir/testData/getOrBuildFir/annotations/fileAnnotation2Script.txt +++ b/analysis/low-level-api-fir/testData/getOrBuildFir/annotations/fileAnnotation2Script.txt @@ -6,7 +6,7 @@ FIR element rendered: @FILE:R|kotlin/Suppress|[Types](names = vararg(String())) FIR FILE: -FILE: [ResolvedTo(BODY_RESOLVE)] fileAnnotation2Script.kts +FILE: [ResolvedTo(ANNOTATION_ARGUMENTS)] fileAnnotation2Script.kts @FILE:R|kotlin/Suppress|[Types](names = vararg(String())) context(