[FIR] Enhance light tree DEFAULT strategy for objects to cover header only

This commit is contained in:
Mikhail Glukhikh
2020-11-17 15:15:11 +03:00
parent d844b33b1c
commit 42c59f7383
2 changed files with 20 additions and 10 deletions
@@ -16,6 +16,25 @@ import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtParameter.VAL_VAR_TOKEN_SET
object LightTreePositioningStrategies {
internal val DEFAULT = object : LightTreePositioningStrategy() {
override fun mark(node: LighterASTNode, tree: FlyweightCapableTreeStructure<LighterASTNode>): List<TextRange> {
when (node.tokenType) {
KtNodeTypes.OBJECT_DECLARATION -> {
val objectKeyword = tree.findChildByType(node, KtTokens.OBJECT_KEYWORD)!!
return markRange(
from = objectKeyword,
to = tree.findChildByType(node, KtTokens.IDENTIFIER) ?: objectKeyword,
tree
)
}
KtNodeTypes.CONSTRUCTOR_DELEGATION_CALL -> {
return SECONDARY_CONSTRUCTOR_DELEGATION_CALL.mark(node, tree)
}
}
return super.mark(node, tree)
}
}
val VAL_OR_VAR_NODE: LightTreePositioningStrategy = object : LightTreePositioningStrategy() {
override fun mark(node: LighterASTNode, tree: FlyweightCapableTreeStructure<LighterASTNode>): List<TextRange> {
val target = tree.findChildByType(node, VAL_VAR_TOKEN_SET) ?: node
@@ -21,16 +21,7 @@ open class LightTreePositioningStrategy {
}
companion object {
val DEFAULT = object : LightTreePositioningStrategy() {
override fun mark(node: LighterASTNode, tree: FlyweightCapableTreeStructure<LighterASTNode>): List<TextRange> {
when (node.tokenType) {
KtNodeTypes.CONSTRUCTOR_DELEGATION_CALL -> {
return LightTreePositioningStrategies.SECONDARY_CONSTRUCTOR_DELEGATION_CALL.mark(node, tree)
}
}
return super.mark(node, tree)
}
}
val DEFAULT = LightTreePositioningStrategies.DEFAULT
}
}