[Analysis API] Handle missed cases in PsiElement.getExpectedType()

^KTIJ-24256
This commit is contained in:
aleksandrina-streltsova
2023-01-19 21:48:30 +02:00
committed by teamcity
parent 7dd438cb9e
commit 3d0bca5ca1
70 changed files with 1112 additions and 72 deletions
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiSingleFileTest
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
import org.jetbrains.kotlin.analysis.test.framework.utils.executeOnPooledThreadInReadAction
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices
@@ -20,10 +21,11 @@ import org.jetbrains.kotlin.types.Variance
abstract class AbstractAnalysisApiGetSuperTypesTest : AbstractAnalysisApiSingleFileTest(){
override fun doTestByFileStructure(ktFile: KtFile, module: TestModule, testServices: TestServices) {
val expression = testServices.expressionMarkerProvider.getSelectedElement(ktFile)
expression as? KtExpression ?: error("unexpected expression kind ${expression::class}")
val actual = executeOnPooledThreadInReadAction {
analyze(expression) {
val expectedType = expression.getExpectedType() ?: error("expect to get type of expression '${expression.text}'")
val expectedType = expression.getKtType() ?: error("expect to get type of expression '${expression.text}'")
val directSuperTypes = expectedType.getDirectSuperTypes()
val approximatedDirectSuperTypes = expectedType.getDirectSuperTypes(shouldApproximate = true)
val allSuperTypes = expectedType.getAllSuperTypes()