Skip to content

Commit a4a8a01

Browse files
committed
Add since attribute to Deprecated annotation
Introduce the since attribute to the Deprecated annotation to allow documenting the version or date when an API was marked as deprecated. Update the KDoc to explain its purpose.
1 parent 916d81d commit a4a8a01

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libraries/stdlib/src/kotlin/Annotations.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import kotlin.annotation.AnnotationTarget.*
1919
* To help removing deprecated API gradually, the property [level] could be used.
2020
* Usually a gradual phase-out goes through the "warning", then "error", then "hidden" or "removed" stages:
2121
* - First and by default, [DeprecationLevel.WARNING] is used to notify API consumers, but not to break their compilation or runtime usages.
22+
* You can optionally set the [since] attribute to specify when the deprecation started (e.g., version or date).
2223
* - Then, some time later the deprecation level is raised to [DeprecationLevel.ERROR], so that no new Kotlin code can be compiled
2324
* using the deprecated API.
2425
* - Finally, the API is either removed entirely, or hidden ([DeprecationLevel.HIDDEN]) from code,
@@ -30,13 +31,17 @@ import kotlin.annotation.AnnotationTarget.*
3031
* the deprecated API usage.
3132
* @property level Specifies how the deprecated element usages are reported in code.
3233
* See the [DeprecationLevel] enum for the possible values.
34+
* @property since Specifies the version or date when the API element was marked as deprecated.
35+
* This helps API users track deprecations over time and identify the first point in history
36+
* where the deprecation was introduced.
3337
*/
3438
@Target(CLASS, FUNCTION, PROPERTY, ANNOTATION_CLASS, CONSTRUCTOR, PROPERTY_SETTER, PROPERTY_GETTER, TYPEALIAS)
3539
@MustBeDocumented
3640
public annotation class Deprecated(
3741
val message: String,
3842
val replaceWith: ReplaceWith = ReplaceWith(""),
39-
val level: DeprecationLevel = DeprecationLevel.WARNING
43+
val level: DeprecationLevel = DeprecationLevel.WARNING,
44+
val since: String = "",
4045
)
4146

4247
/**

0 commit comments

Comments
 (0)