[LL FIR] FirElementBuilder: search file header elements without body resolution
^KT-65780
This commit is contained in:
committed by
Space Team
parent
04a2d6b616
commit
78c394d4de
+33
@@ -99,6 +99,7 @@ internal class FirElementBuilder(
|
||||
|
||||
getFirForElementInsideAnnotations(element)?.let { return it }
|
||||
getFirForElementInsideTypes(element)?.let { return it }
|
||||
getFirForElementInsideFileHeader(element)?.let { return it }
|
||||
|
||||
val psi = getPsiAsFirElementSource(element) ?: return null
|
||||
val firFile = element.containingKtFile
|
||||
@@ -176,6 +177,38 @@ internal class FirElementBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFirForElementInsideFileHeader(
|
||||
element: KtElement,
|
||||
): FirElement? = getFirForNonBodyElement<KtElement, KtAnnotated>(
|
||||
element = element,
|
||||
anchorElementProvider = { it.fileHeaderAnchorElement() },
|
||||
elementOwnerProvider = { it.containingKtFile },
|
||||
resolveAndFindFirForAnchor = { declaration, anchor ->
|
||||
declaration.requireTypeIntersectionWith<FirFile>()
|
||||
|
||||
when (anchor) {
|
||||
is KtPackageDirective -> declaration.packageDirective
|
||||
is KtFileAnnotationList -> declaration.annotationsContainer?.also { it.lazyResolveToPhase(FirResolvePhase.ANNOTATION_ARGUMENTS) }
|
||||
is KtImportDirective -> {
|
||||
declaration.lazyResolveToPhase(FirResolvePhase.IMPORTS)
|
||||
declaration.imports.find { it.psi == anchor }
|
||||
}
|
||||
else -> errorWithAttachment("Unexpected element type: ${anchor::class.simpleName}") {
|
||||
withPsiEntry("anchor", anchor)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
private fun KtElement.fileHeaderAnchorElement(): KtElement? {
|
||||
/**
|
||||
* File annotations already covered by [getFirForElementInsideAnnotations], but we have to cover the list itself
|
||||
*/
|
||||
if (this is KtFileAnnotationList) return this
|
||||
|
||||
return parentsWithSelf.find { it is KtPackageDirective || it is KtImportDirective } as? KtElement
|
||||
}
|
||||
|
||||
private fun findElementInside(firElement: FirElement, element: KtElement, stopAt: PsiElement): FirElement? {
|
||||
val elementToSearch = getPsiAsFirElementSource(element) ?: return null
|
||||
val mapping = FirElementsRecorder.recordElementsFrom(firElement, FirElementsRecorder())
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] firstImportNamePart.kt
|
||||
FILE: [ResolvedTo(IMPORTS)] firstImportNamePart.kt
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] firstImportNamePartScript.kts
|
||||
FILE: [ResolvedTo(IMPORTS)] firstImportNamePartScript.kts
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
SCRIPT: [ResolvedTo(RAW_FIR)] <script-firstImportNamePartScript.kts>
|
||||
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] middleImportNamePart.kt
|
||||
FILE: [ResolvedTo(IMPORTS)] middleImportNamePart.kt
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] middleImportNamePartScript.kts
|
||||
FILE: [ResolvedTo(IMPORTS)] middleImportNamePartScript.kts
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
SCRIPT: [ResolvedTo(RAW_FIR)] <script-middleImportNamePartScript.kts>
|
||||
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] qualifiedImportNamePart.kt
|
||||
FILE: [ResolvedTo(IMPORTS)] qualifiedImportNamePart.kt
|
||||
|
||||
Vendored
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] qualifiedImportNamePartScript.kts
|
||||
FILE: [ResolvedTo(IMPORTS)] qualifiedImportNamePartScript.kts
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
SCRIPT: [ResolvedTo(RAW_FIR)] <script-qualifiedImportNamePartScript.kts>
|
||||
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] wholeImportDirective.kt
|
||||
FILE: [ResolvedTo(IMPORTS)] wholeImportDirective.kt
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] wholeImportDirectiveScript.kts
|
||||
FILE: [ResolvedTo(IMPORTS)] wholeImportDirectiveScript.kts
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
SCRIPT: [ResolvedTo(RAW_FIR)] <script-wholeImportDirectiveScript.kts>
|
||||
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] wholeImportName.kt
|
||||
FILE: [ResolvedTo(IMPORTS)] wholeImportName.kt
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
import a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] wholeImportNameScript.kts
|
||||
FILE: [ResolvedTo(IMPORTS)] wholeImportNameScript.kts
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
SCRIPT: [ResolvedTo(RAW_FIR)] <script-wholeImportNameScript.kts>
|
||||
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||
|
||||
+1
-1
@@ -6,5 +6,5 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] firstPackageNamePart.kt
|
||||
FILE: [ResolvedTo(RAW_FIR)] firstPackageNamePart.kt
|
||||
package a.b.c
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] firstPackageNamePartScript.kts
|
||||
FILE: [ResolvedTo(RAW_FIR)] firstPackageNamePartScript.kts
|
||||
package a.b.c
|
||||
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
|
||||
+1
-1
@@ -6,5 +6,5 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] middlePackageNamePart.kt
|
||||
FILE: [ResolvedTo(RAW_FIR)] middlePackageNamePart.kt
|
||||
package a.b.c
|
||||
|
||||
Vendored
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] middlePackageNamePartScript.kts
|
||||
FILE: [ResolvedTo(RAW_FIR)] middlePackageNamePartScript.kts
|
||||
package a.b.c
|
||||
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
|
||||
+1
-1
@@ -6,5 +6,5 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] qualifiedPackageNamePart.kt
|
||||
FILE: [ResolvedTo(RAW_FIR)] qualifiedPackageNamePart.kt
|
||||
package a.b.c
|
||||
|
||||
Vendored
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] qualifiedPackageNamePartScript.kts
|
||||
FILE: [ResolvedTo(RAW_FIR)] qualifiedPackageNamePartScript.kts
|
||||
package a.b.c
|
||||
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
|
||||
+1
-1
@@ -6,5 +6,5 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] wholePackageDirective.kt
|
||||
FILE: [ResolvedTo(RAW_FIR)] wholePackageDirective.kt
|
||||
package a.b.c
|
||||
|
||||
Vendored
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] wholePackageDirectiveScript.kts
|
||||
FILE: [ResolvedTo(RAW_FIR)] wholePackageDirectiveScript.kts
|
||||
package a.b.c
|
||||
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
|
||||
+1
-1
@@ -6,5 +6,5 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] wholePackageName.kt
|
||||
FILE: [ResolvedTo(RAW_FIR)] wholePackageName.kt
|
||||
package a.b.c
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ FIR element rendered:
|
||||
package a.b.c
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] wholePackageNameScript.kts
|
||||
FILE: [ResolvedTo(RAW_FIR)] wholePackageNameScript.kts
|
||||
package a.b.c
|
||||
|
||||
context(<script>@kotlin.script.templates.standard.ScriptTemplateWithArgs)
|
||||
|
||||
+3
-3
@@ -4,9 +4,9 @@ FIR source kind: KtRealSourceElementKind
|
||||
|
||||
FIR element rendered:
|
||||
@FILE:R|kotlin/Suppress|[Types](names = vararg(String()))
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
[ResolvedTo(ANNOTATION_ARGUMENTS)] annotations container
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] fileAnnotationList.kt
|
||||
FILE: [ResolvedTo(IMPORTS)] fileAnnotationList.kt
|
||||
@FILE:R|kotlin/Suppress|[Types](names = vararg(String()))
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
[ResolvedTo(ANNOTATION_ARGUMENTS)] annotations container
|
||||
|
||||
Vendored
+3
-3
@@ -4,12 +4,12 @@ FIR source kind: KtRealSourceElementKind
|
||||
|
||||
FIR element rendered:
|
||||
@FILE:R|kotlin/Suppress|[Types](names = vararg(String()))
|
||||
[ResolvedTo(BODY_RESOLVE)] annotations container
|
||||
[ResolvedTo(ANNOTATION_ARGUMENTS)] annotations container
|
||||
|
||||
FIR FILE:
|
||||
FILE: [ResolvedTo(BODY_RESOLVE)] fileAnnotationListScript.kts
|
||||
FILE: [ResolvedTo(IMPORTS)] fileAnnotationListScript.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-fileAnnotationListScript.kts>
|
||||
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
|
||||
|
||||
Reference in New Issue
Block a user