| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Constants for use in metadata annotations. | 5 /// Constants for use in metadata annotations. |
| 6 /// | 6 /// |
| 7 /// See also `@deprecated` and `@override` in the `dart:core` library. | 7 /// See also `@deprecated` and `@override` in the `dart:core` library. |
| 8 /// | 8 /// |
| 9 /// Annotations provide semantic information that tools can use to provide a | 9 /// Annotations provide semantic information that tools can use to provide a |
| 10 /// better user experience. For example, an IDE might not autocomplete the name | 10 /// better user experience. For example, an IDE might not autocomplete the name |
| 11 /// of a function that's been marked `@deprecated`, or it might display the | 11 /// of a function that's been marked `@deprecated`, or it might display the |
| 12 /// function's name differently. | 12 /// function's name differently. |
| 13 /// | 13 /// |
| 14 /// For information on installing and importing this library, see the | 14 /// For information on installing and importing this library, see the |
| 15 /// [meta package on pub.dartlang.org] (http://pub.dartlang.org/packages/meta). | 15 /// [meta package on pub.dartlang.org] (http://pub.dartlang.org/packages/meta). |
| 16 /// For examples of using annotations, see | 16 /// For examples of using annotations, see |
| 17 /// [Metadata](https://www.dartlang.org/docs/dart-up-and-running/ch02.html#metad
ata) | 17 /// [Metadata](https://www.dartlang.org/docs/dart-up-and-running/ch02.html#metad
ata) |
| 18 /// in the language tour. | 18 /// in the language tour. |
| 19 library meta; | 19 library meta; |
| 20 | 20 |
| 21 /// Used to annotate a function `f`. Indicates that `f` always throws an |
| 22 /// exception. Any functions that override `f`, in class inheritence, are also |
| 23 /// expected to conform to this contract. |
| 24 /// |
| 25 /// Tools, such as the analyzer, can use this to understand whether a block of |
| 26 /// code "exits". For example: |
| 27 /// |
| 28 /// ```dart |
| 29 /// @alwaysThrows toss() { throw 'Thrown'; } |
| 30 /// |
| 31 /// int fn(bool b) { |
| 32 /// if (b) { |
| 33 /// return 0; |
| 34 /// } else { |
| 35 /// toss(); |
| 36 /// print("Hello."); |
| 37 /// } |
| 38 /// } |
| 39 /// ``` |
| 40 /// |
| 41 /// Without the annotation on `toss`, it would look as though `fn` doesn't |
| 42 /// always return a value. The annotation shows that `fn` does always exit. In |
| 43 /// addition, the annotation reveals that any statements following a call to |
| 44 /// `toss` (like the `print` call) are dead code. |
| 45 /// |
| 46 /// Tools, such as the analyzer, can also expect this contract to be enforced; |
| 47 /// that is, tools may emit warnings if a function with this annotation |
| 48 /// _doesn't_ always throw. |
| 49 const _AlwaysThrows alwaysThrows = const _AlwaysThrows(); |
| 50 |
| 21 /// Used to annotate a parameter of an instance method that overrides another | 51 /// Used to annotate a parameter of an instance method that overrides another |
| 22 /// method. | 52 /// method. |
| 23 /// | 53 /// |
| 24 /// Indicates that this parameter may have a tighter type than the parameter on | 54 /// Indicates that this parameter may have a tighter type than the parameter on |
| 25 /// its superclass. The actual argument will be checked at runtime to ensure it | 55 /// its superclass. The actual argument will be checked at runtime to ensure it |
| 26 /// is a subtype of the overridden parameter type. | 56 /// is a subtype of the overridden parameter type. |
| 27 const _Checked checked = const _Checked(); | 57 const _Checked checked = const _Checked(); |
| 28 | 58 |
| 29 /// Used to annotate a library, or any declaration that is part of the public | 59 /// Used to annotate a library, or any declaration that is part of the public |
| 30 /// interface of a library (such as top-level members, class members, and | 60 /// interface of a library (such as top-level members, class members, and |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 /// @Required('Buttons must do something when pressed') | 218 /// @Required('Buttons must do something when pressed') |
| 189 /// Function onPressed, | 219 /// Function onPressed, |
| 190 /// ... | 220 /// ... |
| 191 /// }) ... | 221 /// }) ... |
| 192 final String reason; | 222 final String reason; |
| 193 | 223 |
| 194 /// Initialize a newly created instance to have the given [reason]. | 224 /// Initialize a newly created instance to have the given [reason]. |
| 195 const Required([this.reason]); | 225 const Required([this.reason]); |
| 196 } | 226 } |
| 197 | 227 |
| 228 class _AlwaysThrows { |
| 229 const _AlwaysThrows(); |
| 230 } |
| 231 |
| 198 class _Checked { | 232 class _Checked { |
| 199 const _Checked(); | 233 const _Checked(); |
| 200 } | 234 } |
| 201 | 235 |
| 202 class _Experimental { | 236 class _Experimental { |
| 203 const _Experimental(); | 237 const _Experimental(); |
| 204 } | 238 } |
| 205 | 239 |
| 206 class _Factory { | 240 class _Factory { |
| 207 const _Factory(); | 241 const _Factory(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 227 const _Virtual(); | 261 const _Virtual(); |
| 228 } | 262 } |
| 229 | 263 |
| 230 class _VisibleForOverriding { | 264 class _VisibleForOverriding { |
| 231 const _VisibleForOverriding(); | 265 const _VisibleForOverriding(); |
| 232 } | 266 } |
| 233 | 267 |
| 234 class _VisibleForTesting { | 268 class _VisibleForTesting { |
| 235 const _VisibleForTesting(); | 269 const _VisibleForTesting(); |
| 236 } | 270 } |
| OLD | NEW |