Chromium Code Reviews| 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. | |
| 23 /// | |
| 24 /// Tools, such as the analyzer, can use this to understand whether a block of | |
| 25 /// code "exits". For example: | |
| 26 /// | |
| 27 /// ```dart | |
| 28 /// @alwaysThrows toss() { throw 'Thrown'; } | |
| 29 /// | |
| 30 /// int fn(bool b) { | |
| 31 /// if (b) { | |
| 32 /// return 0; | |
| 33 /// } else { | |
| 34 /// toss(); | |
| 35 /// print("Hello."); | |
| 36 /// } | |
| 37 /// } | |
| 38 /// ``` | |
| 39 /// | |
| 40 /// Without the annotation on `toss`, it would look as though `fn` doesn't | |
| 41 /// always return a / value. The annotation shows that `fn` does always exit. In | |
|
Brian Wilkerson
2016/07/21 15:39:25
Not sure why there's a slash on either this line o
| |
| 42 /// addition, the / annotation reveals that any statements following a call to | |
| 43 /// `toss` (like the `print` call) are dead code. | |
| 44 const _AlwaysThrows alwaysThrows = const _AlwaysThrows(); | |
|
Brian Wilkerson
2016/07/21 15:39:25
There are two ways in which this annotation can ad
| |
| 45 | |
| 21 /// Used to annotate an instance or static method `m`. Indicates that `m` must | 46 /// Used to annotate an instance or static method `m`. Indicates that `m` must |
| 22 /// either be abstract or must return a newly allocated object or `null`. In | 47 /// either be abstract or must return a newly allocated object or `null`. In |
| 23 /// addition, every method that either implements or overrides `m` is implicitly | 48 /// addition, every method that either implements or overrides `m` is implicitly |
| 24 /// annotated with this same annotation. | 49 /// annotated with this same annotation. |
| 25 /// | 50 /// |
| 26 /// Tools, such as the analyzer, can provide feedback if | 51 /// Tools, such as the analyzer, can provide feedback if |
| 27 /// | 52 /// |
| 28 /// * the annotation is associated with anything other than a method, or | 53 /// * the annotation is associated with anything other than a method, or |
| 29 /// * the annotation is associated with a method that has this annotation that | 54 /// * the annotation is associated with a method that has this annotation that |
| 30 /// can return anything other than a newly allocated object or `null`. | 55 /// can return anything other than a newly allocated object or `null`. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 /// @Required('Buttons must do something when pressed') | 134 /// @Required('Buttons must do something when pressed') |
| 110 /// Function onPressed, | 135 /// Function onPressed, |
| 111 /// ... | 136 /// ... |
| 112 /// }) ... | 137 /// }) ... |
| 113 final String reason; | 138 final String reason; |
| 114 | 139 |
| 115 /// Initialize a newly created instance to have the given [reason]. | 140 /// Initialize a newly created instance to have the given [reason]. |
| 116 const Required([this.reason]); | 141 const Required([this.reason]); |
| 117 } | 142 } |
| 118 | 143 |
| 144 class _AlwaysThrows { | |
| 145 const _AlwaysThrows(); | |
| 146 } | |
| 147 | |
| 119 class _Factory { | 148 class _Factory { |
| 120 const _Factory(); | 149 const _Factory(); |
| 121 } | 150 } |
| 122 | 151 |
| 123 class _Literal { | 152 class _Literal { |
| 124 const _Literal(); | 153 const _Literal(); |
| 125 } | 154 } |
| 126 | 155 |
| 127 class _MustCallSuper { | 156 class _MustCallSuper { |
| 128 const _MustCallSuper(); | 157 const _MustCallSuper(); |
| 129 } | 158 } |
| 130 | 159 |
| 131 class _OptionalTypeArgs { | 160 class _OptionalTypeArgs { |
| 132 const _OptionalTypeArgs(); | 161 const _OptionalTypeArgs(); |
| 133 } | 162 } |
| 134 | 163 |
| 135 class _Protected { | 164 class _Protected { |
| 136 const _Protected(); | 165 const _Protected(); |
| 137 } | 166 } |
| OLD | NEW |