diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java index f363837796e..ec274392835 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java @@ -921,7 +921,9 @@ public class KotlinTypeMapper { return name; } - if (!(descriptor instanceof ConstructorDescriptor) && descriptor.getVisibility() == Visibilities.INTERNAL) { + if (!(descriptor instanceof ConstructorDescriptor) && + descriptor.getVisibility() == Visibilities.INTERNAL && + !descriptor.getAnnotations().hasAnnotation(KotlinBuiltIns.FQ_NAMES.publishedApi)) { return name + "$" + JvmAbi.sanitizeAsJavaIdentifier(moduleName); } diff --git a/compiler/testData/codegen/box/publishedApi/noMangling.kt b/compiler/testData/codegen/box/publishedApi/noMangling.kt new file mode 100644 index 00000000000..bc4b0b5a388 --- /dev/null +++ b/compiler/testData/codegen/box/publishedApi/noMangling.kt @@ -0,0 +1,15 @@ +// IGNORE_BACKEND: JS +//WITH_REFLECT +class A { + @PublishedApi + internal fun published() = "OK" + + inline fun test() = published() + +} + +fun box() : String { + val clazz = A::class.java + if (clazz.getDeclaredMethod("published") == null) return "fail" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/publishedApi/simple.kt b/compiler/testData/codegen/box/publishedApi/simple.kt new file mode 100644 index 00000000000..f21d948cf2a --- /dev/null +++ b/compiler/testData/codegen/box/publishedApi/simple.kt @@ -0,0 +1,12 @@ +class A { + + @PublishedApi + internal fun published() = "OK" + + inline fun test() = published() + +} + +fun box() : String { + return A().test() +} \ No newline at end of file diff --git a/compiler/testData/codegen/light-analysis/publishedApi/noMangling.txt b/compiler/testData/codegen/light-analysis/publishedApi/noMangling.txt new file mode 100644 index 00000000000..c5baf5dae27 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/publishedApi/noMangling.txt @@ -0,0 +1,10 @@ +public final class A { + public method (): void + public final @kotlin.PublishedApi @org.jetbrains.annotations.NotNull method published(): java.lang.String + public final @org.jetbrains.annotations.NotNull method test(): java.lang.String +} + + +public final class NoManglingKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} diff --git a/compiler/testData/codegen/light-analysis/publishedApi/simple.txt b/compiler/testData/codegen/light-analysis/publishedApi/simple.txt new file mode 100644 index 00000000000..f1ddb5c5e67 --- /dev/null +++ b/compiler/testData/codegen/light-analysis/publishedApi/simple.txt @@ -0,0 +1,10 @@ +public final class A { + public method (): void + public final @kotlin.PublishedApi @org.jetbrains.annotations.NotNull method published(): java.lang.String + public final @org.jetbrains.annotations.NotNull method test(): java.lang.String +} + + +public final class SimpleKt { + public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String +} 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 410ca6545af..592d446d70e 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 @@ -11655,6 +11655,27 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/publishedApi") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PublishedApi extends AbstractIrBlackBoxCodegenTest { + public void testAllFilesPresentInPublishedApi() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/publishedApi"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("noMangling.kt") + public void testNoMangling() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/publishedApi/noMangling.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/publishedApi/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 50d5da0d54f..a7f9ff72325 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -11655,6 +11655,27 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/publishedApi") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PublishedApi extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInPublishedApi() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/publishedApi"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("noMangling.kt") + public void testNoMangling() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/publishedApi/noMangling.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/publishedApi/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java index d22976ef59d..91bf7b928dd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeCodegenTestGenerated.java @@ -11655,6 +11655,27 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis } } + @TestMetadata("compiler/testData/codegen/box/publishedApi") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PublishedApi extends AbstractLightAnalysisModeCodegenTest { + public void testAllFilesPresentInPublishedApi() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/publishedApi"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("noMangling.kt") + public void testNoMangling() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/publishedApi/noMangling.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/publishedApi/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) 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 476b2362373..e75fa62acb5 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 @@ -14182,6 +14182,33 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/publishedApi") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class PublishedApi extends AbstractJsCodegenBoxTest { + public void testAllFilesPresentInPublishedApi() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/publishedApi"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("noMangling.kt") + public void testNoMangling() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/publishedApi/noMangling.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/publishedApi/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/ranges") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)