Chromium Code Reviews| Index: lib/core/errors.dart |
| diff --git a/lib/core/errors.dart b/lib/core/errors.dart |
| index 6890f050077e0d12d478d7fd08e8e5280ec0c01a..5a72adcca017b3df445a51def4d116a91a4e5835 100644 |
| --- a/lib/core/errors.dart |
| +++ b/lib/core/errors.dart |
| @@ -22,3 +22,48 @@ class FallThroughError implements Error { |
| class AbstractClassInstantiationError { |
| } |
| + |
| +/** |
| + * Error thrown by the default implementation of [:noSuchMethod:] on [Object]. |
| + */ |
| +class NoSuchMethodError implements Error { |
| + final Object _receiver; |
| + final String _functionName; |
| + final List _arguments; |
| + final List _existingArgumentNames; |
| + |
| + const NoSuchMethodError(Object this._receiver, |
|
Johnni Winther
2012/09/11 08:41:38
Please add dartdoc to explain usage. In particular
Lasse Reichstein Nielsen
2012/09/11 11:35:41
Done.
|
| + String this._functionName, |
| + List this._arguments, |
| + [List existingArgumentNames = null]) |
| + : this._existingArgumentNames = existingArgumentNames; |
| + |
| + String toString() { |
| + StringBuffer sb = new StringBuffer(); |
| + for (int i = 0; i < _arguments.length; i++) { |
| + if (i > 0) { |
| + sb.add(", "); |
| + } |
| + sb.add(_arguments[i]); |
| + } |
| + if (_existingArgumentNames === null) { |
| + return "NoSuchMethodError : method not found: '$_functionName'\n" |
| + "Receiver: $_receiver\n" |
| + "Arguments: [$sb]"; |
| + } else { |
| + String actualParameters = sb.toString(); |
| + sb = new StringBuffer(); |
| + for (int i = 0; i < _existingArgumentNames.length; i++) { |
| + if (i > 0) { |
| + sb.add(", "); |
| + } |
| + sb.add(_existingArgumentNames[i]); |
| + } |
| + String formalParameters = sb.toString(); |
| + return "NoSuchMethodError: incorrect number of arguments passed to " |
| + "method named '$_functionName'\nReceiver: $_receiver\n" |
| + "Tried calling: $_functionName($actualParameters)\n" |
| + "Found: $_functionName($formalParameters)"; |
| + } |
| + } |
| +} |