[FIR] Support type code fragments in 'PsiRawFirBuilder'
For type code fragments, which essentially contain a single type reference, we add a single statement 'null is Type'. ^KT-61332 Fixed
This commit is contained in:
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
import org.jetbrains.kotlin.psi.stubs.KotlinFileStub
|
import org.jetbrains.kotlin.psi.stubs.KotlinFileStub
|
||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||||
|
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
@@ -1373,6 +1374,7 @@ open class PsiRawFirBuilder(
|
|||||||
when (file) {
|
when (file) {
|
||||||
is KtExpressionCodeFragment -> file.getContentElement()?.toFirBlock() ?: buildEmptyExpressionBlock()
|
is KtExpressionCodeFragment -> file.getContentElement()?.toFirBlock() ?: buildEmptyExpressionBlock()
|
||||||
is KtBlockCodeFragment -> configureBlockWithoutBuilding(file.getContentElement()).build()
|
is KtBlockCodeFragment -> configureBlockWithoutBuilding(file.getContentElement()).build()
|
||||||
|
is KtTypeCodeFragment -> convertTypeCodeFragmentBlock(file)
|
||||||
else -> error("Unexpected code fragment type: ${file::class}")
|
else -> error("Unexpected code fragment type: ${file::class}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1380,6 +1382,18 @@ open class PsiRawFirBuilder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun convertTypeCodeFragmentBlock(file: KtTypeCodeFragment): FirBlock {
|
||||||
|
return buildBlock {
|
||||||
|
statements += buildTypeOperatorCall {
|
||||||
|
operation = FirOperation.IS
|
||||||
|
conversionTypeRef = file.getContentElement().toFirOrErrorType()
|
||||||
|
argumentList = buildUnaryArgumentList(
|
||||||
|
buildLiteralExpression(source = null, ConstantValueKind.Null, value = null, setType = false)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitScript(script: KtScript, data: FirElement?): FirElement {
|
override fun visitScript(script: KtScript, data: FirElement?): FirElement {
|
||||||
val ktFile = script.containingKtFile
|
val ktFile = script.containingKtFile
|
||||||
val fileName = ktFile.name
|
val fileName = ktFile.name
|
||||||
|
|||||||
Reference in New Issue
Block a user