diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/FirSessionFactoryHelper.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/FirSessionFactoryHelper.kt index 2656bcf5468..a6325f807c2 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/FirSessionFactoryHelper.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/FirSessionFactoryHelper.kt @@ -9,6 +9,7 @@ import org.jetbrains.annotations.TestOnly import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar +import org.jetbrains.kotlin.fir.extensions.FirExtensionService import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider import org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment import org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope @@ -115,6 +116,8 @@ object FirSessionFactoryHelper { get() = stub() } )) + + register(FirExtensionService::class, FirExtensionService(this)) } } } diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.kts b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.kts new file mode 100644 index 00000000000..652510df5d0 --- /dev/null +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.kts @@ -0,0 +1,36 @@ +class Builder { + var version: String = "" + + fun execute() { + println(version) + } + + class Nested { + fun foo() {} + fun boo() {} + } +} + +fun build(action: Builder.() -> Unit) = Builder().apply(action) +fun build2(action: Builder.() -> Unit): Builder = Builder().apply(action) + +build { + version = "123" + class A { + fun doo() { + + } + } + + execute() +} + +version += 123 + +val builder = build { + version = "321" +} + +println() +builder.version = "" +builder.execute() diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.lazyBodies.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.lazyBodies.txt new file mode 100644 index 00000000000..374876aaf42 --- /dev/null +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.lazyBodies.txt @@ -0,0 +1,39 @@ +FILE: script.kts + SCRIPT: + + public? final? class Builder : R|kotlin/Any| { + public? constructor(): R|Builder| { + LAZY_super + } + + public? final? var version: String = LAZY_EXPRESSION + public? get(): String + public? set(value: String): R|kotlin/Unit| + + public? final? fun execute(): R|kotlin/Unit| { LAZY_BLOCK } + + public? final? class Nested : R|kotlin/Any| { + public? constructor(): R|Builder.Nested| { + LAZY_super + } + + public? final? fun foo(): R|kotlin/Unit| { LAZY_BLOCK } + + public? final? fun boo(): R|kotlin/Unit| { LAZY_BLOCK } + + } + + } + + public? final? fun build(action: ( Builder.() -> Unit )): { LAZY_BLOCK } + + public? final? fun build2(action: ( Builder.() -> Unit )): Builder { LAZY_BLOCK } + + build#( = LAZY_EXPRESSION) + +=(version#, IntegerLiteral(123)) + public? final? val builder: = LAZY_EXPRESSION + public? get(): + + println#() + builder#.version# = String() + builder#.execute#() diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.txt new file mode 100644 index 00000000000..88be741c088 --- /dev/null +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.txt @@ -0,0 +1,64 @@ +FILE: script.kts + SCRIPT: + + public? final? class Builder : R|kotlin/Any| { + public? [ContainingClassKey=Builder] constructor(): R|Builder| { + super() + } + + public? final? var version: String = String() + public? [ContainingClassKey=Builder] get(): String + public? [ContainingClassKey=Builder] set(value: String): R|kotlin/Unit| + + public? final? fun execute(): R|kotlin/Unit| { + println#(version#) + } + + public? final? class Nested : R|kotlin/Any| { + public? [ContainingClassKey=Nested] constructor(): R|Builder.Nested| { + super() + } + + public? final? fun foo(): R|kotlin/Unit| { + } + + public? final? fun boo(): R|kotlin/Unit| { + } + + } + + } + + public? final? fun build(action: ( Builder.() -> Unit )): { + ^build Builder#().apply#(action#) + } + + public? final? fun build2(action: ( Builder.() -> Unit )): Builder { + ^build2 Builder#().apply#(action#) + } + + build#( = build@fun .(): { + version# = String(123) + local final? class A : R|kotlin/Any| { + public? [ContainingClassKey=A] constructor(): R|A| { + super() + } + + public? final? fun doo(): R|kotlin/Unit| { + } + + } + + execute#() + } + ) + +=(version#, IntegerLiteral(123)) + public? final? val builder: = build#( = build@fun .(): { + version# = String(321) + } + ) + public? get(): + + println#() + builder#.version# = String() + builder#.execute#() diff --git a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java index 504a4c1a2d0..d92706b8508 100644 --- a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java +++ b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderLazyBodiesTestCaseGenerated.java @@ -26,7 +26,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil } public void testAllFilesPresentInRawBuilder() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations") @@ -38,7 +38,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil } public void testAllFilesPresentInDeclarations() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("annotation.kt") @@ -201,6 +201,11 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingFieldDifferentTypes.kt"); } + @TestMetadata("script.kts") + public void testScript() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.kts"); + } + @TestMetadata("simpleClass.kt") public void testSimpleClass() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt"); @@ -255,7 +260,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil } public void testAllFilesPresentInContracts() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax") @@ -267,7 +272,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil } public void testAllFilesPresentInNewSyntax() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("functionWithBothOldAndNewSyntaxContractDescription.kt") @@ -295,7 +300,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil } public void testAllFilesPresentInOldSyntax() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("contractDescription.kt") @@ -314,7 +319,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil } public void testAllFilesPresentInNoParameterType() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("noParameterTypRefInCatch.kt") @@ -368,7 +373,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil } public void testAllFilesPresentInExpressions() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("annotated.kt") diff --git a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java index 48c5bd9f028..6b0031ee979 100644 --- a/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java +++ b/compiler/fir/raw-fir/psi2fir/tests-gen/org/jetbrains/kotlin/fir/builder/RawFirBuilderTestCaseGenerated.java @@ -26,7 +26,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas } public void testAllFilesPresentInRawBuilder() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations") @@ -38,7 +38,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas } public void testAllFilesPresentInDeclarations() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("annotation.kt") @@ -201,6 +201,11 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingFieldDifferentTypes.kt"); } + @TestMetadata("script.kts") + public void testScript() throws Exception { + runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.kts"); + } + @TestMetadata("simpleClass.kt") public void testSimpleClass() throws Exception { runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt"); @@ -255,7 +260,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas } public void testAllFilesPresentInContracts() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax") @@ -267,7 +272,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas } public void testAllFilesPresentInNewSyntax() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("functionWithBothOldAndNewSyntaxContractDescription.kt") @@ -295,7 +300,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas } public void testAllFilesPresentInOldSyntax() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("contractDescription.kt") @@ -314,7 +319,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas } public void testAllFilesPresentInNoParameterType() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("noParameterTypRefInCatch.kt") @@ -368,7 +373,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas } public void testAllFilesPresentInExpressions() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.(kt|kts)$"), null, true); } @TestMetadata("annotated.kt") diff --git a/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderLazyBodiesTestCase.kt b/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderLazyBodiesTestCase.kt index 10eec92d126..92c7238576c 100644 --- a/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderLazyBodiesTestCase.kt +++ b/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderLazyBodiesTestCase.kt @@ -14,7 +14,7 @@ abstract class AbstractRawFirBuilderLazyBodiesTestCase : AbstractRawFirBuilderTe val file = createKtFile(filePath) val firFile = file.toFirFile(BodyBuildingMode.LAZY_BODIES) val firFileDump = FirRenderer().renderElementAsString(firFile) - val expectedPath = filePath.replace(".kt", ".lazyBodies.txt") + val expectedPath = filePath.replace(".${myFileExt}", ".lazyBodies.txt") KotlinTestUtils.assertEqualsToFile(File(expectedPath), firFileDump) } } \ No newline at end of file diff --git a/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderTestCase.kt b/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderTestCase.kt index 8ebcc672c8f..be704a3598b 100644 --- a/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderTestCase.kt +++ b/compiler/fir/raw-fir/psi2fir/tests/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilderTestCase.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 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. */ @@ -66,7 +66,7 @@ abstract class AbstractRawFirBuilderTestCase : KtParsingTestCase( val file = createKtFile(filePath) val firFile = file.toFirFile(BodyBuildingMode.NORMAL) val firFileDump = FirRenderer.withDeclarationAttributes().renderElementAsString(firFile) - val expectedPath = filePath.replace(".kt", ".txt") + val expectedPath = filePath.replace(".${myFileExt}", ".txt") KotlinTestUtils.assertEqualsToFile(File(expectedPath), firFileDump) } diff --git a/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt b/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt index 4c3bcbc1eb9..64bfaca841f 100644 --- a/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt +++ b/compiler/tests-for-compiler-generator/tests/org/jetbrains/kotlin/test/generators/GenerateJUnit3CompilerTests.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2023 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. */ @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.java.AbstractFirTypeEnhancementTest import org.jetbrains.kotlin.fir.java.AbstractOwnFirTypeEnhancementTest import org.jetbrains.kotlin.fir.lightTree.AbstractLightTree2FirConverterTestCase import org.jetbrains.kotlin.generators.impl.generateTestGroupSuite +import org.jetbrains.kotlin.generators.util.TestGeneratorUtil import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS_WITHOUT_DOTS_IN_NAME import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME import org.jetbrains.kotlin.integration.AbstractAntTaskTest @@ -403,11 +404,11 @@ fun generateJUnit3CompilerTests(args: Array) { testGroup("compiler/fir/raw-fir/psi2fir/tests-gen", "compiler/fir/raw-fir/psi2fir/testData") { testClass { - model("rawBuilder", testMethod = "doRawFirTest") + model("rawBuilder", testMethod = "doRawFirTest", pattern = TestGeneratorUtil.KT_OR_KTS) } testClass { - model("rawBuilder", testMethod = "doRawFirTest") + model("rawBuilder", testMethod = "doRawFirTest", pattern = TestGeneratorUtil.KT_OR_KTS) } testClass {