FIR LC: add tests about type approximation in PsiType provider
This commit is contained in:
committed by
Roman Golyshev
parent
c441980c74
commit
9ed2c9d371
+34
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
+68
@@ -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");
|
||||
}
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
fun f<caret>oo() = object : Runnable {
|
||||
override fun run() {}
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
KtType: java.lang.Runnable
|
||||
PsiType: PsiType:Runnable
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
fun f<caret>oo(): Runnable {
|
||||
class Local : Runnable {
|
||||
override fun run() {}
|
||||
}
|
||||
return Local()
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
KtType: java.lang.Runnable
|
||||
PsiType: PsiType:Runnable
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
private fun f<caret>oo() = run {
|
||||
class Local {
|
||||
fun bar(): Local {
|
||||
return this
|
||||
}
|
||||
}
|
||||
val p = Local().bar()
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
KtType: kotlin.Unit
|
||||
PsiType: PsiType:Unit
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
fun foo() {
|
||||
class Local {
|
||||
}
|
||||
fun b<caret>ar() = Local()
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
KtType: Local
|
||||
PsiType: PsiType:Object
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
fun foo() = run {
|
||||
class Local {
|
||||
fun bar(): Local {
|
||||
return this
|
||||
}
|
||||
}
|
||||
val p<caret> = Local().bar()
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
KtType: Local
|
||||
PsiType: PsiType:Object
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun foo() {
|
||||
class Local {
|
||||
}
|
||||
val a<caret> = fun (): Local {
|
||||
return Local()
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
KtType: () -> Local
|
||||
PsiType: PsiType:Function0<? extends Object>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun foo() {
|
||||
class Local {
|
||||
fun b<caret>ar(): Local {
|
||||
return this
|
||||
}
|
||||
}
|
||||
val a = Local().bar()
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
KtType: Local
|
||||
PsiType: PsiType:Object
|
||||
+4
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user