[LL FIR] FirElementBuilder: search file annotations without body resolution

^KT-65780
This commit is contained in:
Dmitrii Gridin
2024-02-13 15:30:28 +01:00
committed by Space Team
parent cca58f5c2a
commit 38a3010ac8
5 changed files with 22 additions and 16 deletions
@@ -116,16 +116,21 @@ internal class FirElementBuilder(
resolveAndFindFirForAnchor: (FirAnnotationContainer, T) -> FirElement?,
): FirElement? {
val anchorElement = anchorElementProvider(element) ?: return null
val declaration = annotatedElementProvider(anchorElement) ?: return null
val nonLocalDeclaration = declaration.getNonLocalContainingOrThisDeclaration()
if (declaration != nonLocalDeclaration) return null
val annotationElement = annotatedElementProvider(anchorElement) ?: return null
val firDeclaration = nonLocalDeclaration.findSourceNonLocalFirDeclaration(
firFileBuilder = moduleComponents.firFileBuilder,
provider = moduleComponents.session.firProvider,
)
val firAnnotationContainer = if (annotationElement is KtFile) {
moduleComponents.firFileBuilder.buildRawFirFileWithCaching(annotationElement)
} else {
val nonLocalDeclaration = annotationElement.getNonLocalContainingOrThisDeclaration()
if (annotationElement != nonLocalDeclaration) return null
val anchorFir = resolveAndFindFirForAnchor(firDeclaration, anchorElement) ?: return null
nonLocalDeclaration.findSourceNonLocalFirDeclaration(
firFileBuilder = moduleComponents.firFileBuilder,
provider = moduleComponents.session.firProvider,
)
}
val anchorFir = resolveAndFindFirForAnchor(firAnnotationContainer, anchorElement) ?: return null
// We use identity comparison here intentionally to check that it is exactly the object we want to find
if (element === anchorElement) return anchorFir
@@ -136,6 +141,7 @@ internal class FirElementBuilder(
val modifierList = when (val parent = parent) {
is KtModifierList -> parent
is KtAnnotation -> parent.parent as? KtModifierList
is KtFileAnnotationList -> return parent.parent as? KtFile
else -> null
}
@@ -6,6 +6,6 @@ FIR element rendered:
@FILE:R|kotlin/Suppress|[Types](names = vararg(String()))
FIR FILE:
FILE: [ResolvedTo(BODY_RESOLVE)] fileAnnotation.kt
FILE: [ResolvedTo(ANNOTATION_ARGUMENTS)] fileAnnotation.kt
@FILE:R|kotlin/Suppress|[Types](names = vararg(String()))
[ResolvedTo(BODY_RESOLVE)] annotations container
[ResolvedTo(ANNOTATION_ARGUMENTS)] annotations container
@@ -6,9 +6,9 @@ FIR element rendered:
@FILE:R|kotlin/Suppress|[Types](names = vararg(String()))
FIR FILE:
FILE: [ResolvedTo(BODY_RESOLVE)] fileAnnotationScript.kts
FILE: [ResolvedTo(ANNOTATION_ARGUMENTS)] fileAnnotationScript.kts
@FILE:R|kotlin/Suppress|[Types](names = vararg(String()))
[ResolvedTo(BODY_RESOLVE)] annotations container
[ResolvedTo(ANNOTATION_ARGUMENTS)] annotations container
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
SCRIPT: [ResolvedTo(RAW_FIR)] <script-fileAnnotationScript.kts>
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
@@ -6,9 +6,9 @@ FIR element rendered:
@FILE:R|Ann|[Types]()
FIR FILE:
FILE: [ResolvedTo(BODY_RESOLVE)] file.kt
FILE: [ResolvedTo(ANNOTATION_ARGUMENTS)] file.kt
@FILE:R|Ann|[Types]()
[ResolvedTo(BODY_RESOLVE)] annotations container
[ResolvedTo(ANNOTATION_ARGUMENTS)] annotations container
public final [ResolvedTo(STATUS)] annotation class Ann : R|kotlin/Annotation| {
public [ResolvedTo(STATUS)] [ContainingClassKey=Ann] constructor(): R|Ann| {
LAZY_super<R|kotlin/Any|>
@@ -6,9 +6,9 @@ FIR element rendered:
@FILE:R|Ann|[Types]()
FIR FILE:
FILE: [ResolvedTo(BODY_RESOLVE)] fileScript.kts
FILE: [ResolvedTo(ANNOTATION_ARGUMENTS)] fileScript.kts
@FILE:R|Ann|[Types]()
[ResolvedTo(BODY_RESOLVE)] annotations container
[ResolvedTo(ANNOTATION_ARGUMENTS)] annotations container
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
SCRIPT: [ResolvedTo(RAW_FIR)] <script-fileScript.kts>
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|