Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: pkg/meta/lib/meta.dart

Issue 2170643003: Add an alwaysThrows annotation to indicate that a function always throws. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 30 matching lines...) Expand all
41 /// Tools, such as the analyzer, can provide feedback if 41 /// Tools, such as the analyzer, can provide feedback if
42 /// 42 ///
43 /// * the annotation is associated with a declaration that is not part of the 43 /// * the annotation is associated with a declaration that is not part of the
44 /// public interface of a library (such as a local variable or a declaration 44 /// public interface of a library (such as a local variable or a declaration
45 /// that is private) or a directive other than the first directive in the 45 /// that is private) or a directive other than the first directive in the
46 /// library, or 46 /// library, or
47 /// * the declaration is referenced by a package that has not explicitly 47 /// * the declaration is referenced by a package that has not explicitly
48 /// indicated its intention to use experimental APIs (details TBD). 48 /// indicated its intention to use experimental APIs (details TBD).
49 const _Experimental experimental = const _Experimental(); 49 const _Experimental experimental = const _Experimental();
50 50
51 /// Used to annotate a function `f`. Indicates that `f` always throws an
52 /// exception. Any functions that override `f`, in class inheritence, are also
53 /// expected to conform to this contract.
54 ///
55 /// Tools, such as the analyzer, can use this to understand whether a block of
56 /// code "exits". For example:
57 ///
58 /// ```dart
59 /// @alwaysThrows toss() { throw 'Thrown'; }
60 ///
61 /// int fn(bool b) {
62 /// if (b) {
63 /// return 0;
64 /// } else {
65 /// toss();
66 /// print("Hello.");
67 /// }
68 /// }
69 /// ```
70 ///
71 /// Without the annotation on `toss`, it would look as though `fn` doesn't
72 /// always return a / value. The annotation shows that `fn` does always exit. In
73 /// addition, the / annotation reveals that any statements following a call to
Brian Wilkerson 2017/06/13 19:35:19 Please remove the '/'s in the middle of the lines.
srawlins 2017/06/13 19:42:04 Done.
74 /// `toss` (like the `print` call) are dead code.
75 ///
76 /// Tools, such as the analyzer, can also expect this contract to be enforced;
77 /// that is, tools may emit warnings if a function with this annotation
78 /// _doesn't_ always throw.
79 const _AlwaysThrows alwaysThrows = const _AlwaysThrows();
80
51 /// Used to annotate an instance or static method `m`. Indicates that `m` must 81 /// Used to annotate an instance or static method `m`. Indicates that `m` must
52 /// either be abstract or must return a newly allocated object or `null`. In 82 /// either be abstract or must return a newly allocated object or `null`. In
53 /// addition, every method that either implements or overrides `m` is implicitly 83 /// addition, every method that either implements or overrides `m` is implicitly
54 /// annotated with this same annotation. 84 /// annotated with this same annotation.
55 /// 85 ///
56 /// Tools, such as the analyzer, can provide feedback if 86 /// Tools, such as the analyzer, can provide feedback if
57 /// 87 ///
58 /// * the annotation is associated with anything other than a method, or 88 /// * the annotation is associated with anything other than a method, or
59 /// * the annotation is associated with a method that has this annotation that 89 /// * the annotation is associated with a method that has this annotation that
60 /// can return anything other than a newly allocated object or `null`. 90 /// can return anything other than a newly allocated object or `null`.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698