From 77101edfa430e62744b94620e5b0f713bfe08f72 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 1 Dec 2021 17:16:21 +0300 Subject: [PATCH] [FIR] Setup tests for IC with compiler plugins Most of those tests are ignored, because IC is not supported properly for compiler plugins. This commit is needed to prepare infrastructure, fix current behaviour and collect main problems of IC with plugins Check fail.txt files in new testdata for explanation of problems --- build.gradle.kts | 4 +- generators/build.gradle.kts | 1 + .../kotlin/generators/tests/GenerateTests.kt | 6 ++ plugins/fir-plugin-prototype/build.gradle.kts | 1 + .../fir-plugin-ic-test/build.gradle.kts | 61 +++++++++++++++++++ .../pureKotlin/addMethodToGeneratedClass/A.kt | 9 +++ .../addMethodToGeneratedClass/B.kt.new | 6 ++ .../addMethodToGeneratedClass/build.log | 8 +++ .../addMethodToGeneratedClass/fail.txt | 2 + .../addMethodToGeneratedClass/usage.kt | 7 +++ .../MyInterface.kt | 5 ++ .../MyInterface.kt.new | 7 +++ .../SomeClass.kt | 8 +++ .../addMethodToGeneratedSupertype/build.log | 7 +++ .../addMethodToGeneratedSupertype/usage.kt | 5 ++ .../pureKotlin/addNewSerializableClass/A.kt | 4 ++ .../addNewSerializableClass/B.kt.new | 4 ++ .../addNewSerializableClass/Serializer.kt | 4 ++ .../addNewSerializableClass/build.log | 8 +++ .../addNewSerializableClass/fail.txt | 1 + .../generateNewTopLevelFunction/A.kt | 6 ++ .../generateNewTopLevelFunction/B.kt.new | 6 ++ .../generateNewTopLevelFunction/build.log | 9 +++ .../generateNewTopLevelFunction/fail.txt | 2 + .../generateNewTopLevelFunction/lib.kt | 3 + .../generateNewTopLevelFunction/usage.kt | 7 +++ ...WithPluginCompilerRunnerTestGenerated.java | 52 ++++++++++++++++ ...ractIncrementalFirJvmCompilerRunnerTest.kt | 44 +++++++++++++ ...kotlin.compiler.plugin.ComponentRegistrar} | 2 +- ...> FirPluginPrototypeExtensionRegistrar.kt} | 14 ++++- .../ExtensionRegistrarConfigurator.kt | 4 +- settings.gradle | 1 + 32 files changed, 303 insertions(+), 5 deletions(-) create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/build.gradle.kts create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/A.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/B.kt.new create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/build.log create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/fail.txt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/usage.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/MyInterface.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/MyInterface.kt.new create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/SomeClass.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/build.log create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/usage.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/A.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/B.kt.new create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/Serializer.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/build.log create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/fail.txt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/A.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/B.kt.new create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/build.log create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/fail.txt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/lib.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/usage.kt create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/tests-gen/org/jetbrains/kotlin/incremental/IncrementalFirJvmWithPluginCompilerRunnerTestGenerated.java create mode 100644 plugins/fir-plugin-prototype/fir-plugin-ic-test/tests/org/jetbrains/kotlin/incremental/AbstractIncrementalFirJvmCompilerRunnerTest.kt rename plugins/fir-plugin-prototype/resources/META-INF/services/{org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar => org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar} (74%) rename plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/{FirAllOpenComponentRegistrar.kt => FirPluginPrototypeExtensionRegistrar.kt} (55%) diff --git a/build.gradle.kts b/build.gradle.kts index 1e364472ee5..64a5f1b7249 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -733,6 +733,7 @@ tasks { dependsOn(":compiler:fir:analysis-tests:legacy-fir-tests:test") dependsOn(":compiler:fir:fir2ir:test") dependsOn(":plugins:fir-plugin-prototype:test") + dependsOn(":plugins:fir-plugin-prototype:fir-plugin-ic-test:test") } register("firAllTest") { @@ -743,7 +744,8 @@ tasks { ":compiler:fir:analysis-tests:test", ":compiler:fir:analysis-tests:legacy-fir-tests:test", ":compiler:fir:fir2ir:test", - ":plugins:fir-plugin-prototype:test" + ":plugins:fir-plugin-prototype:test", + ":plugins:fir-plugin-prototype:fir-plugin-ic-test:test" ) } diff --git a/generators/build.gradle.kts b/generators/build.gradle.kts index bec39c00665..dad38d40fcd 100644 --- a/generators/build.gradle.kts +++ b/generators/build.gradle.kts @@ -67,6 +67,7 @@ dependencies { testApi(projectTests(":kotlinx-serialization-compiler-plugin")) testApi(projectTests(":kotlinx-atomicfu-compiler-plugin")) testApi(projectTests(":plugins:fir-plugin-prototype")) + testApi(projectTests(":plugins:fir-plugin-prototype:fir-plugin-ic-test")) testApi(projectTests(":generators:test-generator")) testCompileOnly(project(":kotlin-reflect-api")) testImplementation(intellijDep()) { includeJars("idea_rt") } diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 4ee82a747dc..d1c96ef3638 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -347,6 +347,12 @@ fun main(args: Array) { } } */ + + testGroup("plugins/fir-plugin-prototype/fir-plugin-ic-test/tests-gen", "plugins/fir-plugin-prototype/fir-plugin-ic-test/testData") { + testClass { + model("pureKotlin", extension = null, recursive = false, targetBackend = TargetBackend.JVM_IR) + } + } } generateTestGroupSuiteWithJUnit5 { diff --git a/plugins/fir-plugin-prototype/build.gradle.kts b/plugins/fir-plugin-prototype/build.gradle.kts index 9e231bced0b..32ae14e2fe0 100644 --- a/plugins/fir-plugin-prototype/build.gradle.kts +++ b/plugins/fir-plugin-prototype/build.gradle.kts @@ -14,6 +14,7 @@ dependencies { compileOnly(project(":compiler:ir.backend.common")) compileOnly(project(":compiler:ir.tree.impl")) compileOnly(project(":compiler:fir:entrypoint")) + compileOnly(project(":compiler:plugin-api")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(project(":kotlin-reflect-api")) diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/build.gradle.kts b/plugins/fir-plugin-prototype/fir-plugin-ic-test/build.gradle.kts new file mode 100644 index 00000000000..35d0694207a --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/build.gradle.kts @@ -0,0 +1,61 @@ +import org.jetbrains.kotlin.ideaExt.idea + +plugins { + kotlin("jvm") + id("jps-compatible") +} + +dependencies { + testApi(project(":plugins:fir-plugin-prototype")) + testApi(project(":compiler:incremental-compilation-impl")) + testApi(projectTests(":compiler:incremental-compilation-impl")) + + testCompileOnly(intellijCoreDep()) { includeJars("intellij-core") } + testCompileOnly(project(":kotlin-reflect-api")) + + testRuntimeOnly(project(":kotlin-reflect")) + testRuntimeOnly(project(":core:descriptors.runtime")) + testRuntimeOnly(project(":compiler:fir:fir-serialization")) + + testRuntimeOnly(intellijDep()) { + includeJars( + "lz4-java", + "jna", + "jdom", + "trove4j", + "intellij-deps-fastutil-8.4.1-4", + rootProject = rootProject) + } + + testRuntimeOnly(toolsJar()) +} + +val generationRoot = projectDir.resolve("tests-gen") + +sourceSets { + "main" { + projectDefault() + } + "test" { + projectDefault() + this.java.srcDir(generationRoot.name) + } +} + +if (kotlinBuildProperties.isInJpsBuildIdeaSync) { + apply(plugin = "idea") + idea { + this.module.generatedSourceDirs.add(generationRoot) + } +} + +projectTest(parallel = true, jUnitMode = JUnitMode.JUnit4) { + workingDir = rootDir + useJUnitPlatform() + jvmArgs!!.removeIf { it.contains("-Xmx") } + maxHeapSize = "3g" + dependsOn(":plugins:fir-plugin-prototype:jar") + dependsOn(":plugins:fir-plugin-prototype:plugin-annotations:jar") +} + +testsJar() diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/A.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/A.kt new file mode 100644 index 00000000000..e82b2aac57c --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/A.kt @@ -0,0 +1,9 @@ +package bar + +import foo.AllOpenGenerated +import org.jetbrains.kotlin.fir.plugin.ExternalClassWithNested + +@ExternalClassWithNested +class A + +FAIL // comment me to actually run test diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/B.kt.new b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/B.kt.new new file mode 100644 index 00000000000..eff100c9032 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/B.kt.new @@ -0,0 +1,6 @@ +package bar + +import org.jetbrains.kotlin.fir.plugin.ExternalClassWithNested + +@ExternalClassWithNested +class B diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/build.log b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/build.log new file mode 100644 index 00000000000..9aa356a7da2 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/build.log @@ -0,0 +1,8 @@ +================ Step #1 ================= + +Compiling files: + src/B.kt +End of files +Exit code: OK + +------------------------------------------ diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/fail.txt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/fail.txt new file mode 100644 index 00000000000..3cb4c57ca68 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/fail.txt @@ -0,0 +1,2 @@ +For some reason IC goes to eternal loop of compilation in this test. To observe this comment `FAIL` line in A.kt + to make test actually compilable diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/usage.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/usage.kt new file mode 100644 index 00000000000..49b2d3f25db --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/usage.kt @@ -0,0 +1,7 @@ +package bar + +import foo.AllOpenGenerated + +fun test() { + AllOpenGenerated.NestedA().materialize() +} diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/MyInterface.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/MyInterface.kt new file mode 100644 index 00000000000..552f9c9a56b --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/MyInterface.kt @@ -0,0 +1,5 @@ +package foo + +interface MyInterface { + fun foo() +} diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/MyInterface.kt.new b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/MyInterface.kt.new new file mode 100644 index 00000000000..fb3078eaeaa --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/MyInterface.kt.new @@ -0,0 +1,7 @@ +package foo + +interface MyInterface { + fun foo() + + fun bar() {} +} diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/SomeClass.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/SomeClass.kt new file mode 100644 index 00000000000..ff4d5ff556f --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/SomeClass.kt @@ -0,0 +1,8 @@ +package foo + +import org.jetbrains.kotlin.fir.plugin.MyInterfaceSupertype + +@MyInterfaceSupertype +class SomeClass { + override fun foo() {} +} diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/build.log b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/build.log new file mode 100644 index 00000000000..e07b904018a --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/build.log @@ -0,0 +1,7 @@ +================ Step #1 ================= +Compiling files: + src/MyInterface.kt + src/SomeClass.kt +End of files +Exit code: OK +------------------------------------------ diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/usage.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/usage.kt new file mode 100644 index 00000000000..3083ac9ac3d --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/usage.kt @@ -0,0 +1,5 @@ +package foo + +fun test() { + SomeClass().foo() +} diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/A.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/A.kt new file mode 100644 index 00000000000..78882b34122 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/A.kt @@ -0,0 +1,4 @@ +import org.jetbrains.kotlin.fir.plugin.MySerializable + +@MySerializable +class A diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/B.kt.new b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/B.kt.new new file mode 100644 index 00000000000..6e7f991a3c4 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/B.kt.new @@ -0,0 +1,4 @@ +import org.jetbrains.kotlin.fir.plugin.MySerializable + +@MySerializable +class B diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/Serializer.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/Serializer.kt new file mode 100644 index 00000000000..903d0b50053 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/Serializer.kt @@ -0,0 +1,4 @@ +import org.jetbrains.kotlin.fir.plugin.CoreSerializer + +@CoreSerializer +object Serializer diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/build.log b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/build.log new file mode 100644 index 00000000000..9aa356a7da2 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/build.log @@ -0,0 +1,8 @@ +================ Step #1 ================= + +Compiling files: + src/B.kt +End of files +Exit code: OK + +------------------------------------------ diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/fail.txt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/fail.txt new file mode 100644 index 00000000000..3a940db8d8f --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/fail.txt @@ -0,0 +1 @@ +Serializer.kt should be also marked as dirty, because it's content depends on declarations which are annotated with @Serializable diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/A.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/A.kt new file mode 100644 index 00000000000..d4720bdb92f --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/A.kt @@ -0,0 +1,6 @@ +package foo + +import org.jetbrains.kotlin.fir.plugin.DummyFunction + +@DummyFunction +class A diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/B.kt.new b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/B.kt.new new file mode 100644 index 00000000000..d4ba925b5a1 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/B.kt.new @@ -0,0 +1,6 @@ +package foo + +import org.jetbrains.kotlin.fir.plugin.DummyFunction + +@DummyFunction +class B diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/build.log b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/build.log new file mode 100644 index 00000000000..afe97eb14c2 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/build.log @@ -0,0 +1,9 @@ +================ Step #1 ================= + +Compiling files: + src/B.kt + src/usage.kt +End of files +Exit code: OK + +------------------------------------------ diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/fail.txt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/fail.txt new file mode 100644 index 00000000000..67bce80d4ba --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/fail.txt @@ -0,0 +1,2 @@ +Test fails because FirPredicateBasedProvider doesn't search for annotated declarations in binary dependencies + which came from previous compilation round, so plugin can not generate all what it wants diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/lib.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/lib.kt new file mode 100644 index 00000000000..feb1a608b8f --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/lib.kt @@ -0,0 +1,3 @@ +package bar + +fun dummyB(any: Any) {} diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/usage.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/usage.kt new file mode 100644 index 00000000000..974d3acee20 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/usage.kt @@ -0,0 +1,7 @@ +package foo + +import bar.* + +fun test() { + dummyB("hello") +} diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/tests-gen/org/jetbrains/kotlin/incremental/IncrementalFirJvmWithPluginCompilerRunnerTestGenerated.java b/plugins/fir-plugin-prototype/fir-plugin-ic-test/tests-gen/org/jetbrains/kotlin/incremental/IncrementalFirJvmWithPluginCompilerRunnerTestGenerated.java new file mode 100644 index 00000000000..523a5bb5441 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/tests-gen/org/jetbrains/kotlin/incremental/IncrementalFirJvmWithPluginCompilerRunnerTestGenerated.java @@ -0,0 +1,52 @@ +/* + * 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.incremental; + +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.TargetBackend; +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("plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class IncrementalFirJvmWithPluginCompilerRunnerTestGenerated extends AbstractIncrementalFirJvmWithPluginCompilerRunnerTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + @TestMetadata("addMethodToGeneratedClass") + public void testAddMethodToGeneratedClass() throws Exception { + runTest("plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedClass/"); + } + + @TestMetadata("addMethodToGeneratedSupertype") + public void testAddMethodToGeneratedSupertype() throws Exception { + runTest("plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addMethodToGeneratedSupertype/"); + } + + @TestMetadata("addNewSerializableClass") + public void testAddNewSerializableClass() throws Exception { + runTest("plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/addNewSerializableClass/"); + } + + public void testAllFilesPresentInPureKotlin() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin"), Pattern.compile("^([^\\.]+)$"), null, TargetBackend.JVM_IR, false); + } + + @TestMetadata("generateNewTopLevelFunction") + public void testGenerateNewTopLevelFunction() throws Exception { + runTest("plugins/fir-plugin-prototype/fir-plugin-ic-test/testData/pureKotlin/generateNewTopLevelFunction/"); + } +} diff --git a/plugins/fir-plugin-prototype/fir-plugin-ic-test/tests/org/jetbrains/kotlin/incremental/AbstractIncrementalFirJvmCompilerRunnerTest.kt b/plugins/fir-plugin-prototype/fir-plugin-ic-test/tests/org/jetbrains/kotlin/incremental/AbstractIncrementalFirJvmCompilerRunnerTest.kt new file mode 100644 index 00000000000..20b91f74c95 --- /dev/null +++ b/plugins/fir-plugin-prototype/fir-plugin-ic-test/tests/org/jetbrains/kotlin/incremental/AbstractIncrementalFirJvmCompilerRunnerTest.kt @@ -0,0 +1,44 @@ +/* + * 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.incremental + +import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments +import org.jetbrains.kotlin.incremental.testingUtils.BuildLogFinder +import org.junit.jupiter.api.fail +import java.io.File +import java.io.FilenameFilter + +abstract class AbstractIncrementalFirJvmWithPluginCompilerRunnerTest : AbstractIncrementalFirJvmCompilerRunnerTest() { + companion object { + private const val ANNOTATIONS_JAR_DIR = "plugins/fir-plugin-prototype/plugin-annotations/build/libs/" + private const val ANNOTATIONS_JAR_NAME = "plugin-annotations" + + private const val PLUGIN_JAR_DIR = "plugins/fir-plugin-prototype/build/libs/" + private const val PLUGIN_JAR_NAME = "fir-plugin-prototype" + + private fun findJar(dir: String, name: String, taskName: String): String { + val failMessage = { "Jar $name does not exist. Please run $taskName" } + val libDir = File(dir) + kotlin.test.assertTrue(libDir.exists() && libDir.isDirectory) + val jar = libDir.listFiles()?.firstOrNull { + it.name.startsWith(name) && it.extension == "jar" + } ?: fail(failMessage) + return jar.canonicalPath + } + } + + override fun createCompilerArguments(destinationDir: File, testDir: File): K2JVMCompilerArguments = + super.createCompilerArguments(destinationDir, testDir).apply { + val annotationsJar = findJar(ANNOTATIONS_JAR_DIR, ANNOTATIONS_JAR_NAME, ":plugins:fir-plugin-prototype:plugin-annotations:jar") + val pluginJar = findJar(PLUGIN_JAR_DIR, PLUGIN_JAR_NAME, ":plugins:fir-plugin-prototype:jar") + + classpath += "${File.pathSeparator}$annotationsJar" + pluginClasspaths = arrayOf(pluginJar) + } + + override val buildLogFinder: BuildLogFinder + get() = BuildLogFinder(isGradleEnabled = true, isFirEnabled = true) // TODO: investigate cases that need isGradleEnabled - the combination looks fragile +} diff --git a/plugins/fir-plugin-prototype/resources/META-INF/services/org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar b/plugins/fir-plugin-prototype/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar similarity index 74% rename from plugins/fir-plugin-prototype/resources/META-INF/services/org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar rename to plugins/fir-plugin-prototype/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar index 30025ef4446..1e0e2a01470 100644 --- a/plugins/fir-plugin-prototype/resources/META-INF/services/org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar +++ b/plugins/fir-plugin-prototype/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar @@ -3,4 +3,4 @@ # Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. # -org.jetbrains.kotlin.fir.plugin.FirAllOpenComponentRegistrar \ No newline at end of file +org.jetbrains.kotlin.fir.plugin.FirPluginPrototypeComponentRegistrar diff --git a/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirAllOpenComponentRegistrar.kt b/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirPluginPrototypeExtensionRegistrar.kt similarity index 55% rename from plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirAllOpenComponentRegistrar.kt rename to plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirPluginPrototypeExtensionRegistrar.kt index 04841faa69a..5a108cf9d8e 100644 --- a/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirAllOpenComponentRegistrar.kt +++ b/plugins/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/FirPluginPrototypeExtensionRegistrar.kt @@ -5,11 +5,16 @@ package org.jetbrains.kotlin.fir.plugin +import com.intellij.mock.MockProject +import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar import org.jetbrains.kotlin.fir.plugin.generators.* import org.jetbrains.kotlin.fir.plugin.types.FirNumberSignAttributeExtension +import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar +import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.ir.plugin.GeneratedDeclarationsIrBodyFiller -class FirAllOpenComponentRegistrar : FirExtensionRegistrar() { +class FirPluginPrototypeExtensionRegistrar : FirExtensionRegistrar() { override fun ExtensionRegistrarContext.configurePlugin() { +::AllOpenStatusTransformer +::AllPublicVisibilityTransformer @@ -25,3 +30,10 @@ class FirAllOpenComponentRegistrar : FirExtensionRegistrar() { +::MembersOfSerializerGenerator } } + +class FirPluginPrototypeComponentRegistrar : ComponentRegistrar { + override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) { + FirExtensionRegistrar.registerExtension(project, FirPluginPrototypeExtensionRegistrar()) + IrGenerationExtension.registerExtension(project, GeneratedDeclarationsIrBodyFiller()) + } +} diff --git a/plugins/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/services/ExtensionRegistrarConfigurator.kt b/plugins/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/services/ExtensionRegistrarConfigurator.kt index 934a309901e..be056ffc907 100644 --- a/plugins/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/services/ExtensionRegistrarConfigurator.kt +++ b/plugins/fir-plugin-prototype/tests/org/jetbrains/kotlin/fir/plugin/services/ExtensionRegistrarConfigurator.kt @@ -8,14 +8,14 @@ package org.jetbrains.kotlin.fir.plugin.services import com.intellij.openapi.project.Project import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar -import org.jetbrains.kotlin.fir.plugin.FirAllOpenComponentRegistrar +import org.jetbrains.kotlin.fir.plugin.FirPluginPrototypeExtensionRegistrar import org.jetbrains.kotlin.ir.plugin.GeneratedDeclarationsIrBodyFiller import org.jetbrains.kotlin.test.services.EnvironmentConfigurator import org.jetbrains.kotlin.test.services.TestServices class ExtensionRegistrarConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) { override fun registerCompilerExtensions(project: Project) { - FirExtensionRegistrar.registerExtension(project, FirAllOpenComponentRegistrar()) + FirExtensionRegistrar.registerExtension(project, FirPluginPrototypeExtensionRegistrar()) IrGenerationExtension.registerExtension(project, GeneratedDeclarationsIrBodyFiller()) } } diff --git a/settings.gradle b/settings.gradle index f50678d1eaa..bf6dfd0a97e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -197,6 +197,7 @@ include ":benchmarks", ":kotlin-script-runtime", ":plugins:fir-plugin-prototype", ":plugins:fir-plugin-prototype:plugin-annotations", + ":plugins:fir-plugin-prototype:fir-plugin-ic-test", ":kotlin-test:kotlin-test-common", ":kotlin-test:kotlin-test-annotations-common", ":kotlin-test:kotlin-test-jvm",