[FIR] Support some kinds of fake sources in light builder

This commit is contained in:
Mikhail Glukhikh
2020-08-02 14:46:26 +03:00
parent 951aa8185e
commit 4e4fe9f719
3 changed files with 12 additions and 7 deletions
@@ -31,7 +31,7 @@ open class BaseConverter(
override fun LighterASTNode.toFirSourceElement(kind: FirFakeSourceElementKind?): FirLightSourceElement { override fun LighterASTNode.toFirSourceElement(kind: FirFakeSourceElementKind?): FirLightSourceElement {
val startOffset = offset + tree.getStartOffset(this) val startOffset = offset + tree.getStartOffset(this)
val endOffset = offset + tree.getEndOffset(this) val endOffset = offset + tree.getEndOffset(this)
return toFirLightSourceElement(startOffset, endOffset, tree) return toFirLightSourceElement(startOffset, endOffset, tree, kind ?: FirRealSourceElementKind)
} }
override val LighterASTNode.elementType: IElementType override val LighterASTNode.elementType: IElementType
@@ -457,7 +457,7 @@ class DeclarationsConverter(
) )
//parse primary constructor //parse primary constructor
val primaryConstructorWrapper = convertPrimaryConstructor( val primaryConstructorWrapper = convertPrimaryConstructor(
primaryConstructor, classWrapper, delegatedConstructorSource, primaryConstructor, classNode, classWrapper, delegatedConstructorSource,
delegationSpecifiers?.primaryConstructorBody delegationSpecifiers?.primaryConstructorBody
) )
val firPrimaryConstructor = primaryConstructorWrapper?.firConstructor val firPrimaryConstructor = primaryConstructorWrapper?.firConstructor
@@ -564,7 +564,7 @@ class DeclarationsConverter(
superTypeCallEntry = superTypeCallEntry superTypeCallEntry = superTypeCallEntry
) )
//parse primary constructor //parse primary constructor
convertPrimaryConstructor(primaryConstructor, classWrapper, delegatedConstructorSource, primaryConstructorBody) convertPrimaryConstructor(primaryConstructor, objectLiteral, classWrapper, delegatedConstructorSource, primaryConstructorBody)
?.let { this.declarations += it.firConstructor } ?.let { this.declarations += it.firConstructor }
//parse declarations //parse declarations
@@ -635,7 +635,9 @@ class DeclarationsConverter(
superTypeCallEntry = enumSuperTypeCallEntry superTypeCallEntry = enumSuperTypeCallEntry
) )
superTypeRefs += enumClassWrapper.delegatedSuperTypeRef superTypeRefs += enumClassWrapper.delegatedSuperTypeRef
convertPrimaryConstructor(null, enumClassWrapper, null)?.let { declarations += it.firConstructor } convertPrimaryConstructor(null, enumEntry, enumClassWrapper, null)?.let {
declarations += it.firConstructor
}
classBodyNode?.also { declarations += convertClassBody(it, enumClassWrapper) } classBodyNode?.also { declarations += convertClassBody(it, enumClassWrapper) }
} }
} }
@@ -683,6 +685,7 @@ class DeclarationsConverter(
*/ */
private fun convertPrimaryConstructor( private fun convertPrimaryConstructor(
primaryConstructor: LighterASTNode?, primaryConstructor: LighterASTNode?,
classNode: LighterASTNode,
classWrapper: ClassWrapper, classWrapper: ClassWrapper,
delegatedConstructorSource: FirLightSourceElement?, delegatedConstructorSource: FirLightSourceElement?,
body: FirBlock? = null body: FirBlock? = null
@@ -719,6 +722,7 @@ class DeclarationsConverter(
return PrimaryConstructor( return PrimaryConstructor(
buildPrimaryConstructor { buildPrimaryConstructor {
source = primaryConstructor?.toFirSourceElement() source = primaryConstructor?.toFirSourceElement()
?: classNode.toFirSourceElement(FirFakeSourceElementKind.ImplicitConstructor)
session = baseSession session = baseSession
origin = FirDeclarationOrigin.Source origin = FirDeclarationOrigin.Source
returnTypeRef = classWrapper.delegatedSelfTypeRef returnTypeRef = classWrapper.delegatedSelfTypeRef
@@ -1343,7 +1347,7 @@ class DeclarationsConverter(
delegatedSuperTypeRef = first delegatedSuperTypeRef = first
superTypeRefs += first superTypeRefs += first
superTypeCallEntry += second superTypeCallEntry += second
delegateConstructorSource = it.toFirSourceElement() delegateConstructorSource = it.toFirSourceElement(FirFakeSourceElementKind.DelegatingConstructorCall)
} }
DELEGATED_SUPER_TYPE_ENTRY -> { DELEGATED_SUPER_TYPE_ENTRY -> {
superTypeRefs += convertExplicitDelegation(it, delegateNumber, delegateFields, initializeDelegateStatements, containerSymbol, delegatedTypeRef) superTypeRefs += convertExplicitDelegation(it, delegateNumber, delegateFields, initializeDelegateStatements, containerSymbol, delegatedTypeRef)
@@ -201,7 +201,8 @@ inline fun PsiElement.toFirPsiSourceElement(kind: FirSourceElementKind = FirReal
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun LighterASTNode.toFirLightSourceElement( inline fun LighterASTNode.toFirLightSourceElement(
startOffset: Int, endOffset: Int, startOffset: Int, endOffset: Int,
tree: FlyweightCapableTreeStructure<LighterASTNode> tree: FlyweightCapableTreeStructure<LighterASTNode>,
): FirLightSourceElement = FirLightSourceElement(this, startOffset, endOffset, tree) kind: FirSourceElementKind = FirRealSourceElementKind
): FirLightSourceElement = FirLightSourceElement(this, startOffset, endOffset, tree, kind)
val FirSourceElement?.lightNode: LighterASTNode? get() = (this as? FirLightSourceElement)?.element val FirSourceElement?.lightNode: LighterASTNode? get() = (this as? FirLightSourceElement)?.element