From 61651c685c67f6db40ff687c99ce25fc5eccf105 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Mon, 21 Jun 2021 16:42:01 +0200 Subject: [PATCH] FIR IDE: restore FirLazyDeclarationResolveTest --- .../tests/frontend/api/GenerateTests.kt | 9 +- .../idea-fir-low-level-api/build.gradle.kts | 20 ++ .../testdata/lazyResolve/delegates.txt | 25 +- .../AbstractFirLazyDeclarationResolveTest.kt | 222 +++++++++-------- ...irLazyDeclarationResolveTestGenerated.java | 226 +++++++++++------- .../based/AbstractCompilerBasedTest.kt | 7 +- .../api/test/base/AbstractLowLevelApiTest.kt | 25 +- 7 files changed, 322 insertions(+), 212 deletions(-) diff --git a/generators/frontend-api-generator/tests/org/jetbrains/kotlin/generators/tests/frontend/api/GenerateTests.kt b/generators/frontend-api-generator/tests/org/jetbrains/kotlin/generators/tests/frontend/api/GenerateTests.kt index d50a4182b59..62f89d7498e 100644 --- a/generators/frontend-api-generator/tests/org/jetbrains/kotlin/generators/tests/frontend/api/GenerateTests.kt +++ b/generators/frontend-api-generator/tests/org/jetbrains/kotlin/generators/tests/frontend/api/GenerateTests.kt @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.idea.fir.frontend.api.symbols.AbstractSymbolByFqName import org.jetbrains.kotlin.idea.fir.frontend.api.symbols.AbstractSymbolByPsiTest import org.jetbrains.kotlin.idea.fir.frontend.api.symbols.AbstractSymbolByReferenceTest import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirLazyBodiesCalculatorTest -//import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirLazyDeclarationResolveTest +import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirLazyDeclarationResolveTest import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirOnAirResolveTest import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractPartialRawFirBuilderTestCase import org.jetbrains.kotlin.idea.fir.low.level.api.diagnostic.AbstractDiagnosticTraversalCounterTest @@ -90,9 +90,10 @@ fun main(args: Array) { testClass { model("onAirResolve") } -// testClass { -// model("lazyResolve") -// } + + testClass { + model("lazyResolve") + } testClass { model("fileStructure") diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/build.gradle.kts b/idea/idea-frontend-fir/idea-fir-low-level-api/build.gradle.kts index e801cf8ca95..dca8f14e100 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/build.gradle.kts +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/build.gradle.kts @@ -32,6 +32,26 @@ dependencies { testCompile(project(":kotlin-test:kotlin-test-junit")) testApiJUnit5() testCompile(project(":kotlin-reflect")) + + testRuntimeOnly(intellijDep()) { + includeJars( + "jps-model", + "extensions", + "util", + "platform-api", + "platform-impl", + "idea", + "guava", + "trove4j", + "asm-all", + "log4j", + "jdom", + "streamex", + "bootstrap", + "jna", + rootProject = rootProject + ) + } } sourceSets { diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/delegates.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/delegates.txt index bf4f841124f..ce76db26272 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/delegates.txt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/delegates.txt @@ -1,3 +1,4 @@ + RAW_FIR: FILE: delegates.kt public? final? [RAW_FIR] fun resolveMe(): R|kotlin/Unit| { @@ -632,28 +633,28 @@ FILE: delegates.kt } public final [STATUS] [ResolvePhaseWithForAllDeclarationsKey=STATUS] fun receive([STATUS] value: R|kotlin/Int|): R|kotlin/Unit| { } - public final [BODY_RESOLVE] [ResolvePhaseWithForAllDeclarationsKey=STATUS] val delegate: > = object : > { + public final [BODY_RESOLVE] [ResolvePhaseWithForAllDeclarationsKey=STATUS] val delegate: R|kotlin/properties/ReadWriteProperty| = object : R|kotlin/properties/ReadWriteProperty| { private [BODY_RESOLVE] [ContainingClassKey=] constructor(): R|| { super() } - public final override [BODY_RESOLVE] fun getValue([BODY_RESOLVE] thisRef: R|kotlin/Any?|, [BODY_RESOLVE] property: R|kotlin/reflect/KProperty<*>|): R|kotlin/Int| { + public final override operator [BODY_RESOLVE] fun getValue([BODY_RESOLVE] thisRef: R|kotlin/Any?|, [BODY_RESOLVE] property: R|kotlin/reflect/KProperty<*>|): R|kotlin/Int| { ^getValue Int(1) } - public final override [BODY_RESOLVE] fun setValue([BODY_RESOLVE] thisRef: R|kotlin/Any?|, [BODY_RESOLVE] property: R|kotlin/reflect/KProperty<*>|, [BODY_RESOLVE] value: R|kotlin/Int|): R|kotlin/Unit| { + public final override operator [BODY_RESOLVE] fun setValue([BODY_RESOLVE] thisRef: R|kotlin/Any?|, [BODY_RESOLVE] property: R|kotlin/reflect/KProperty<*>|, [BODY_RESOLVE] value: R|kotlin/Int|): R|kotlin/Unit| { } } - [BODY_RESOLVE] public get(): > + [BODY_RESOLVE] public get(): R|kotlin/properties/ReadWriteProperty| public final [STATUS] [ResolvePhaseWithForAllDeclarationsKey=STATUS] val valueWithExplicitType: R|kotlin/Int|by delegate# [STATUS] public get(): { ^ D|/valueWithExplicitType|.getValue#(Null(null), ::R|/valueWithExplicitType|) } - public final [BODY_RESOLVE] [ResolvePhaseWithForAllDeclarationsKey=STATUS] val valueWithImplicitType: by R|/delegate| - [BODY_RESOLVE] public get(): { - ^ D|/valueWithImplicitType|.#(Null(null), ::R|/valueWithImplicitType|) + public final [BODY_RESOLVE] [ResolvePhaseWithForAllDeclarationsKey=STATUS] val valueWithImplicitType: R|kotlin/Int|by R|/delegate| + [BODY_RESOLVE] public get(): R|kotlin/Int| { + ^ D|/valueWithImplicitType|.R|SubstitutionOverride|(Null(null), ::R|/valueWithImplicitType|) } public final [STATUS] [ResolvePhaseWithForAllDeclarationsKey=STATUS] var variableWithExplicitType: R|kotlin/Int|by delegate# [STATUS] public get(): { @@ -902,10 +903,10 @@ FILE: delegates.kt [BODY_RESOLVE] public set([BODY_RESOLVE] : R|kotlin/Int|): R|kotlin/Unit| { D|/variableWithExplicitType|.R|SubstitutionOverride|(Null(null), ::R|/variableWithExplicitType|, R|/variableWithExplicitType|) } - public final [BODY_RESOLVE] [ResolvePhaseWithForAllDeclarationsKey=BODY_RESOLVE] var variableWithImplicitType: by R|/delegate| - [BODY_RESOLVE] public get(): { - ^ D|/variableWithImplicitType|.#(Null(null), ::R|/variableWithImplicitType|) + public final [BODY_RESOLVE] [ResolvePhaseWithForAllDeclarationsKey=BODY_RESOLVE] var variableWithImplicitType: R|kotlin/Int|by R|/delegate| + [BODY_RESOLVE] public get(): R|kotlin/Int| { + ^ D|/variableWithImplicitType|.R|SubstitutionOverride|(Null(null), ::R|/variableWithImplicitType|) } - [BODY_RESOLVE] public set([BODY_RESOLVE] : ): R|kotlin/Unit| { - D|/variableWithImplicitType|.#(Null(null), ::R|/variableWithImplicitType|, R|/variableWithImplicitType|) + [BODY_RESOLVE] public set([BODY_RESOLVE] : R|kotlin/Int|): R|kotlin/Unit| { + D|/variableWithImplicitType|.R|SubstitutionOverride|(Null(null), ::R|/variableWithImplicitType|, R|/variableWithImplicitType|) } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirLazyDeclarationResolveTest.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirLazyDeclarationResolveTest.kt index bb610f9e615..81ed145c1b9 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirLazyDeclarationResolveTest.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirLazyDeclarationResolveTest.kt @@ -1,112 +1,110 @@ -///* -// * 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.fir.low.level.api -// -//import com.intellij.openapi.util.io.FileUtil -//import com.intellij.testFramework.LightProjectDescriptor -//import org.jetbrains.kotlin.fir.* -//import org.jetbrains.kotlin.fir.declarations.* -//import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid -//import org.jetbrains.kotlin.idea.caches.project.ModuleSourceInfo -//import org.jetbrains.kotlin.idea.caches.project.getModuleInfo -//import org.jetbrains.kotlin.idea.fir.low.level.api.api.withFirDeclaration -//import org.jetbrains.kotlin.idea.fir.low.level.api.lazy.resolve.FirLazyDeclarationResolver -//import org.jetbrains.kotlin.idea.fir.low.level.api.lazy.resolve.ResolveType -//import org.jetbrains.kotlin.idea.fir.low.level.api.lazy.resolve.declarationCanBeLazilyResolved -//import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -//import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -//import org.jetbrains.kotlin.psi.KtCallableDeclaration -//import org.jetbrains.kotlin.psi.KtClassOrObject -//import org.jetbrains.kotlin.psi.KtDeclaration -//import org.jetbrains.kotlin.psi.KtFile -//import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType -//import org.jetbrains.kotlin.test.KotlinTestUtils -//import java.io.File -// -///** -// * Test that we do not resolve declarations we do not need & do not build bodies for them -// */ -//abstract class AbstractFirLazyDeclarationResolveTest : KotlinLightCodeInsightFixtureTestCase() { -// override fun isFirPlugin(): Boolean = true -// -// private fun FirFile.findResolveMe(): FirDeclaration { -// val visitor = object : FirVisitorVoid() { -// var result: FirDeclaration? = null -// override fun visitElement(element: FirElement) { -// if (result != null) return -// val declaration = element.realPsi as? KtDeclaration -// if (element is FirDeclaration && declaration != null && declaration.name == "resolveMe") { -// result = element -// return -// } -// element.acceptChildren(this) -// } -// -// } -// accept(visitor) -// return visitor.result ?: error("declaration with name `resolveMe` was not found") -// } -// -// -// fun doTest(path: String) { -// val testDataFile = File(path) -// val ktFile = myFixture.configureByText(testDataFile.name, FileUtil.loadFile(testDataFile)) as KtFile -// val rendererOption = FirRenderer.RenderMode.WithDeclarationAttributes.copy(renderDeclarationResolvePhase = true) -// val resultBuilder = StringBuilder() -// resolveWithClearCaches(ktFile) { firModuleResolveState -> -// check(firModuleResolveState is FirModuleResolveStateImpl) -// val declarationToResolve = firModuleResolveState -// .getOrBuildFirFile(ktFile) -// .findResolveMe() -// for (currentPhase in FirResolvePhase.values()) { -// if (currentPhase.pluginPhase || currentPhase == FirResolvePhase.SEALED_CLASS_INHERITORS) continue -// declarationToResolve.withFirDeclaration(firModuleResolveState, currentPhase) { -// val firFile = firModuleResolveState.getOrBuildFirFile(ktFile) -// resultBuilder.append("\n${currentPhase.name}:\n") -// resultBuilder.append(firFile.render(rendererOption)) -// } -// } -// } -// -// for (resolveType in ResolveType.values()) { -// resolveWithClearCaches(ktFile) { firModuleResolveState -> -// check(firModuleResolveState is FirModuleResolveStateImpl) -// val declarationToResolve = firModuleResolveState -// .getOrBuildFirFile(ktFile) -// .findResolveMe() -// -// when (resolveType) { -// ResolveType.CallableReturnType, -// ResolveType.CallableBodyResolve, -// ResolveType.CallableContracts -> if (declarationToResolve !is FirCallableDeclaration<*>) return@resolveWithClearCaches -// ResolveType.ClassSuperTypes -> if (declarationToResolve !is FirClassLikeDeclaration<*>) return@resolveWithClearCaches -// else -> { -// } -// } -// -// declarationToResolve.withFirDeclaration(resolveType, firModuleResolveState) { -// val firFile = firModuleResolveState.getOrBuildFirFile(ktFile) -// resultBuilder.append("\n${resolveType.name}:\n") -// resultBuilder.append(firFile.render(rendererOption)) -// } -// } -// } -// -// resolveWithClearCaches(ktFile) { firModuleResolveState -> -// check(firModuleResolveState is FirModuleResolveStateImpl) -// val firFile = firModuleResolveState.getOrBuildFirFile(ktFile) -// firFile.withFirDeclaration(firModuleResolveState, FirResolvePhase.BODY_RESOLVE) { -// resultBuilder.append("\nFILE RAW TO BODY:\n") -// resultBuilder.append(firFile.render(rendererOption)) -// } -// } -// -// val expectedFileName = testDataFile.name.replace(".kt", ".txt") -// KotlinTestUtils.assertEqualsToFile(testDataFile.parentFile.resolve(expectedFileName), resultBuilder.toString()) -// } -// -// override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE -//} \ No newline at end of file +/* + * 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.fir.low.level.api + +import org.jetbrains.kotlin.fir.* +import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid +import org.jetbrains.kotlin.idea.fir.low.level.api.api.withFirDeclaration +import org.jetbrains.kotlin.idea.fir.low.level.api.lazy.resolve.ResolveType +import org.jetbrains.kotlin.idea.fir.low.level.api.test.base.AbstractLowLevelApiSingleFileTest +import org.jetbrains.kotlin.psi.KtDeclaration +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives +import org.jetbrains.kotlin.test.services.TestModuleStructure +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.assertions +import org.junit.jupiter.api.parallel.Execution +import org.junit.jupiter.api.parallel.ExecutionMode + +/** + * Test that we do not resolve declarations we do not need & do not build bodies for them + */ +@Execution(ExecutionMode.SAME_THREAD) +abstract class AbstractFirLazyDeclarationResolveTest : AbstractLowLevelApiSingleFileTest() { + + private fun FirFile.findResolveMe(): FirDeclaration { + val visitor = object : FirVisitorVoid() { + var result: FirDeclaration? = null + override fun visitElement(element: FirElement) { + if (result != null) return + val declaration = element.realPsi as? KtDeclaration + if (element is FirDeclaration && declaration != null && declaration.name == "resolveMe") { + result = element + return + } + element.acceptChildren(this) + } + + } + accept(visitor) + return visitor.result ?: error("declaration with name `resolveMe` was not found") + } + + override fun doTestByFileStructure(ktFile: KtFile, moduleStructure: TestModuleStructure, testServices: TestServices) { + val rendererOption = FirRenderer.RenderMode.WithDeclarationAttributes.copy(renderDeclarationResolvePhase = true) + val resultBuilder = StringBuilder() + resolveWithClearCaches(ktFile) { firModuleResolveState -> + check(firModuleResolveState is FirModuleResolveStateImpl) + val declarationToResolve = firModuleResolveState + .getOrBuildFirFile(ktFile) + .findResolveMe() + for (currentPhase in FirResolvePhase.values()) { + if (currentPhase.pluginPhase || currentPhase == FirResolvePhase.SEALED_CLASS_INHERITORS) continue + declarationToResolve.withFirDeclaration(firModuleResolveState, currentPhase) { + val firFile = firModuleResolveState.getOrBuildFirFile(ktFile) + resultBuilder.append("\n${currentPhase.name}:\n") + resultBuilder.append(firFile.render(rendererOption)) + } + } + } + + for (resolveType in ResolveType.values()) { + resolveWithClearCaches(ktFile) { firModuleResolveState -> + check(firModuleResolveState is FirModuleResolveStateImpl) + val declarationToResolve = firModuleResolveState + .getOrBuildFirFile(ktFile) + .findResolveMe() + + when (resolveType) { + ResolveType.CallableReturnType, + ResolveType.CallableBodyResolve, + ResolveType.CallableContracts -> if (declarationToResolve !is FirCallableDeclaration<*>) return@resolveWithClearCaches + ResolveType.ClassSuperTypes -> if (declarationToResolve !is FirClassLikeDeclaration<*>) return@resolveWithClearCaches + else -> { + } + } + + declarationToResolve.withFirDeclaration(resolveType, firModuleResolveState) { + val firFile = firModuleResolveState.getOrBuildFirFile(ktFile) + resultBuilder.append("\n${resolveType.name}:\n") + resultBuilder.append(firFile.render(rendererOption)) + } + } + } + + resolveWithClearCaches(ktFile) { firModuleResolveState -> + check(firModuleResolveState is FirModuleResolveStateImpl) + val firFile = firModuleResolveState.getOrBuildFirFile(ktFile) + firFile.withFirDeclaration(firModuleResolveState, FirResolvePhase.BODY_RESOLVE) { + resultBuilder.append("\nFILE RAW TO BODY:\n") + resultBuilder.append(firFile.render(rendererOption)) + } + } + + testServices.assertions.assertEqualsToFile(testDataFileSibling(".txt"), resultBuilder.toString()) + } + + override fun configureTest(builder: TestConfigurationBuilder) { + super.configureTest(builder) + with(builder) { + defaultDirectives { + +JvmEnvironmentConfigurationDirectives.WITH_STDLIB + } + } + } +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/FirLazyDeclarationResolveTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/FirLazyDeclarationResolveTestGenerated.java index f55e9ff0974..323ae6b5cb0 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/FirLazyDeclarationResolveTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/FirLazyDeclarationResolveTestGenerated.java @@ -1,80 +1,146 @@ -///* -// * 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.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("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve") -//@TestDataPath("$PROJECT_ROOT") -//public class FirLazyDeclarationResolveTestGenerated extends AbstractFirLazyDeclarationResolveTest { -// @Test -// public void testAllFilesPresentInLazyResolve() throws Exception { -// KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve"), Pattern.compile("^(.+)\\.kt$"), null, true); -// } -// -// @Test -// @TestMetadata("classMembers.kt") -// public void testClassMembers() throws Exception { -// runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/classMembers.kt"); -// } -// -// @Test -// @TestMetadata("delegates.kt") -// public void testDelegates() throws Exception { -// runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/delegates.kt"); -// } -// -// @Test -// @TestMetadata("propertyWithGetter.kt") -// public void testPropertyWithGetter() throws Exception { -// runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/propertyWithGetter.kt"); -// } -// -// @Test -// @TestMetadata("propertyWithGetterAndSetter.kt") -// public void testPropertyWithGetterAndSetter() throws Exception { -// runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/propertyWithGetterAndSetter.kt"); -// } -// -// @Test -// @TestMetadata("propertyWithInitializer.kt") -// public void testPropertyWithInitializer() throws Exception { -// runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/propertyWithInitializer.kt"); -// } -// -// @Test -// @TestMetadata("secondaryConstructor.kt") -// public void testSecondaryConstructor() throws Exception { -// runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/secondaryConstructor.kt"); -// } -// -// @Test -// @TestMetadata("topLevelFunctions.kt") -// public void testTopLevelFunctions() throws Exception { -// runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/topLevelFunctions.kt"); -// } -// -// @Test -// @TestMetadata("topLevelFunctionsWithExpressionBodyAndExplicitType.kt") -// public void testTopLevelFunctionsWithExpressionBodyAndExplicitType() throws Exception { -// runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/topLevelFunctionsWithExpressionBodyAndExplicitType.kt"); -// } -// -// @Test -// @TestMetadata("topLevelFunctionsWithImplicitType.kt") -// public void testTopLevelFunctionsWithImplicitType() throws Exception { -// runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/topLevelFunctionsWithImplicitType.kt"); -// } -//} +/* + * 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.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("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve") +@TestDataPath("$PROJECT_ROOT") +public class FirLazyDeclarationResolveTestGenerated extends AbstractFirLazyDeclarationResolveTest { + @Test + public void testAllFilesPresentInLazyResolve() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("annotations.kt") + public void testAnnotations() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/annotations.kt"); + } + + @Test + @TestMetadata("classMembers.kt") + public void testClassMembers() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/classMembers.kt"); + } + + @Test + @TestMetadata("delegates.kt") + public void testDelegates() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/delegates.kt"); + } + + @Test + @TestMetadata("localDeclaration.kt") + public void testLocalDeclaration() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/localDeclaration.kt"); + } + + @Test + @TestMetadata("localFunction.kt") + public void testLocalFunction() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/localFunction.kt"); + } + + @Test + @TestMetadata("parameterOfLocalSetter.kt") + public void testParameterOfLocalSetter() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/parameterOfLocalSetter.kt"); + } + + @Test + @TestMetadata("parameterOfNonLocalSetter.kt") + public void testParameterOfNonLocalSetter() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/parameterOfNonLocalSetter.kt"); + } + + @Test + @TestMetadata("propertyWithGetter.kt") + public void testPropertyWithGetter() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/propertyWithGetter.kt"); + } + + @Test + @TestMetadata("propertyWithGetterAndSetter.kt") + public void testPropertyWithGetterAndSetter() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/propertyWithGetterAndSetter.kt"); + } + + @Test + @TestMetadata("propertyWithInitializer.kt") + public void testPropertyWithInitializer() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/propertyWithInitializer.kt"); + } + + @Test + @TestMetadata("secondaryConstructor.kt") + public void testSecondaryConstructor() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/secondaryConstructor.kt"); + } + + @Test + @TestMetadata("superTypes.kt") + public void testSuperTypes() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/superTypes.kt"); + } + + @Test + @TestMetadata("superTypesLoop.kt") + public void testSuperTypesLoop() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/superTypesLoop.kt"); + } + + @Test + @TestMetadata("topLevelFunctions.kt") + public void testTopLevelFunctions() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/topLevelFunctions.kt"); + } + + @Test + @TestMetadata("topLevelFunctionsWithExpressionBodyAndExplicitType.kt") + public void testTopLevelFunctionsWithExpressionBodyAndExplicitType() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/topLevelFunctionsWithExpressionBodyAndExplicitType.kt"); + } + + @Test + @TestMetadata("topLevelFunctionsWithImplicitType.kt") + public void testTopLevelFunctionsWithImplicitType() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/topLevelFunctionsWithImplicitType.kt"); + } + + @Test + @TestMetadata("typeParameterOfLocalFunction.kt") + public void testTypeParameterOfLocalFunction() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/typeParameterOfLocalFunction.kt"); + } + + @Test + @TestMetadata("typeParameterOfNonLocalFunction.kt") + public void testTypeParameterOfNonLocalFunction() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/typeParameterOfNonLocalFunction.kt"); + } + + @Test + @TestMetadata("typeParameterOfTopFunction.kt") + public void testTypeParameterOfTopFunction() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/typeParameterOfTopFunction.kt"); + } + + @Test + @TestMetadata("typeParameterOfTopSetter.kt") + public void testTypeParameterOfTopSetter() throws Exception { + runTest("idea/idea-frontend-fir/idea-fir-low-level-api/testdata/lazyResolve/typeParameterOfTopSetter.kt"); + } +} diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/compiler/based/AbstractCompilerBasedTest.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/compiler/based/AbstractCompilerBasedTest.kt index adcdf6b316a..aefc67919f1 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/compiler/based/AbstractCompilerBasedTest.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/compiler/based/AbstractCompilerBasedTest.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.idea.fir.low.level.api.compiler.based import com.intellij.mock.MockProject +import com.intellij.openapi.Disposable import com.intellij.psi.PsiElementFinder import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.ProjectScope @@ -89,7 +90,7 @@ abstract class AbstractCompilerBasedTest : AbstractKotlinCompilerTest() { val moduleInfo = TestModuleInfo(module) testServices.firModuleInfoProvider.registerModuleData(module, FirModuleInfoBasedModuleData(moduleInfo)) - val configurator = FirModuleResolveStateConfiguratorForSingleModuleTestImpl(testServices, module, ktFiles, moduleInfo) + val configurator = FirModuleResolveStateConfiguratorForSingleModuleTestImpl(testServices, module, ktFiles, moduleInfo, project) with(project as MockProject) { registerTestServices(configurator, ktFiles) @@ -162,6 +163,7 @@ class FirModuleResolveStateConfiguratorForSingleModuleTestImpl( private val testModule: TestModule, private val ktFiles: Map, private val moduleInfo: ModuleInfo, + private val parentDisposable: Disposable, ) : FirModuleResolveStateConfigurator() { val moduleInfoProvider = testServices.firModuleInfoProvider val compilerConfigurationProvider = testServices.compilerConfigurationProvider @@ -220,8 +222,7 @@ class FirModuleResolveStateConfiguratorForSingleModuleTestImpl( } override fun configureSourceSession(session: FirSession) { - @Suppress("IncorrectParentDisposable") - PsiElementFinder.EP.getPoint(project).registerExtension(FirJavaElementFinder(session, project), project) + PsiElementFinder.EP.getPoint(project).registerExtension(FirJavaElementFinder(session, project), parentDisposable) } } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/test/base/AbstractLowLevelApiTest.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/test/base/AbstractLowLevelApiTest.kt index 48891aa92a5..adb50983230 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/test/base/AbstractLowLevelApiTest.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/test/base/AbstractLowLevelApiTest.kt @@ -6,6 +6,8 @@ package org.jetbrains.kotlin.idea.fir.low.level.api.test.base import com.intellij.mock.MockProject +import com.intellij.openapi.Disposable +import com.intellij.openapi.util.Disposer import com.intellij.psi.PsiElementFinder import org.jetbrains.kotlin.asJava.finder.JavaElementFinder import org.jetbrains.kotlin.fir.session.FirModuleInfoBasedModuleData @@ -24,6 +26,7 @@ import org.jetbrains.kotlin.test.services.* import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator import org.jetbrains.kotlin.test.services.impl.TemporaryDirectoryManagerImpl +import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.TestInfo import java.nio.file.Path @@ -33,6 +36,20 @@ import kotlin.io.path.nameWithoutExtension abstract class AbstractLowLevelApiTest { private lateinit var testInfo: KotlinTestInfo + private var _disposable: Disposable? = null + protected val disposable: Disposable get() = _disposable!! + + @BeforeEach + private fun intiDisposable(testInfo: TestInfo) { + _disposable = Disposer.newDisposable("disposable for ${testInfo.displayName}") + } + + @AfterEach + private fun disposeDisposable() { + _disposable?.let { Disposer.dispose(it) } + _disposable = null + } + private val configure: TestConfigurationBuilder.() -> Unit = { globalDefaults { frontend = FrontendKinds.FIR @@ -84,7 +101,13 @@ abstract class AbstractLowLevelApiTest { val moduleInfo = TestModuleInfo(singleModule) testServices.firModuleInfoProvider.registerModuleData(singleModule, FirModuleInfoBasedModuleData(moduleInfo)) - val configurator = FirModuleResolveStateConfiguratorForSingleModuleTestImpl(testServices, singleModule, ktFiles, moduleInfo) + val configurator = FirModuleResolveStateConfiguratorForSingleModuleTestImpl( + testServices, + singleModule, + ktFiles, + moduleInfo, + disposable + ) with(project as MockProject) { registerTestServices(configurator, ktFiles)