[FIR] Make LighterASTNode.getChildren utility return list of not null nodes

This commit is contained in:
Dmitriy Novozhilov
2021-10-21 14:49:39 +03:00
committed by teamcityserver
parent f52361ac2b
commit bf453674b9
4 changed files with 6 additions and 6 deletions
@@ -41,7 +41,7 @@ sealed class FirModifierList {
override val modifiers: List<FirModifier.FirLightModifier>
get() {
val modifierNodes = modifierList.getChildren(tree)
return modifierNodes.filterNotNull()
return modifierNodes
.filter { it.tokenType is KtModifierKeywordToken }
.map { FirModifier.FirLightModifier(it, it.tokenType as KtModifierKeywordToken, tree, offsetDelta) }
}
@@ -86,7 +86,7 @@ fun FirSourceElement?.getModifierList(): FirModifierList? {
null -> null
is FirPsiSourceElement -> (psi as? KtModifierListOwner)?.modifierList?.let { FirModifierList.FirPsiModifierList(it) }
is FirLightSourceElement -> {
val modifierListNode = lighterASTNode.getChildren(treeStructure).find { it?.tokenType == KtNodeTypes.MODIFIER_LIST }
val modifierListNode = lighterASTNode.getChildren(treeStructure).find { it.tokenType == KtNodeTypes.MODIFIER_LIST }
?: return null
val offsetDelta = startOffset - lighterASTNode.startOffset
FirModifierList.FirLightModifierList(modifierListNode, treeStructure, offsetDelta)
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtModifierList
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType
internal fun LighterASTNode.getChildren(tree: FlyweightCapableTreeStructure<LighterASTNode>): List<LighterASTNode?> {
internal fun LighterASTNode.getChildren(tree: FlyweightCapableTreeStructure<LighterASTNode>): List<LighterASTNode> {
val children = Ref<Array<LighterASTNode?>>()
val count = tree.getChildren(this, children)
return if (count > 0) children.get().filterNotNull() else emptyList()
@@ -108,7 +108,7 @@ object CanBeValChecker : AbstractFirPropertyInitializationChecker() {
private fun FirPropertySymbol.getDestructuringChildrenCount(): Int? {
val source = source ?: return null
return source.lighterASTNode.getChildren(source.treeStructure).count {
it?.tokenType == KtNodeTypes.DESTRUCTURING_DECLARATION_ENTRY
it.tokenType == KtNodeTypes.DESTRUCTURING_DECLARATION_ENTRY
}
}
@@ -83,10 +83,10 @@ private val FILLER_TOKENS = setOf(
)
private fun LighterASTNode.nonFillerFirstChildOrSelf(tree: FlyweightCapableTreeStructure<LighterASTNode>): LighterASTNode =
getChildren(tree).firstOrNull { it != null && !it.isFiller() } ?: this
getChildren(tree).firstOrNull { !it.isFiller() } ?: this
internal fun LighterASTNode.nonFillerLastChildOrSelf(tree: FlyweightCapableTreeStructure<LighterASTNode>): LighterASTNode =
getChildren(tree).lastOrNull { it != null && !it.isFiller() } ?: this
getChildren(tree).lastOrNull { !it.isFiller() } ?: this
internal fun LighterASTNode.isFiller() = tokenType in FILLER_TOKENS