diff --git a/compiler/testData/codegen/box/jvmPackageName/rootPackage.kt b/compiler/testData/codegen/box/jvmPackageName/rootPackage.kt new file mode 100644 index 00000000000..475834f0ee7 --- /dev/null +++ b/compiler/testData/codegen/box/jvmPackageName/rootPackage.kt @@ -0,0 +1,18 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// LANGUAGE_VERSION: 1.2 + +// FILE: foo.kt + +@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") +@file:JvmPackageName("jjj") + +fun f(): String = "O" + +val g: String? get() = "K" + +inline fun i(block: () -> String) = block() + +// FILE: bar.kt + +fun box(): String = i { f() + g } diff --git a/compiler/testData/codegen/box/jvmPackageName/simple.kt b/compiler/testData/codegen/box/jvmPackageName/simple.kt new file mode 100644 index 00000000000..01d9fac7917 --- /dev/null +++ b/compiler/testData/codegen/box/jvmPackageName/simple.kt @@ -0,0 +1,21 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// LANGUAGE_VERSION: 1.2 + +// FILE: foo.kt + +@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") +@file:JvmPackageName("baz.foo.quux.bar") +package foo.bar + +fun f(): String = "O" + +val g: String? get() = "K" + +inline fun i(block: () -> T): T = block() + +// FILE: bar.kt + +import foo.bar.* + +fun box(): String = i { f() + g } diff --git a/compiler/testData/codegen/box/jvmPackageName/withJvmName.kt b/compiler/testData/codegen/box/jvmPackageName/withJvmName.kt new file mode 100644 index 00000000000..df2917bef0e --- /dev/null +++ b/compiler/testData/codegen/box/jvmPackageName/withJvmName.kt @@ -0,0 +1,19 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// LANGUAGE_VERSION: 1.2 + +// FILE: foo.kt + +@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") +@file:JvmPackageName("jjj") +@file:JvmName("Foooo") + +fun f(): String = "O" + +val g: String? get() = "K" + +inline fun i(block: () -> String) = block() + +// FILE: bar.kt + +fun box(): String = i { f() + g } diff --git a/compiler/testData/codegen/boxInline/jvmPackageName/simple.kt b/compiler/testData/codegen/boxInline/jvmPackageName/simple.kt new file mode 100644 index 00000000000..a68cc6dd26d --- /dev/null +++ b/compiler/testData/codegen/boxInline/jvmPackageName/simple.kt @@ -0,0 +1,21 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// LANGUAGE_VERSION: 1.2 + +// FILE: 1.kt + +@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") +@file:JvmPackageName("baz.foo.quux.bar") +package foo.bar + +fun f(): String = "O" + +val g: String? get() = "K" + +inline fun i(block: () -> T): T = block() + +// FILE: 2.kt + +import foo.bar.* + +fun box(): String = i { f() + g } diff --git a/compiler/testData/compileKotlinAgainstKotlin/jvmPackageName.kt b/compiler/testData/compileKotlinAgainstKotlin/jvmPackageName.kt new file mode 100644 index 00000000000..8a351766474 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/jvmPackageName.kt @@ -0,0 +1,26 @@ +// IGNORE_BACKEND: NATIVE +// FILE: A.kt +// LANGUAGE_VERSION: 1.2 + +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("bar") +package foo + +fun f() = "OK" + +var v: Int = 1 + +inline fun i(block: () -> Unit) = block() + +// FILE: B.kt +// LANGUAGE_VERSION: 1.2 + +import foo.* + +fun box(): String { + v = 2 + if (v != 2) return "Fail" + i { v = 3 } + if (v != 3) return "Fail" + return f() +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameInRootPackage.kt b/compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameInRootPackage.kt new file mode 100644 index 00000000000..65d9f3365ab --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameInRootPackage.kt @@ -0,0 +1,19 @@ +// IGNORE_BACKEND: NATIVE +// FILE: A.kt +// LANGUAGE_VERSION: 1.2 + +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("bar") + +fun f() = "OK" + +var v: Int = 1 + +// FILE: B.kt +// LANGUAGE_VERSION: 1.2 + +fun box(): String { + v = 2 + if (v != 2) return "Fail" + return f() +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameWithJvmName.kt b/compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameWithJvmName.kt new file mode 100644 index 00000000000..d5aa6ce0906 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameWithJvmName.kt @@ -0,0 +1,23 @@ +// IGNORE_BACKEND: NATIVE +// FILE: A.kt +// LANGUAGE_VERSION: 1.2 + +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("bar") +@file:JvmName("Baz") +package foo + +fun f() = "OK" + +var v: Int = 1 + +// FILE: B.kt +// LANGUAGE_VERSION: 1.2 + +import foo.* + +fun box(): String { + v = 2 + if (v != 2) return "Fail" + return f() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.kt new file mode 100644 index 00000000000..e739a7e7461 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.kt @@ -0,0 +1,34 @@ +// !DIAGNOSTICS: -INVISIBLE_MEMBER -INVISIBLE_REFERENCE +// !API_VERSION: 1.2 + +// FILE: a.kt +@file:JvmPackageName("a") +@file:JvmMultifileClass +package a +fun a() {} + +// FILE: b.kt +@file:JvmPackageName("") +package b +fun b() {} + +// FILE: c.kt +@file:JvmPackageName("invalid-fq-name") +package c +fun c() {} + +// FILE: d.kt +@file:JvmPackageName("d") +package d +class D +fun d() {} + +// FILE: e.kt +@file:JvmPackageName(42) +package e +fun e() {} + +// FILE: f.kt +@file:JvmPackageName(f) +package f +const val name = "f" diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.txt b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.txt new file mode 100644 index 00000000000..628e6376875 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.txt @@ -0,0 +1,32 @@ +package + +package a { + public fun a(): kotlin.Unit +} + +package b { + public fun b(): kotlin.Unit +} + +package c { + public fun c(): kotlin.Unit +} + +package d { + public fun d(): kotlin.Unit + + public final class D { + public constructor D() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +package e { + public fun e(): kotlin.Unit +} + +package f { + public const val name: kotlin.String = "f" +} diff --git a/compiler/testData/jvmPackageTable/jvmPackageName/BarAsJ.kt b/compiler/testData/jvmPackageTable/jvmPackageName/BarAsJ.kt new file mode 100644 index 00000000000..e314ca02610 --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageName/BarAsJ.kt @@ -0,0 +1,5 @@ +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("j") +package bar + +fun file0() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageName/BarAsJJ.kt b/compiler/testData/jvmPackageTable/jvmPackageName/BarAsJJ.kt new file mode 100644 index 00000000000..1332d265269 --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageName/BarAsJJ.kt @@ -0,0 +1,6 @@ +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmName("JJ") +@file:JvmPackageName("jj") +package bar + +fun jj() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageName/Foo.kt b/compiler/testData/jvmPackageTable/jvmPackageName/Foo.kt new file mode 100644 index 00000000000..ffa0ca17992 --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageName/Foo.kt @@ -0,0 +1,3 @@ +package foo + +fun file1() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageName/FooAsJJJ.kt b/compiler/testData/jvmPackageTable/jvmPackageName/FooAsJJJ.kt new file mode 100644 index 00000000000..4bb55187bca --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageName/FooAsJJJ.kt @@ -0,0 +1,5 @@ +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("jjj") +package foo + +fun file2() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageName/FooMultiFile.kt b/compiler/testData/jvmPackageTable/jvmPackageName/FooMultiFile.kt new file mode 100644 index 00000000000..7c7268d5381 --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageName/FooMultiFile.kt @@ -0,0 +1,5 @@ +@file:JvmMultifileClass +@file:JvmName("MultiFoo") +package foo + +fun multiFile1() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageName/jvm-package-table.txt b/compiler/testData/jvmPackageTable/jvmPackageName/jvm-package-table.txt new file mode 100644 index 00000000000..0390ef39c28 --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageName/jvm-package-table.txt @@ -0,0 +1,7 @@ +bar + j/BarAsJKt + jj/JJ +foo + foo/MultiFoo__FooMultiFileKt (foo/MultiFoo) + foo/FooKt + jjj/FooAsJJJKt diff --git a/compiler/testData/jvmPackageTable/jvmPackageNameLanguageVersion11/Foo.kt b/compiler/testData/jvmPackageTable/jvmPackageNameLanguageVersion11/Foo.kt new file mode 100644 index 00000000000..ffa0ca17992 --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageNameLanguageVersion11/Foo.kt @@ -0,0 +1,3 @@ +package foo + +fun file1() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageNameLanguageVersion11/FooAsJ.kt b/compiler/testData/jvmPackageTable/jvmPackageNameLanguageVersion11/FooAsJ.kt new file mode 100644 index 00000000000..ad28a3952ca --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageNameLanguageVersion11/FooAsJ.kt @@ -0,0 +1,5 @@ +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("j") +package foo + +fun file2() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageNameLanguageVersion11/jvm-package-table.txt b/compiler/testData/jvmPackageTable/jvmPackageNameLanguageVersion11/jvm-package-table.txt new file mode 100644 index 00000000000..78bc5936829 --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageNameLanguageVersion11/jvm-package-table.txt @@ -0,0 +1,2 @@ +foo + foo/FooKt diff --git a/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/Foo1.kt b/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/Foo1.kt new file mode 100644 index 00000000000..55ca8bc833e --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/Foo1.kt @@ -0,0 +1,5 @@ +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("foo.jvm") +package foo + +fun foo1() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/Foo2.kt b/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/Foo2.kt new file mode 100644 index 00000000000..f7e3ccea95b --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/Foo2.kt @@ -0,0 +1,5 @@ +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("foo.jvm") +package foo + +fun foo2() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/Foo3.kt b/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/Foo3.kt new file mode 100644 index 00000000000..ac492382822 --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/Foo3.kt @@ -0,0 +1,5 @@ +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@file:JvmPackageName("foo.jvm") +package foo + +fun foo3() {} diff --git a/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/jvm-package-table.txt b/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/jvm-package-table.txt new file mode 100644 index 00000000000..5500612a972 --- /dev/null +++ b/compiler/testData/jvmPackageTable/jvmPackageNameManyParts/jvm-package-table.txt @@ -0,0 +1,4 @@ +foo + foo/jvm/Foo1Kt + foo/jvm/Foo2Kt + foo/jvm/Foo3Kt diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 25a8f36bdcd..181e885dd11 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -10560,6 +10560,33 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractIrBlackBoxCodegenTest { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("rootPackage.kt") + public void testRootPackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/rootPackage.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/simple.kt"); + doTest(fileName); + } + + @TestMetadata("withJvmName.kt") + public void testWithJvmName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/withJvmName.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/jvmStatic") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 1d844273d18..c5befc65851 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -1587,6 +1587,21 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli } } + @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractIrBlackBoxInlineCodegenTest { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/jvmPackageName/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/lambdaClassClash") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index b256426ddee..69d5d6182f7 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1587,6 +1587,21 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC } } + @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractIrCompileKotlinAgainstInlineKotlinTest { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/jvmPackageName/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/lambdaClassClash") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 5bdb1e92356..a828bceb9fe 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -554,6 +554,21 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW } } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractDiagnosticsTestWithStdLib { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("incorrectJvmPackageName.kt") + public void testIncorrectJvmPackageName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmStatic") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index ffe2fef9a30..ab94b74b1b9 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -520,6 +520,21 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractDiagnosticsTestWithStdLibUsingJavac { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("incorrectJvmPackageName.kt") + public void testIncorrectJvmPackageName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmPackageName/incorrectJvmPackageName.kt"); + doTest(fileName); + } + } + @TestMetadata("JvmOverloadWithNoDefaults.kt") public void testJvmOverloadWithNoDefaults() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/jvmOverloads/JvmOverloadWithNoDefaults.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index ba43bcb20e1..b303967aa7d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -10560,6 +10560,33 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("rootPackage.kt") + public void testRootPackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/rootPackage.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/simple.kt"); + doTest(fileName); + } + + @TestMetadata("withJvmName.kt") + public void testWithJvmName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/withJvmName.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/jvmStatic") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 02354bf5181..f1352b73f2c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -1587,6 +1587,21 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo } } + @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractBlackBoxInlineCodegenTest { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/jvmPackageName/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/lambdaClassClash") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 84df6dcffc2..342ee1b8040 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1587,6 +1587,21 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi } } + @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractCompileKotlinAgainstInlineKotlinTest { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/jvmPackageName/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/lambdaClassClash") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java index 01e7ad364a1..097e80fd0d0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java @@ -138,6 +138,24 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl doTest(fileName); } + @TestMetadata("jvmPackageName.kt") + public void testJvmPackageName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmPackageName.kt"); + doTest(fileName); + } + + @TestMetadata("jvmPackageNameInRootPackage.kt") + public void testJvmPackageNameInRootPackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameInRootPackage.kt"); + doTest(fileName); + } + + @TestMetadata("jvmPackageNameWithJvmName.kt") + public void testJvmPackageNameWithJvmName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmPackageNameWithJvmName.kt"); + doTest(fileName); + } + @TestMetadata("jvmStaticInObject.kt") public void testJvmStaticInObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/jvmStaticInObject.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/JvmPackageTableTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/JvmPackageTableTest.kt index d291b5d71cc..dbcb53f5f2a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/JvmPackageTableTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/codegen/JvmPackageTableTest.kt @@ -76,4 +76,19 @@ class JvmPackageTableTest : KtUsefulTestCase() { fun testSimple() { doTest("/jvmPackageTable/simple") } + + fun testJvmPackageName() { + doTest("/jvmPackageTable/jvmPackageName", + compileWith = LanguageVersion.KOTLIN_1_2, loadWith = LanguageVersion.KOTLIN_1_2) + } + + fun testJvmPackageNameManyParts() { + doTest("/jvmPackageTable/jvmPackageNameManyParts", + compileWith = LanguageVersion.KOTLIN_1_2, loadWith = LanguageVersion.KOTLIN_1_2) + } + + fun testJvmPackageNameLanguageVersion11() { + doTest("/jvmPackageTable/jvmPackageNameLanguageVersion11", + compileWith = LanguageVersion.KOTLIN_1_2, loadWith = LanguageVersion.KOTLIN_1_1) + } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 2984ab8475f..e0b711d95c9 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -10560,6 +10560,33 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractLightAnalysisModeTest { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("rootPackage.kt") + public void testRootPackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/rootPackage.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/simple.kt"); + doTest(fileName); + } + + @TestMetadata("withJvmName.kt") + public void testWithJvmName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmPackageName/withJvmName.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/jvmStatic") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/core/runtime.jvm/src/kotlin/jvm/annotations/JvmPlatformAnnotations.kt b/core/runtime.jvm/src/kotlin/jvm/annotations/JvmPlatformAnnotations.kt index 28890bec5fc..e270da2ded6 100644 --- a/core/runtime.jvm/src/kotlin/jvm/annotations/JvmPlatformAnnotations.kt +++ b/core/runtime.jvm/src/kotlin/jvm/annotations/JvmPlatformAnnotations.kt @@ -62,6 +62,18 @@ public annotation class JvmName(val name: String) @MustBeDocumented public annotation class JvmMultifileClass +/** + * Changes the fully qualified name of the JVM package of the .class file generated from this file. + * This does not affect the way Kotlin clients will see the declarations in this file, but Java clients and other JVM language clients + * will see the class file as if it was declared in the specified package. + * If a file is annotated with this annotation, it can only have function, property and typealias declarations, but no classes. + */ +@Target(AnnotationTarget.FILE) +@Retention(AnnotationRetention.SOURCE) +@MustBeDocumented +@SinceKotlin("1.2") +internal annotation class JvmPackageName(val name: String) + @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FIELD) @Retention(AnnotationRetention.SOURCE) public annotation class JvmSynthetic diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 9f7bb5c523c..f35b18b2181 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -11802,6 +11802,15 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/jvmPackageName") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JvmPackageName extends AbstractJsCodegenBoxTest { + public void testAllFilesPresentInJvmPackageName() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/jvmPackageName"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + } + @TestMetadata("compiler/testData/codegen/box/jvmStatic") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)