FIR LC: add tests about type approximation in PsiType provider

This commit is contained in:
Jinseong Jeon
2021-10-07 22:01:55 -07:00
committed by Roman Golyshev
parent c441980c74
commit 9ed2c9d371
17 changed files with 165 additions and 0 deletions
@@ -0,0 +1,34 @@
/*
* Copyright 2010-2021 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.analysis.api.fir.components
import org.jetbrains.kotlin.analysis.api.analyse
import org.jetbrains.kotlin.analysis.api.fir.test.framework.AbstractHLApiSingleModuleTest
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.expressionMarkerProvider
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions
abstract class AbstractPsiTypeProviderTest : AbstractHLApiSingleModuleTest() {
override fun doTestByFileStructure(ktFiles: List<KtFile>, module: TestModule, testServices: TestServices) {
val mainKtFile = ktFiles.singleOrNull() ?: ktFiles.first { it.name == "main.kt" }
val declaration = testServices.expressionMarkerProvider.getElementOfTypAtCaret<KtDeclaration>(mainKtFile)
val actual = buildString {
executeOnPooledThreadInReadAction {
analyse(declaration) {
val ktType = declaration.getReturnKtType()
appendLine("KtType: ${ktType.render()}")
appendLine("PsiType: ${ktType.asPsiType(declaration)}")
}
}
}
testServices.assertions.assertEqualsToFile(testDataFileSibling(".txt"), actual)
}
}
@@ -0,0 +1,68 @@
/*
* Copyright 2010-2021 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.analysis.api.fir.components;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("analysis/analysis-api/testData/components/psiTypeProvider")
@TestDataPath("$PROJECT_ROOT")
public class PsiTypeProviderTestGenerated extends AbstractPsiTypeProviderTest {
@Test
public void testAllFilesPresentInPsiTypeProvider() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/psiTypeProvider"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("anonymousObject_exposedAsReturnValue.kt")
public void testAnonymousObject_exposedAsReturnValue() throws Exception {
runTest("analysis/analysis-api/testData/components/psiTypeProvider/anonymousObject_exposedAsReturnValue.kt");
}
@Test
@TestMetadata("localClass_exposedAsReturnValue.kt")
public void testLocalClass_exposedAsReturnValue() throws Exception {
runTest("analysis/analysis-api/testData/components/psiTypeProvider/localClass_exposedAsReturnValue.kt");
}
@Test
@TestMetadata("localClass_exposedAsReturnValue_privateFunction.kt")
public void testLocalClass_exposedAsReturnValue_privateFunction() throws Exception {
runTest("analysis/analysis-api/testData/components/psiTypeProvider/localClass_exposedAsReturnValue_privateFunction.kt");
}
@Test
@TestMetadata("localClass_localFunctionInSameScope.kt")
public void testLocalClass_localFunctionInSameScope() throws Exception {
runTest("analysis/analysis-api/testData/components/psiTypeProvider/localClass_localFunctionInSameScope.kt");
}
@Test
@TestMetadata("localClass_localPropertyInSameScope.kt")
public void testLocalClass_localPropertyInSameScope() throws Exception {
runTest("analysis/analysis-api/testData/components/psiTypeProvider/localClass_localPropertyInSameScope.kt");
}
@Test
@TestMetadata("localClass_localPropertyInSampeScope_functionalType.kt")
public void testLocalClass_localPropertyInSampeScope_functionalType() throws Exception {
runTest("analysis/analysis-api/testData/components/psiTypeProvider/localClass_localPropertyInSampeScope_functionalType.kt");
}
@Test
@TestMetadata("localClass_memberFunction.kt")
public void testLocalClass_memberFunction() throws Exception {
runTest("analysis/analysis-api/testData/components/psiTypeProvider/localClass_memberFunction.kt");
}
}
@@ -0,0 +1,3 @@
fun f<caret>oo() = object : Runnable {
override fun run() {}
}
@@ -0,0 +1,2 @@
KtType: java.lang.Runnable
PsiType: PsiType:Runnable
@@ -0,0 +1,6 @@
fun f<caret>oo(): Runnable {
class Local : Runnable {
override fun run() {}
}
return Local()
}
@@ -0,0 +1,2 @@
KtType: java.lang.Runnable
PsiType: PsiType:Runnable
@@ -0,0 +1,8 @@
private fun f<caret>oo() = run {
class Local {
fun bar(): Local {
return this
}
}
val p = Local().bar()
}
@@ -0,0 +1,2 @@
KtType: kotlin.Unit
PsiType: PsiType:Unit
@@ -0,0 +1,5 @@
fun foo() {
class Local {
}
fun b<caret>ar() = Local()
}
@@ -0,0 +1,2 @@
KtType: Local
PsiType: PsiType:Object
@@ -0,0 +1,8 @@
fun foo() = run {
class Local {
fun bar(): Local {
return this
}
}
val p<caret> = Local().bar()
}
@@ -0,0 +1,2 @@
KtType: Local
PsiType: PsiType:Object
@@ -0,0 +1,7 @@
fun foo() {
class Local {
}
val a<caret> = fun (): Local {
return Local()
}
}
@@ -0,0 +1,2 @@
KtType: () -> Local
PsiType: PsiType:Function0<? extends Object>
@@ -0,0 +1,8 @@
fun foo() {
class Local {
fun b<caret>ar(): Local {
return this
}
}
val a = Local().bar()
}
@@ -0,0 +1,2 @@
KtType: Local
PsiType: PsiType:Object
@@ -99,6 +99,10 @@ fun main(args: Array<String>) {
testClass<AbstractFirGetSuperTypesTest> {
model("components/getSuperTypes")
}
testClass<AbstractPsiTypeProviderTest> {
model("components/psiTypeProvider")
}
}
testGroup("analysis/analysis-api-fe10/tests", "analysis/analysis-api/testData") {