FIR IDE: separate KtExpressionTypeProvider into components

This commit is contained in:
Ilya Kirillov
2020-12-13 21:51:52 +01:00
parent 2101816f03
commit 2d5b23b650
9 changed files with 205 additions and 139 deletions
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.psi.*
*/
abstract class KtAnalysisSession(final override val token: ValidityToken) : ValidityTokenOwner {
protected abstract val smartCastProvider: KtSmartCastProvider
protected abstract val typeProvider: KtTypeProvider
protected abstract val diagnosticProvider: KtDiagnosticProvider
protected abstract val scopeProvider: KtScopeProvider
protected abstract val containingDeclarationProvider: KtSymbolContainingDeclarationProvider
@@ -45,7 +44,11 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
protected abstract val completionCandidateChecker: KtCompletionCandidateChecker
protected abstract val symbolDeclarationOverridesProvider: KtSymbolDeclarationOverridesProvider
@Suppress("LeakingThis")
protected open val typeRenderer: KtTypeRenderer = KtDefaultTypeRenderer(this, token)
protected abstract val expressionTypeProvider: KtExpressionTypeProvider
protected abstract val typeProvider: KtTypeProvider
protected abstract val subtypingComponent: KtSubtypingComponent
protected abstract val expressionHandlingComponent: KtExpressionHandlingComponent
/// TODO: get rid of
@@ -59,18 +62,20 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
fun KtExpression.getImplicitReceiverSmartCasts(): Collection<ImplicitReceiverSmartCast> = smartCastProvider.getImplicitReceiverSmartCasts(this)
fun KtExpression.getKtType(): KtType = typeProvider.getKtExpressionType(this)
fun KtExpression.getKtType(): KtType = expressionTypeProvider.getKtExpressionType(this)
fun KtDeclaration.getReturnKtType(): KtType = typeProvider.getReturnTypeForKtDeclaration(this)
fun KtDeclaration.getReturnKtType(): KtType = expressionTypeProvider.getReturnTypeForKtDeclaration(this)
infix fun KtType.isEqualTo(other: KtType): Boolean = typeProvider.isEqualTo(this, other)
infix fun KtType.isEqualTo(other: KtType): Boolean = subtypingComponent.isEqualTo(this, other)
infix fun KtType.isSubTypeOf(superType: KtType): Boolean = typeProvider.isSubTypeOf(this, superType)
infix fun KtType.isSubTypeOf(superType: KtType): Boolean = subtypingComponent.isSubTypeOf(this, superType)
fun PsiElement.getExpectedType(): KtType? = typeProvider.getExpectedType(this)
fun PsiElement.getExpectedType(): KtType? = expressionTypeProvider.getExpectedType(this)
fun KtType.isBuiltInFunctionalType(): Boolean = typeProvider.isBuiltinFunctionalType(this)
val builtinTypes: KtBuiltinTypes get() = typeProvider.builtinTypes
fun KtElement.getDiagnostics(): Collection<Diagnostic> = diagnosticProvider.getDiagnosticsForElement(this)
fun KtFile.collectDiagnosticsForFile(): Collection<Diagnostic> = diagnosticProvider.collectDiagnosticsForFile(this)
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.frontend.api.components
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtExpression
abstract class KtExpressionTypeProvider : KtAnalysisSessionComponent() {
abstract fun getReturnTypeForKtDeclaration(declaration: KtDeclaration): KtType
abstract fun getKtExpressionType(expression: KtExpression): KtType
abstract fun getExpectedType(expression: PsiElement): KtType?
}
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.frontend.api.components
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
abstract class KtSubtypingComponent : KtAnalysisSessionComponent() {
abstract fun isEqualTo(first: KtType, second: KtType): Boolean
abstract fun isSubTypeOf(subType: KtType, superType: KtType): Boolean
}
@@ -5,27 +5,17 @@
package org.jetbrains.kotlin.idea.frontend.api.components
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtExpression
abstract class KtTypeProvider : KtAnalysisSessionComponent() {
abstract fun getReturnTypeForKtDeclaration(declaration: KtDeclaration): KtType
abstract fun getKtExpressionType(expression: KtExpression): KtType
abstract fun isEqualTo(first: KtType, second: KtType): Boolean
abstract fun isSubTypeOf(subType: KtType, superType: KtType): Boolean
//TODO get rid of
//TODO get rid of it
abstract fun isBuiltinFunctionalType(type: KtType): Boolean
abstract fun getExpectedType(expression: PsiElement): KtType?
abstract val builtinTypes: KtBuiltinTypes
}
@Suppress("PropertyName")
abstract class KtBuiltinTypes : ValidityTokenOwner {
abstract val INT: KtType