From 36f154882ca9e6162fe1ce2f9df5b4765c19d1b3 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 21 Aug 2018 18:51:35 +0300 Subject: [PATCH] Provide JvmSynthetic annotation in stdlib-common as optional #KT-24478 --- .../stdlib/common/src/kotlin/JvmAnnotationsH.kt | 13 +++++++++++++ .../jvm/annotations/JvmPlatformAnnotations.kt | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libraries/stdlib/common/src/kotlin/JvmAnnotationsH.kt b/libraries/stdlib/common/src/kotlin/JvmAnnotationsH.kt index 78a80d4779c..341366b839f 100644 --- a/libraries/stdlib/common/src/kotlin/JvmAnnotationsH.kt +++ b/libraries/stdlib/common/src/kotlin/JvmAnnotationsH.kt @@ -64,6 +64,19 @@ public expect annotation class JvmMultifileClass() @OptionalExpectation public expect annotation class JvmField() +/** + * Sets `ACC_SYNTHETIC` flag on the annotated target in the Java bytecode. + * + * Synthetic targets become inaccessible for Java sources at compile time while still being accessible for Kotlin sources. + * Marking target as synthetic is a binary compatible change, already compiled Java code will be able to access such target. + * + * This annotation is intended for *rare cases* when API designer needs to hide Kotlin-specific target from Java API + * while keeping it a part of Kotlin API so the resulting API is idiomatic for both languages. + */ +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FIELD) +@OptionalExpectation +public expect annotation class JvmSynthetic() + /** * Instructs compiler to generate or omit wildcards for type arguments corresponding to parameters with * declaration-site variance, for example such as `Collection` has. diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/annotations/JvmPlatformAnnotations.kt b/libraries/stdlib/jvm/runtime/kotlin/jvm/annotations/JvmPlatformAnnotations.kt index 4f6560fa8fb..c0757e11790 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/annotations/JvmPlatformAnnotations.kt +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/annotations/JvmPlatformAnnotations.kt @@ -76,7 +76,7 @@ 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 +public actual annotation class JvmSynthetic /** * This annotation indicates what exceptions should be declared by a function when compiled to a JVM method.