Skip to content

Commit d1efd49

Browse files
srawlinsCommit Queue
authored andcommitted
Core libs: Introduce Deprecated.optional, a new annotation.
Also correct a copy/paste error in the Deprecated.new doc comment. Work towards #60504 Change-Id: Iecc60f9909be708597b8571670585cc1b8508afe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451546 Reviewed-by: Lasse Nielsen <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Reviewed-by: Stephen Adams <[email protected]>
1 parent 484c0b8 commit d1efd49

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

sdk/lib/core/annotations.dart

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ class Deprecated {
7474
/// expiration of the annotated feature.
7575
///
7676
/// The [message] is displayed as part of the warning. The message should be
77-
/// aimed at the programmer who owns the extending class, and should
78-
/// recommend an alternative (if available), and say when this functionality
79-
/// is expected to be removed if that is sooner or later than the next major
80-
/// version.
77+
/// aimed at the programmer using the annotated feature, and should recommend
78+
/// an alternative (if available), and say when this feature is expected to
79+
/// be removed if that is sooner or later than the next major version.
8180
const Deprecated(this.message) : _kind = _DeprecationKind.use;
8281

8382
/// Creates an annotation which deprecates implementing a class or mixin.
@@ -187,6 +186,25 @@ class Deprecated {
187186
/// or later than the next major version.
188187
const Deprecated.mixin([this.message]) : _kind = _DeprecationKind.mixin;
189188

189+
/// Creates an annotation which deprecates omitting an argument for the
190+
/// annotated parameter.
191+
///
192+
/// The annotation can be used on optional parameters of methods,
193+
/// constructors, or top-level functions, indicating the parameter will be
194+
/// required in a later release.
195+
///
196+
/// Any call to a function which does not pass a value for the annotated
197+
/// parameter will cause a warning that such omission is deprecated.
198+
///
199+
/// The annotation is not inherited in method overrides.
200+
///
201+
/// The [message], if given, is displayed as part of the warning. The message
202+
/// should be aimed at the programmer who is calling the function with the
203+
/// annotated parameter, and should recommend an alternative (if available),
204+
/// and say when this functionality is expected to be removed if that is
205+
/// sooner or later than the next major version.
206+
const Deprecated.optional([this.message]) : _kind = _DeprecationKind.optional;
207+
190208
String toString() => "Deprecated feature: $message";
191209
}
192210

@@ -201,7 +219,15 @@ const Deprecated deprecated = Deprecated("next release");
201219
///
202220
/// This enum can be private because the information is only intended for
203221
/// static tooling, such as the analyzer. Values may be added.
204-
enum _DeprecationKind { use, implement, extend, subclass, instantiate, mixin }
222+
enum _DeprecationKind {
223+
use,
224+
implement,
225+
extend,
226+
subclass,
227+
instantiate,
228+
mixin,
229+
optional,
230+
}
205231

206232
class _Override {
207233
const _Override();

0 commit comments

Comments
 (0)