Skip to content

Commit

Permalink
Simplify LighterASTNode.toFirLightSourceElement
Browse files Browse the repository at this point in the history
  • Loading branch information
mglukhikh committed Nov 26, 2020
1 parent 037c505 commit c6b703b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ private fun FirPsiSourceElement<*>.getChild(types: Set<IElementType>, index: Int
private fun FirLightSourceElement.getChild(types: Set<IElementType>, index: Int, depth: Int): FirSourceElement? {
val visitor = LighterTreeElementFinderByType(treeStructure, types, index, depth)

return visitor.find(lighterASTNode)?.let { it.toFirLightSourceElement(it.startOffset, it.endOffset, treeStructure) }
return visitor.find(lighterASTNode)?.toFirLightSourceElement(treeStructure)
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ val FirModifier<*>.lightNode: LighterASTNode? get() = (this as? FirLightModifier

val FirModifier<*>.source: FirSourceElement?
get() = when (this) {
is FirPsiModifier -> this.psi?.toFirPsiSourceElement()
is FirLightModifier -> {
// TODO pretty sure I got offsets wrong here
val startOffset = tree.getStartOffset(node)
val endOffset = tree.getEndOffset(node)
node.toFirLightSourceElement(startOffset, endOffset, tree)
}
is FirPsiModifier -> psi?.toFirPsiSourceElement()
is FirLightModifier -> node.toFirLightSourceElement(tree)
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ object FirAnnotationArgumentChecker : FirBasicDeclarationChecker() {
is FirLightSourceElement -> {
val elementOfParent = source.treeStructure.getParent(source.lighterASTNode) ?: source.lighterASTNode

elementOfParent.toFirLightSourceElement(elementOfParent.startOffset, elementOfParent.endOffset, source.treeStructure)
elementOfParent.toFirLightSourceElement(source.treeStructure)
}
else ->
source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ object FirExposedVisibilityDeclarationChecker : FirMemberDeclarationChecker() {
val kidsRef = Ref<Array<LighterASTNode?>>()
this.treeStructure.getChildren(lighterASTNode, kidsRef)
val identifier = kidsRef.get().find { it?.tokenType == KtTokens.IDENTIFIER }
identifier?.toFirLightSourceElement(this.treeStructure.getStartOffset(identifier), this.treeStructure.getEndOffset(identifier), this.treeStructure)
identifier?.toFirLightSourceElement(this.treeStructure)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ open class BaseConverter(
override fun LighterASTNode.toFirSourceElement(kind: FirFakeSourceElementKind?): FirLightSourceElement {
val startOffset = offset + tree.getStartOffset(this)
val endOffset = offset + tree.getEndOffset(this)
return toFirLightSourceElement(startOffset, endOffset, tree, kind ?: FirRealSourceElementKind)
return toFirLightSourceElement(tree, kind ?: FirRealSourceElementKind, startOffset, endOffset)
}

override val LighterASTNode.elementType: IElementType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class ValueParameter(
val parameterSource = firValueParameter.source as? FirLightSourceElement
val parameterNode = parameterSource?.lighterASTNode
source = parameterNode?.toFirLightSourceElement(
parameterSource.startOffset, parameterSource.endOffset, parameterSource.treeStructure,
FirFakeSourceElementKind.PropertyFromParameter
parameterSource.treeStructure, FirFakeSourceElementKind.PropertyFromParameter
)
this.session = session
origin = FirDeclarationOrigin.Source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ inline fun PsiElement.toFirPsiSourceElement(kind: FirSourceElementKind = FirReal

@Suppress("NOTHING_TO_INLINE")
inline fun LighterASTNode.toFirLightSourceElement(
startOffset: Int, endOffset: Int,
tree: FlyweightCapableTreeStructure<LighterASTNode>,
kind: FirSourceElementKind = FirRealSourceElementKind
kind: FirSourceElementKind = FirRealSourceElementKind,
startOffset: Int = this.startOffset,
endOffset: Int = this.endOffset
): FirLightSourceElement = FirLightSourceElement(this, startOffset, endOffset, tree, kind)

0 comments on commit c6b703b

Please sign in to comment.