| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library dart2js.diagnostics.invariant; | 5 library dart2js.diagnostics.invariant; |
| 6 | 6 |
| 7 import 'spannable.dart'; | 7 import 'spannable.dart'; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * If true, print a warning for each method that was resolved, but not | 10 * If true, print a warning for each method that was resolved, but not |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 /// Throws a [SpannableAssertionFailure]. | 29 /// Throws a [SpannableAssertionFailure]. |
| 30 /// | 30 /// |
| 31 /// Use this method to provide better information for assertion by calling | 31 /// Use this method to provide better information for assertion by calling |
| 32 /// [failedAt] as the second argument to an `assert` statement: | 32 /// [failedAt] as the second argument to an `assert` statement: |
| 33 /// | 33 /// |
| 34 /// assert(condition, failedAt(position, message)); | 34 /// assert(condition, failedAt(position, message)); |
| 35 /// | 35 /// |
| 36 /// [spannable] must be non-null and will be used to provide positional | 36 /// [spannable] must be non-null and will be used to provide positional |
| 37 /// information in the generated error message. | 37 /// information in the generated error message. |
| 38 bool failedAt(Spannable spannable, [var message]) { | 38 /// |
| 39 /// This method can also be used to throw a [SpannableAssertionFailure] outside |
| 40 /// an assert: |
| 41 /// |
| 42 /// failedAt(position, message); |
| 43 /// |
| 44 /// or, if the enclosing function requires a result or control flow: |
| 45 /// |
| 46 /// throw failedAt(position, message); |
| 47 /// |
| 48 bool failedAt(Spannable spannable, [String message]) { |
| 39 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 49 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 40 // information on assertion errors. | 50 // information on assertion errors. |
| 41 if (spannable == null) { | 51 if (spannable == null) { |
| 42 throw new SpannableAssertionFailure( | 52 throw new SpannableAssertionFailure(CURRENT_ELEMENT_SPANNABLE, |
| 43 CURRENT_ELEMENT_SPANNABLE, | 53 'Spannable was null for failedAt. Use CURRENT_ELEMENT_SPANNABLE.'); |
| 44 'Spannable was null for failedInvariant. ' | |
| 45 'Use CURRENT_ELEMENT_SPANNABLE.'); | |
| 46 } | |
| 47 if (message is Function) { | |
| 48 message = message(); | |
| 49 } | 54 } |
| 50 throw new SpannableAssertionFailure(spannable, message); | 55 throw new SpannableAssertionFailure(spannable, message); |
| 51 } | 56 } |
| OLD | NEW |