diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/analysis/FirAnalyzerFacade.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/analysis/FirAnalyzerFacade.kt index fd672918e64..7e57fe53482 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/analysis/FirAnalyzerFacade.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/analysis/FirAnalyzerFacade.kt @@ -45,7 +45,8 @@ class FirAnalyzerFacade( val languageVersionSettings: LanguageVersionSettings, val ktFiles: Collection = emptyList(), // may be empty if light tree mode enabled val originalFiles: Collection = emptyList(), // may be empty if light tree mode disabled - val useLightTree: Boolean = false + val useLightTree: Boolean = false, + val enablePluginPhases: Boolean = false, ) : AbstractFirAnalyzerFacade() { private var firFiles: List? = null private var _scopeSession: ScopeSession? = null @@ -77,7 +78,7 @@ class FirAnalyzerFacade( override fun runResolution(): List { if (firFiles == null) buildRawFir() if (_scopeSession != null) return firFiles!! - val resolveProcessor = FirTotalResolveProcessor(session) + val resolveProcessor = FirTotalResolveProcessor(session, enablePluginPhases) resolveProcessor.process(firFiles!!) _scopeSession = resolveProcessor.scopeSession return firFiles!! diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveProcessor.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveProcessor.kt index 286acb3ad28..14f0692cac9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveProcessor.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirTotalResolveProcessor.kt @@ -15,10 +15,10 @@ import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirImplicitTyp import org.jetbrains.kotlin.fir.resolve.transformers.contracts.FirContractResolveProcessor import org.jetbrains.kotlin.fir.resolve.transformers.plugin.* -class FirTotalResolveProcessor(session: FirSession) { +class FirTotalResolveProcessor(session: FirSession, enablePluginPhases: Boolean = false) { val scopeSession: ScopeSession = ScopeSession() - private val processors: List = createAllCompilerResolveProcessors(session, scopeSession) + private val processors: List = createAllCompilerResolveProcessors(session, scopeSession, enablePluginPhases) fun process(files: List) { for (processor in processors) { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/FirDiagnosticsDirectives.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/FirDiagnosticsDirectives.kt index d061b982ed0..88f77ff503f 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/FirDiagnosticsDirectives.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/FirDiagnosticsDirectives.kt @@ -57,4 +57,8 @@ object FirDiagnosticsDirectives : SimpleDirectivesContainer() { Enables ${FirScopeDumpHandler::class} """.trimIndent() ) + + val ENABLE_PLUGIN_PHASES by directive( + description = "Enable plugin phases" + ) } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/FirFrontendFacade.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/FirFrontendFacade.kt index 98d2d7b98c2..936c9061363 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/FirFrontendFacade.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/fir/FirFrontendFacade.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots import org.jetbrains.kotlin.cli.jvm.config.jvmModularRoots import org.jetbrains.kotlin.config.JVMConfigurationKeys +import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.analysis.FirAnalyzerFacade import org.jetbrains.kotlin.fir.checkers.registerExtendedCommonCheckers import org.jetbrains.kotlin.fir.moduleData @@ -38,8 +39,14 @@ import org.jetbrains.kotlin.test.model.* import org.jetbrains.kotlin.test.services.* class FirFrontendFacade( - testServices: TestServices + testServices: TestServices, + private val additionalSessionConfiguration: SessionConfiguration? ) : FrontendFacade(testServices, FrontendKinds.FIR) { + // Separate constructor is needed for creating callable references to it + constructor(testServices: TestServices) : this(testServices, additionalSessionConfiguration = null) + + fun interface SessionConfiguration : (FirSessionFactory.FirSessionConfigurator) -> Unit + override val additionalServices: List get() = listOf(service(::FirModuleInfoProvider)) @@ -98,11 +105,20 @@ class FirFrontendFacade( if (FirDiagnosticsDirectives.WITH_EXTENDED_CHECKERS in module.directives) { registerExtendedCommonCheckers() } + additionalSessionConfiguration?.invoke(this) } moduleInfoProvider.registerModuleData(module, session.moduleData) - val firAnalyzerFacade = FirAnalyzerFacade(session, languageVersionSettings, ktFiles, originalFiles, lightTreeEnabled) + val enablePluginPhases = FirDiagnosticsDirectives.ENABLE_PLUGIN_PHASES in module.directives + val firAnalyzerFacade = FirAnalyzerFacade( + session, + languageVersionSettings, + ktFiles, + originalFiles, + lightTreeEnabled, + enablePluginPhases + ) val firFiles = firAnalyzerFacade.runResolution() val filesMap = firFiles.mapNotNull { firFile -> val testFile = module.files.firstOrNull { it.name == firFile.name } ?: return@mapNotNull null diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 9f48167c2f6..ac70f94343c 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -369,7 +369,7 @@ fun main(args: Array) { } } - testGroup("plugins/fir/fir-plugin-prototype/tests", "plugins/fir/fir-plugin-prototype/testData") { + testGroup("plugins/fir/fir-plugin-prototype/tests-gen", "plugins/fir/fir-plugin-prototype/testData") { testClass { model("") } diff --git a/plugins/fir/fir-plugin-prototype/build.gradle.kts b/plugins/fir/fir-plugin-prototype/build.gradle.kts index 6dadc83052e..c9a8dce3554 100644 --- a/plugins/fir/fir-plugin-prototype/build.gradle.kts +++ b/plugins/fir/fir-plugin-prototype/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.ideaExt.idea + plugins { kotlin("jvm") id("jps-compatible") @@ -8,36 +10,54 @@ dependencies { api(project(":compiler:fir:tree")) api(project(":compiler:fir:resolve")) api(project(":compiler:fir:checkers")) - api(project(":compiler:frontend")) + api(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(project(":kotlin-reflect-api")) - compileOnly(intellijCoreDep()) { includeJars("intellij-core", "guava", rootProject = rootProject) } - testApi(intellijDep()) - - testApi(commonDep("junit:junit")) - testCompileOnly(project(":kotlin-test:kotlin-test-jvm")) - testCompileOnly(project(":kotlin-test:kotlin-test-junit")) - testApi(projectTests(":compiler:tests-common")) + testApiJUnit5() + testApi(projectTests(":compiler:tests-common-new")) + testApi(projectTests(":compiler:test-infrastructure")) + testApi(projectTests(":compiler:test-infrastructure-utils")) testApi(project(":compiler:fir:checkers")) testApi(project(":compiler:fir:checkers:checkers.jvm")) - testApi(projectTests(":compiler:fir:analysis-tests:legacy-fir-tests")) testApi(project(":compiler:frontend")) testCompileOnly(project(":kotlin-reflect-api")) testRuntimeOnly(project(":kotlin-reflect")) testRuntimeOnly(project(":core:descriptors.runtime")) - testCompileOnly(intellijCoreDep()) { includeJars("intellij-core") } - testRuntimeOnly(intellijCoreDep()) { includeJars("intellij-core") } + testRuntimeOnly(intellijDep()) { + includeJars("jna", rootProject = rootProject) + } + + testRuntimeOnly(intellijDep()) { includeJars( + "intellij-deps-fastutil-8.4.1-4", + "trove4j", + "jdom" + ) } + testRuntimeOnly(toolsJar()) } +val generationRoot = projectDir.resolve("tests-gen") + sourceSets { - "main" { projectDefault() } - "test" { projectDefault() } + "main" { + projectDefault() + } + "test" { + projectDefault() + this.java.srcDir(generationRoot.name) + } } -projectTest(parallel = true) { +if (kotlinBuildProperties.isInJpsBuildIdeaSync) { + apply(plugin = "idea") + idea { + this.module.generatedSourceDirs.add(generationRoot) + } +} + +projectTest(parallel = true, jUnit5Enabled = true) { workingDir = rootDir jvmArgs!!.removeIf { it.contains("-Xmx") } maxHeapSize = "3g" diff --git a/plugins/fir/fir-plugin-prototype/plugin-annotations/build.gradle.kts b/plugins/fir/fir-plugin-prototype/plugin-annotations/build.gradle.kts index c57df359a1e..96ed8e746b3 100644 --- a/plugins/fir/fir-plugin-prototype/plugin-annotations/build.gradle.kts +++ b/plugins/fir/fir-plugin-prototype/plugin-annotations/build.gradle.kts @@ -3,6 +3,9 @@ plugins { id("jps-compatible") } +dependencies { + api(kotlinStdlib()) +} sourceSets { "main" { projectDefault() } diff --git a/plugins/fir/fir-plugin-prototype/testData/checkers/simple.txt b/plugins/fir/fir-plugin-prototype/testData/checkers/simple.fir.txt similarity index 100% rename from plugins/fir/fir-plugin-prototype/testData/checkers/simple.txt rename to plugins/fir/fir-plugin-prototype/testData/checkers/simple.fir.txt diff --git a/plugins/fir/fir-plugin-prototype/testData/memberGen/functionForProperty.txt b/plugins/fir/fir-plugin-prototype/testData/memberGen/functionForProperty.fir.txt similarity index 94% rename from plugins/fir/fir-plugin-prototype/testData/memberGen/functionForProperty.txt rename to plugins/fir/fir-plugin-prototype/testData/memberGen/functionForProperty.fir.txt index 7dd2283511e..399bfa14970 100644 --- a/plugins/fir/fir-plugin-prototype/testData/memberGen/functionForProperty.txt +++ b/plugins/fir/fir-plugin-prototype/testData/memberGen/functionForProperty.fir.txt @@ -20,7 +20,7 @@ FILE: functionForProperty.kt } public final fun test_1(a: R|A|): R|kotlin/Unit| { - R|/a|.R|/A.helloX|() + R|/a|.#() } public final fun test_2(b: R|B|): R|kotlin/Unit| { R|/b|.#() diff --git a/plugins/fir/fir-plugin-prototype/testData/memberGen/nestedClass.fir.txt b/plugins/fir/fir-plugin-prototype/testData/memberGen/nestedClass.fir.txt new file mode 100644 index 00000000000..4f0d74d48b3 --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/memberGen/nestedClass.fir.txt @@ -0,0 +1,37 @@ +FILE: nestedClass.kt + public final fun R|T|.also(block: R|(T) -> kotlin/Unit|): R|T| { + ^also this@R|/also| + } + @R|org/jetbrains/kotlin/fir/plugin/WithNestedFoo|() public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + private final fun test(): R|A.Foo| { + ^test #().#( = also@fun (it: R|A.Foo|): R|kotlin/Unit| { + R|/it|.#() + } + ) + } + + private final inner class Foo { + public constructor(): R|A.Foo| + + public final fun hello(): R|kotlin/Int| + + } + + } + public final class B : R|kotlin/Any| { + public constructor(): R|B| { + super() + } + + private final fun test(): { + ^test #().#( = also@fun (it: ): R|kotlin/Unit| { + R|/it|.#() + } + ) + } + + } diff --git a/plugins/fir/fir-plugin-prototype/testData/memberGen/nestedClass.txt b/plugins/fir/fir-plugin-prototype/testData/memberGen/nestedClass.txt deleted file mode 100644 index 1833bb70ef3..00000000000 --- a/plugins/fir/fir-plugin-prototype/testData/memberGen/nestedClass.txt +++ /dev/null @@ -1,37 +0,0 @@ -FILE: nestedClass.kt - public final fun R|T|.also(block: R|(T) -> kotlin/Unit|): R|T| { - ^also this@R|/also| - } - @R|org/jetbrains/kotlin/fir/plugin/WithNestedFoo|() public final class A : R|kotlin/Any| { - public constructor(): R|A| { - super() - } - - private final fun test(): R|A.Foo| { - ^test R|/A.Foo.Foo|().R|/also|( = also@fun (it: R|A.Foo|): R|kotlin/Unit| { - ^ R|/it|.R|/A.Foo.hello|() - } - ) - } - - private final inner class Foo { - public constructor(): R|A.Foo| - - public final fun hello(): R|kotlin/Int| - - } - - } - public final class B : R|kotlin/Any| { - public constructor(): R|B| { - super() - } - - private final fun test(): R|ERROR CLASS: Symbol not found, for `Foo`| { - ^test #().#( = also@fun (): R|ERROR CLASS: Unresolved name: hello| { - ^ #.#() - } - ) - } - - } diff --git a/plugins/fir/fir-plugin-prototype/testData/memberGen/recursiveNestedClasses.txt b/plugins/fir/fir-plugin-prototype/testData/memberGen/recursiveNestedClasses.fir.txt similarity index 82% rename from plugins/fir/fir-plugin-prototype/testData/memberGen/recursiveNestedClasses.txt rename to plugins/fir/fir-plugin-prototype/testData/memberGen/recursiveNestedClasses.fir.txt index b5463b91192..1de70fed12e 100644 --- a/plugins/fir/fir-plugin-prototype/testData/memberGen/recursiveNestedClasses.txt +++ b/plugins/fir/fir-plugin-prototype/testData/memberGen/recursiveNestedClasses.fir.txt @@ -15,5 +15,5 @@ FILE: recursiveNestedClasses.kt } public final fun test_2(x: R|SomeClass.Nested.Nested|): R|kotlin/Unit| { } - public final fun test_3(x: R|ERROR CLASS: Symbol not found, for `SomeClass.Nested.Nested.Nested`|): R|kotlin/Unit| { + public final fun test_3(x: ): R|kotlin/Unit| { } diff --git a/plugins/fir/fir-plugin-prototype/testData/memberGen/topLevelClass.txt b/plugins/fir/fir-plugin-prototype/testData/memberGen/topLevelClass.fir.txt similarity index 85% rename from plugins/fir/fir-plugin-prototype/testData/memberGen/topLevelClass.txt rename to plugins/fir/fir-plugin-prototype/testData/memberGen/topLevelClass.fir.txt index 93dfee64622..b8fbb4b9fdf 100644 --- a/plugins/fir/fir-plugin-prototype/testData/memberGen/topLevelClass.txt +++ b/plugins/fir/fir-plugin-prototype/testData/memberGen/topLevelClass.fir.txt @@ -6,7 +6,7 @@ FILE: topLevelClass.kt } public final fun test(): R|kotlin/Unit| { - Q|TopLevelSomeClass|.R|/TopLevelSomeClass.hello|() + Q|TopLevelSomeClass|.#() } public final object TopLevelSomeClass { public final fun hello(): R|kotlin/Int| diff --git a/plugins/fir/fir-plugin-prototype/testData/status/metaAnnotation.txt b/plugins/fir/fir-plugin-prototype/testData/status/metaAnnotation.fir.txt similarity index 100% rename from plugins/fir/fir-plugin-prototype/testData/status/metaAnnotation.txt rename to plugins/fir/fir-plugin-prototype/testData/status/metaAnnotation.fir.txt diff --git a/plugins/fir/fir-plugin-prototype/testData/status/simpleAnnotation.txt b/plugins/fir/fir-plugin-prototype/testData/status/simpleAnnotation.fir.txt similarity index 100% rename from plugins/fir/fir-plugin-prototype/testData/status/simpleAnnotation.txt rename to plugins/fir/fir-plugin-prototype/testData/status/simpleAnnotation.fir.txt diff --git a/plugins/fir/fir-plugin-prototype/testData/status/visibilityTransformation.fir.txt b/plugins/fir/fir-plugin-prototype/testData/status/visibilityTransformation.fir.txt new file mode 100644 index 00000000000..c6afa23858a --- /dev/null +++ b/plugins/fir/fir-plugin-prototype/testData/status/visibilityTransformation.fir.txt @@ -0,0 +1,45 @@ +FILE: visibilityTransformation.kt + @R|org/jetbrains/kotlin/fir/plugin/AllPublic|(visibility = Q|org/jetbrains/kotlin/fir/plugin/Visibility|.R|org/jetbrains/kotlin/fir/plugin/Visibility.Protected|) public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final val x: R|kotlin/String| = String() + public get(): R|kotlin/String| + + public final fun foo(): R|kotlin/Unit| { + } + + public final class Nested : R|kotlin/Any| { + public constructor(): R|A.Nested| { + super() + } + + public final fun bar(): R|kotlin/Unit| { + } + + } + + } + @R|org/jetbrains/kotlin/fir/plugin/AllPublic|(visibility = Q|org/jetbrains/kotlin/fir/plugin/Visibility|.R|org/jetbrains/kotlin/fir/plugin/Visibility.Private|) public final class B : R|kotlin/Any| { + public constructor(): R|B| { + super() + } + + public final val x: R|kotlin/String| = String() + public get(): R|kotlin/String| + + public final fun foo(): R|kotlin/Unit| { + } + + public final class Nested : R|kotlin/Any| { + public constructor(): R|B.Nested| { + super() + } + + public final fun bar(): R|kotlin/Unit| { + } + + } + + } diff --git a/plugins/fir/fir-plugin-prototype/testData/status/visibilityTransformation.txt b/plugins/fir/fir-plugin-prototype/testData/status/visibilityTransformation.txt deleted file mode 100644 index 5c60ce86271..00000000000 --- a/plugins/fir/fir-plugin-prototype/testData/status/visibilityTransformation.txt +++ /dev/null @@ -1,45 +0,0 @@ -FILE: visibilityTransformation.kt - @R|org/jetbrains/kotlin/fir/plugin/AllPublic|(Q|org/jetbrains/kotlin/fir/plugin/Visibility|.R|org/jetbrains/kotlin/fir/plugin/Visibility.Protected|) protected final class A : R|kotlin/Any| { - protected constructor(): R|A| { - super() - } - - protected final val x: R|kotlin/String| - public get(): R|kotlin/String| - - protected final fun foo(): R|kotlin/Unit| { - } - - protected final class Nested : R|kotlin/Any| { - protected constructor(): R|A.Nested| { - super() - } - - protected final fun bar(): R|kotlin/Unit| { - } - - } - - } - @R|org/jetbrains/kotlin/fir/plugin/AllPublic|(Q|org/jetbrains/kotlin/fir/plugin/Visibility|.R|org/jetbrains/kotlin/fir/plugin/Visibility.Private|) private final class B : R|kotlin/Any| { - private constructor(): R|B| { - super() - } - - private final val x: R|kotlin/String| - public get(): R|kotlin/String| - - private final fun foo(): R|kotlin/Unit| { - } - - private final class Nested : R|kotlin/Any| { - private constructor(): R|B.Nested| { - super() - } - - private final fun bar(): R|kotlin/Unit| { - } - - } - - } diff --git a/plugins/fir/fir-plugin-prototype/testData/supertypes/simple.txt b/plugins/fir/fir-plugin-prototype/testData/supertypes/simple.fir.txt similarity index 51% rename from plugins/fir/fir-plugin-prototype/testData/supertypes/simple.txt rename to plugins/fir/fir-plugin-prototype/testData/supertypes/simple.fir.txt index abcd7654284..be657e237f7 100644 --- a/plugins/fir/fir-plugin-prototype/testData/supertypes/simple.txt +++ b/plugins/fir/fir-plugin-prototype/testData/supertypes/simple.fir.txt @@ -4,15 +4,15 @@ FILE: simple.kt super() } - public final class MyNested : R|org/jetbrains/kotlin/fir/plugin/LibraryClassWithNestedClass.NestedClass| { + public final class MyNested : { public constructor(): R|A.MyNested| { - super() + super<>() } } public final fun test(): R|kotlin/Unit| { - R|/A.MyNested.MyNested|().R|org/jetbrains/kotlin/fir/plugin/LibraryClassWithNestedClass.NestedClass.foo|() + R|/A.MyNested.MyNested|().#() } } diff --git a/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java b/plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java similarity index 73% rename from plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java rename to plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java index 7edf8d18b7e..074842a6892 100644 --- a/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java +++ b/plugins/fir/fir-plugin-prototype/tests-gen/org/jetbrains/kotlin/fir/plugin/FirAllOpenDiagnosticTestGenerated.java @@ -6,120 +6,112 @@ package org.jetbrains.kotlin.fir.plugin; 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 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 org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("plugins/fir/fir-plugin-prototype/testData") @TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) public class FirAllOpenDiagnosticTestGenerated extends AbstractFirAllOpenDiagnosticTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - + @Test public void testAllFilesPresentInTestData() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @Nested @TestMetadata("plugins/fir/fir-plugin-prototype/testData/checkers") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Checkers extends AbstractFirAllOpenDiagnosticTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - + public class Checkers { + @Test public void testAllFilesPresentInCheckers() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/checkers"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/checkers/simple.kt"); } } + @Nested @TestMetadata("plugins/fir/fir-plugin-prototype/testData/memberGen") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class MemberGen extends AbstractFirAllOpenDiagnosticTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - + public class MemberGen { + @Test public void testAllFilesPresentInMemberGen() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/memberGen"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @Test @TestMetadata("functionForProperty.kt") public void testFunctionForProperty() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/memberGen/functionForProperty.kt"); } + @Test @TestMetadata("nestedClass.kt") public void testNestedClass() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/memberGen/nestedClass.kt"); } + @Test @TestMetadata("recursiveNestedClasses.kt") public void testRecursiveNestedClasses() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/memberGen/recursiveNestedClasses.kt"); } + @Test @TestMetadata("topLevelClass.kt") public void testTopLevelClass() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/memberGen/topLevelClass.kt"); } } + @Nested @TestMetadata("plugins/fir/fir-plugin-prototype/testData/status") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Status extends AbstractFirAllOpenDiagnosticTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - + public class Status { + @Test public void testAllFilesPresentInStatus() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/status"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @Test @TestMetadata("metaAnnotation.kt") public void testMetaAnnotation() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/status/metaAnnotation.kt"); } + @Test @TestMetadata("simpleAnnotation.kt") public void testSimpleAnnotation() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/status/simpleAnnotation.kt"); } + @Test @TestMetadata("visibilityTransformation.kt") public void testVisibilityTransformation() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/status/visibilityTransformation.kt"); } } + @Nested @TestMetadata("plugins/fir/fir-plugin-prototype/testData/supertypes") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Supertypes extends AbstractFirAllOpenDiagnosticTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - + public class Supertypes { + @Test public void testAllFilesPresentInSupertypes() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir/fir-plugin-prototype/testData/supertypes"), Pattern.compile("^(.+)\\.kt$"), null, true); } + @Test @TestMetadata("simple.kt") public void testSimple() throws Exception { runTest("plugins/fir/fir-plugin-prototype/testData/supertypes/simple.kt"); diff --git a/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/AbstractFirAllOpenDiagnosticTest.kt b/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/AbstractFirAllOpenDiagnosticTest.kt index b2a1793f90a..ff896752b5e 100644 --- a/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/AbstractFirAllOpenDiagnosticTest.kt +++ b/plugins/fir/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/AbstractFirAllOpenDiagnosticTest.kt @@ -7,24 +7,47 @@ package org.jetbrains.kotlin.fir.plugin import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot import org.jetbrains.kotlin.config.CompilerConfiguration -import org.jetbrains.kotlin.fir.AbstractFirDiagnosticsTest -import org.jetbrains.kotlin.fir.extensions.BunchOfRegisteredExtensions +import org.jetbrains.kotlin.test.Constructor +import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.ENABLE_PLUGIN_PHASES +import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_DUMP +import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest +import org.jetbrains.kotlin.test.runners.baseFirDiagnosticTestConfiguration +import org.jetbrains.kotlin.test.services.EnvironmentConfigurator +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.assertions import java.io.File -abstract class AbstractFirAllOpenDiagnosticTest : AbstractFirDiagnosticsTest() { - override val pluginPhasesEnabled: Boolean - get() = true +abstract class AbstractFirAllOpenDiagnosticTest : AbstractKotlinCompilerTest() { + override fun TestConfigurationBuilder.configuration() { + baseFirDiagnosticTestConfiguration(frontendFacade = facade) + defaultDirectives { + +ENABLE_PLUGIN_PHASES + +FIR_DUMP + } - override fun getFirExtensions(): BunchOfRegisteredExtensions { - return FirAllOpenComponentRegistrar().configure() + useConfigurators(::PluginAnnotationsProvider) } - override fun updateConfiguration(configuration: CompilerConfiguration) { - super.updateConfiguration(configuration) - val jar = File("plugins/fir/fir-plugin-prototype/plugin-annotations/build/libs/plugin-annotations-1.5.255-SNAPSHOT.jar") - if (!jar.exists()) { - throw AssertionError("Jar with annotations does not exist. Please run :plugins:fir:fir-plugin-prototype:plugin-annotations:jar") + private val facade: Constructor + get() = { testServices -> + FirFrontendFacade(testServices) { + it.registerExtensions(FirAllOpenComponentRegistrar().configure()) + } + } + + class PluginAnnotationsProvider(testServices: TestServices) : EnvironmentConfigurator(testServices) { + companion object { + const val ANNOTATIONS_JAR = + "plugins/fir/fir-plugin-prototype/plugin-annotations/build/libs/plugin-annotations-1.6.255-SNAPSHOT.jar" + } + + override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) { + val jar = File(ANNOTATIONS_JAR) + testServices.assertions.assertTrue(jar.exists()) { "Jar with annotations does not exist. Please run :plugins:fir:fir-plugin-prototype:plugin-annotations:jar" } + configuration.addJvmClasspathRoot(jar) } - configuration.addJvmClasspathRoot(jar) } }