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

Unified Diff: lib/core/errors.dart

Issue 10909166: Rename NoSuchMethodException to NoSuchMethodError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/lib/native_helper.dart ('k') | lib/core/exceptions.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/core/errors.dart
diff --git a/lib/core/errors.dart b/lib/core/errors.dart
index 6890f050077e0d12d478d7fd08e8e5280ec0c01a..357a930c5e5a2b58e363ac7712b7457a5009f27c 100644
--- a/lib/core/errors.dart
+++ b/lib/core/errors.dart
@@ -22,3 +22,61 @@ 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;
+
+ /**
+ * Create a [NoSuchMethodError] corresponding to a failed method call.
+ *
+ * The first parameter is the receiver of the method call.
+ * The second parameter is the name of the called method.
+ * The third parameter is the positional arguments that the method was
+ * called with.
+ * The optional [exisitingArgumentNames] is the expected parameters of a
+ * method with the same name on the receiver, if available. This is
+ * the method that would have been called if the parameters had matched.
+ *
+ * TODO(lrn): This will be rewritten to use mirrors when they are available.
+ */
+ const NoSuchMethodError(Object this._receiver,
+ 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)";
+ }
+ }
+}
« no previous file with comments | « lib/compiler/implementation/lib/native_helper.dart ('k') | lib/core/exceptions.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698