[FIR IDE] Add OnAir resolve tests

This commit is contained in:
Igor Yakovlev
2021-05-06 14:08:38 +02:00
committed by TeamCityServer
parent 633e03b710
commit 0569f810cf
35 changed files with 361 additions and 0 deletions
@@ -1075,6 +1075,9 @@ fun main(args: Array<String>) {
testClass<AbstractFirSealedInheritorsTest> {
model("resolveSealed", recursive = false, extension = null)
}
testClass<AbstractFirOnAirResolveTest> {
model("onAirResolve")
}
testClass<AbstractFirLazyDeclarationResolveTest> {
model("lazyResolve")
}
@@ -0,0 +1,9 @@
class X<T> {
class Y<K>
open class BASE
/*PLACE*/class PLACE
}
/*ONAIR*/inner class ONAIR : BASE() {
fun x() = Y<T>()
}
@@ -0,0 +1,10 @@
public final inner [BODY_RESOLVE] class ONAIR<T> : R|X.BASE| {
public [BODY_RESOLVE] constructor(): R|X.ONAIR<T>| {
super<R|X.BASE|>()
}
public final [BODY_RESOLVE] fun x(): R|X.Y<T>| {
^x R|SubstitutionOverride</X.Y.Y>|<R|T|>()
}
}
@@ -0,0 +1,10 @@
fun xxx() {
val f = 2
val g = "x"
/*PLACE*/val x = g
}
fun x() {
/*ONAIR*/val y = f
}
@@ -0,0 +1 @@
[BODY_RESOLVE] lval y: R|kotlin/Int| = R|<local>/f|
@@ -0,0 +1,6 @@
class X {
class Y
fun x(/*PLACE*/x: Int) {}
}
fun y(/*ONAIR*/y: Y) {}
@@ -0,0 +1 @@
[BODY_RESOLVE] y: R|X.Y|
@@ -0,0 +1,8 @@
class A {
class B
}
val a: /*PLACE*/A.B.C
val b: /*ONAIR*/A.B
@@ -0,0 +1,2 @@
public final [BODY_RESOLVE] val b: R|A.B|
[BODY_RESOLVE] public get(): R|A.B|
@@ -0,0 +1,9 @@
fun xxx() {
val x = 2
/*PLACE*/class C
}
/*ONAIR*/class E {
fun e() = x
}
@@ -0,0 +1,10 @@
public? final? [BODY_RESOLVE] class E : R|kotlin/Any| {
public? [BODY_RESOLVE] constructor(): R|E| {
super<R|kotlin/Any|>()
}
public? final? [BODY_RESOLVE] fun e(): R|kotlin/Int| {
^e R|<local>/x|
}
}
@@ -0,0 +1,6 @@
fun xxx() {
val x = 3
/*PLACE*/fun lcl() = ""
}
/*ONAIR*/fun x() = x
@@ -0,0 +1,3 @@
local final [BODY_RESOLVE] fun x(): R|kotlin/Int| {
^x R|<local>/x|
}
@@ -0,0 +1,13 @@
class X
fun f(): X {
var x = 3
val y = 4
/*PLACE*/while(true) {}
}
fun g(): X {
/*ONAIR*/while (x < 2) {
x--
val z = y
}
}
@@ -0,0 +1,6 @@
while(CMP(<, R|<local>/x|.R|kotlin/Int.compareTo|(Int(2)))) {
[BODY_RESOLVE] lval <unary>: R|kotlin/Int| = R|<local>/x|
R|<local>/x| = R|<local>/<unary>|.R|kotlin/Int.dec|()
R|<local>/<unary>|
[BODY_RESOLVE] lval z: R|kotlin/Int| = R|<local>/y|
}
@@ -0,0 +1,5 @@
class Cls<T, K> {
/*PLACE*/fun member<T>(x: Int) = 2
}
/*ONAIR*/fun niewbe<K>(a: Char, b: Double) = "Trololo"
@@ -0,0 +1,3 @@
public final [BODY_RESOLVE] fun <K> niewbe([BODY_RESOLVE] a: R|kotlin/Char|, [BODY_RESOLVE] b: R|kotlin/Double|): R|kotlin/String| {
^niewbe String(Trololo)
}
@@ -0,0 +1,5 @@
class Cls {
/*PLACE*/val memberProperty = 2
}
/*ONAIR*/val niewbe = "Hello"
@@ -0,0 +1,2 @@
public final [BODY_RESOLVE] val niewbe: R|kotlin/String| = String(Hello)
[BODY_RESOLVE] public get(): R|kotlin/String|
@@ -0,0 +1,9 @@
interface Base {
fun baseMember(): Int
}
class Derived : Base {
/*PLACE*/fun someMember() = "Hello"
}
/*ONAIR*/override fun baseMember() = 3
@@ -0,0 +1,3 @@
public final override [BODY_RESOLVE] fun baseMember(): R|kotlin/Int| {
^baseMember Int(3)
}
@@ -0,0 +1,9 @@
open class X {
/*PLACE*/class PLACE
}
/*ONAIR*/class Y {
open class BASE : X()
class DERIVED : BASE()
fun withType(arg: BASE) { }
}
@@ -0,0 +1,23 @@
public final [BODY_RESOLVE] class Y : R|kotlin/Any| {
public [BODY_RESOLVE] constructor(): R|X.Y| {
super<R|kotlin/Any|>()
}
public? open [BODY_RESOLVE] class BASE : R|X| {
public? [BODY_RESOLVE] constructor(): R|X.Y.BASE| {
super<R|X|>()
}
}
public? final? [BODY_RESOLVE] class DERIVED : R|X.Y.BASE| {
public? [BODY_RESOLVE] constructor(): R|X.Y.DERIVED| {
super<R|X.Y.BASE|>()
}
}
public final [BODY_RESOLVE] fun withType([BODY_RESOLVE] arg: R|X.Y.BASE|): R|kotlin/Unit| {
}
}
@@ -0,0 +1,9 @@
class C<T> {
fun x(/*PLACE*/a: Int) {
}
}
fun y(/*ONAIR*/b: T) {
}
@@ -0,0 +1 @@
[BODY_RESOLVE] b: R|T|
@@ -0,0 +1,8 @@
val x: Int get() {
val qqq = "Hello"
/*PLACE*/val x = 42
2
}
/*ONAIR*/val z = qqq
@@ -0,0 +1,2 @@
public? final? [BODY_RESOLVE] val z: R|kotlin/String| = R|<local>/qqq|
[BODY_RESOLVE] public? get(): R|kotlin/String|
@@ -0,0 +1,6 @@
var x = 2
set(value) {
/*PLACE*/val inside = ""
}
/*ONAIR*/val inSetter = value
@@ -0,0 +1,2 @@
public? final? [BODY_RESOLVE] val inSetter: R|kotlin/Int| = R|<local>/value|
[BODY_RESOLVE] public? get(): R|kotlin/Int|
@@ -0,0 +1,8 @@
/*PLACE*/fun place(): Int {
fun xxx() = 2
}
/*ONAIR*/fun onAir(): Int {
fun yyy() = "hello"
}
@@ -0,0 +1,6 @@
public final [BODY_RESOLVE] fun onAir(): R|kotlin/Int| {
local final [BODY_RESOLVE] fun yyy(): R|kotlin/String| {
^yyy String(hello)
}
}
@@ -0,0 +1,8 @@
class X<T, K> {
/*PLACE*/private typealias A = List<T>
}
class Y {
/*ONAIR*/public typealias B = Set<K>
}
@@ -0,0 +1 @@
public final [BODY_RESOLVE] typealias B = R|kotlin/collections/Set<K>|
@@ -0,0 +1,43 @@
/*
* 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.idea.fir.low.level.api
import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.kotlin.fir.FirRenderer
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.idea.fir.low.level.api.api.LowLevelFirApiFacadeForResolveOnAir
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.util.findElementByCommentPrefix
import java.io.File
abstract class AbstractFirOnAirResolveTest : KotlinLightCodeInsightFixtureTestCase() {
override fun isFirPlugin(): Boolean = true
fun doTest(path: String) {
val testDataFile = File(path)
val ktFile = myFixture.configureByText(testDataFile.name, FileUtil.loadFile(testDataFile)) as KtFile
val place = ktFile.findElementByCommentPrefix("/*PLACE*/") as KtElement
val onAir = ktFile.findElementByCommentPrefix("/*ONAIR*/") as KtElement
check(place::class == onAir::class)
resolveWithClearCaches(ktFile) { firModuleResolveState ->
check(firModuleResolveState is FirModuleResolveStateImpl)
val firElement = LowLevelFirApiFacadeForResolveOnAir.onAirResolveElement(firModuleResolveState, place, onAir)
val rendered = firElement.render(FirRenderer.RenderMode.WithResolvePhases)
val expectedFileName = testDataFile.name.replace(".kt", ".txt")
KotlinTestUtils.assertEqualsToFile(testDataFile.parentFile.resolve(expectedFileName), rendered)
}
}
override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
}
@@ -0,0 +1,111 @@
/*
* 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.idea.fir.low.level.api;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class FirOnAirResolveTestGenerated extends AbstractFirOnAirResolveTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInOnAirResolve() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("classInClass.kt")
public void testClassInClass() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/classInClass.kt");
}
@TestMetadata("identifierInContext.kt")
public void testIdentifierInContext() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/identifierInContext.kt");
}
@TestMetadata("inParameter.kt")
public void testInParameter() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/inParameter.kt");
}
@TestMetadata("incompleteIdentifier.kt")
public void testIncompleteIdentifier() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/incompleteIdentifier.kt");
}
@TestMetadata("localClass.kt")
public void testLocalClass() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/localClass.kt");
}
@TestMetadata("localFunction.kt")
public void testLocalFunction() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/localFunction.kt");
}
@TestMetadata("loopConstruction.kt")
public void testLoopConstruction() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/loopConstruction.kt");
}
@TestMetadata("memberInClass.kt")
public void testMemberInClass() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/memberInClass.kt");
}
@TestMetadata("memberPropertyInClass.kt")
public void testMemberPropertyInClass() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/memberPropertyInClass.kt");
}
@TestMetadata("memberWithOverride.kt")
public void testMemberWithOverride() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/memberWithOverride.kt");
}
@TestMetadata("onAirTypesResolve.kt")
public void testOnAirTypesResolve() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/onAirTypesResolve.kt");
}
@TestMetadata("replacementInHeader.kt")
public void testReplacementInHeader() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/replacementInHeader.kt");
}
@TestMetadata("replacementInsidePropertyBody.kt")
public void testReplacementInsidePropertyBody() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/replacementInsidePropertyBody.kt");
}
@TestMetadata("replacementInsidePropertyBody2.kt")
public void testReplacementInsidePropertyBody2() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/replacementInsidePropertyBody2.kt");
}
@TestMetadata("topLevelFunction.kt")
public void testTopLevelFunction() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/topLevelFunction.kt");
}
@TestMetadata("typeAlias.kt")
public void testTypeAlias() throws Exception {
runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/onAirResolve/typeAlias.kt");
}
}