[FIR] Make check for dangling modifier lists use stubs

Seventh step for ^KT-52615

Merge-request: KT-MR-8651
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
This commit is contained in:
Egor Kulikov
2023-02-03 12:21:58 +00:00
committed by Space Team
parent 0da23d4b9c
commit 8b1e508740
3 changed files with 19 additions and 8 deletions
@@ -69,5 +69,11 @@ class KtClassBody : KtElementImplStub<KotlinPlaceHolderStub<KtClassBody>>, KtDec
* @return annotations that do not belong to any declaration due to incomplete code or syntax errors
*/
val danglingAnnotations: List<KtAnnotationEntry>
get() = getStubOrPsiChildrenAsList(MODIFIER_LIST).flatMap { it.annotationEntries }
get() = danglingModifierLists.flatMap { it.annotationEntries }
/**
* @return modifier lists that do not belong to any declaration due to incomplete code or syntax errors
*/
val danglingModifierLists: List<KtModifierList>
get() = getStubOrPsiChildrenAsList(MODIFIER_LIST)
}
@@ -128,18 +128,23 @@ open class KtFile(viewProvider: FileViewProvider, val isCompiled: Boolean) :
get() = script != null
/**
* @return annotations that do not belong to any declaration due to incomplete code or syntax errors
* @return modifier lists that do not belong to any declaration due to incomplete code or syntax errors
*/
val danglingAnnotations: List<KtAnnotationEntry>
val danglingModifierLists: Array<out KtModifierList>
get() {
val stub = stub
val danglingModifierLists = stub?.getChildrenByType(
return stub?.getChildrenByType(
KtStubElementTypes.MODIFIER_LIST,
KtStubElementTypes.MODIFIER_LIST.arrayFactory
) ?: findChildrenByClass(KtModifierList::class.java)
return danglingModifierLists.flatMap { obj: KtModifierList -> obj.annotationEntries }
}
/**
* @return annotations that do not belong to any declaration due to incomplete code or syntax errors
*/
val danglingAnnotations: List<KtAnnotationEntry>
get() = danglingModifierLists.flatMap { obj: KtModifierList -> obj.annotationEntries }
override fun getFileType(): FileType = KotlinFileType.INSTANCE
override fun toString(): String = "KtFile: $name"