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

Side by Side Diff: runtime/lib/errors_patch.dart

Issue 12328019: - Improve the message for NoSuchMethodErrors that are (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/invocation_mirror.h » ('j') | 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) 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 patch class Error { 5 patch class Error {
6 /* patch */ static String _objectToString(Object object) { 6 /* patch */ static String _objectToString(Object object) {
7 return Object._toString(object); 7 return Object._toString(object);
8 } 8 }
9 } 9 }
10 10
11 patch class NoSuchMethodError { 11 patch class NoSuchMethodError {
12 // The compiler emits a call to _throwNew when it cannot resolve a static 12 // The compiler emits a call to _throwNew when it cannot resolve a static
13 // method at compile time. The receiver is actually the literal class of the 13 // method at compile time. The receiver is actually the literal class of the
14 // unresolved method. 14 // unresolved method.
15 static void _throwNew(Object receiver, 15 static void _throwNew(Object receiver,
16 String memberName, 16 String memberName,
17 int invocation_type,
17 List arguments, 18 List arguments,
18 List argumentNames, 19 List argumentNames,
19 List existingArgumentNames) { 20 List existingArgumentNames) {
20 int numNamedArguments = argumentNames == null ? 0 : argumentNames.length; 21 int numNamedArguments = argumentNames == null ? 0 : argumentNames.length;
21 int numPositionalArguments = arguments == null ? 0 : arguments.length; 22 int numPositionalArguments = arguments == null ? 0 : arguments.length;
22 numPositionalArguments -= numNamedArguments; 23 numPositionalArguments -= numNamedArguments;
23 List positionalArguments; 24 List positionalArguments;
24 if (numPositionalArguments == 0) { 25 if (numPositionalArguments == 0) {
25 positionalArguments = []; 26 positionalArguments = [];
26 } else { 27 } else {
27 positionalArguments = arguments.getRange(0, numPositionalArguments); 28 positionalArguments = arguments.getRange(0, numPositionalArguments);
28 } 29 }
29 Map<String, dynamic> namedArguments = new Map<String, dynamic>(); 30 Map<String, dynamic> namedArguments = new Map<String, dynamic>();
30 for (int i = 0; i < numNamedArguments; i++) { 31 for (int i = 0; i < numNamedArguments; i++) {
31 var arg_value = arguments[numPositionalArguments + i]; 32 var arg_value = arguments[numPositionalArguments + i];
32 namedArguments[argumentNames[i]] = arg_value; 33 namedArguments[argumentNames[i]] = arg_value;
33 } 34 }
34 throw new NoSuchMethodError(receiver, 35 throw new NoSuchMethodError._withType(receiver,
35 memberName, 36 memberName,
37 invocation_type,
36 positionalArguments, 38 positionalArguments,
37 namedArguments, 39 namedArguments,
38 existingArgumentNames); 40 existingArgumentNames);
39 } 41 }
40 42
43 final int _invocation_type;
44
41 const NoSuchMethodError(Object this._receiver, 45 const NoSuchMethodError(Object this._receiver,
42 String this._memberName, 46 String this._memberName,
43 List this._arguments, 47 List this._arguments,
44 Map<String,dynamic> this._namedArguments, 48 Map<String,dynamic> this._namedArguments,
45 [List existingArgumentNames = null]) 49 [List existingArgumentNames = null])
50 : this._existingArgumentNames = existingArgumentNames,
51 this._invocation_type = 0;
regis 2013/02/21 00:48:18 What is 0?
Ivan Posva 2013/02/21 18:51:40 Changed to -1 to mark invalid/unknown invocation t
52
53 const NoSuchMethodError._withType(Object this._receiver,
54 String this._memberName,
regis 2013/02/21 00:48:18 indentation
Ivan Posva 2013/02/21 18:51:40 Done.
55 this._invocation_type,
56 List this._arguments,
57 Map<String,dynamic> this._namedArguments,
58 [List existingArgumentNames = null])
46 : this._existingArgumentNames = existingArgumentNames; 59 : this._existingArgumentNames = existingArgumentNames;
47 60
61
62 String _developerMessage() {
63 var type = _invocation_type & _InvocationMirror._TYPE_MASK;
64 var level = (_invocation_type >> _InvocationMirror._CALL_SHIFT) &
65 _InvocationMirror._CALL_MASK;
66 var type_str =
67 (const ["method", "getter", "setter", "getter or setter"])[type];
68 var msg;
69 switch (level) {
70 case _InvocationMirror._DYNAMIC: {
71 if (_receiver == null) {
72 msg = "The null object does not support $type_str '$_memberName'.";
73 } else {
74 msg = "No $type_str '$_memberName' declared in class "
75 "'${_receiver.runtimeType}'.";
76 }
77 break;
78 }
79 case _InvocationMirror._STATIC: {
80 msg = "No static $type_str '$_memberName' declared in class "
81 "'$_receiver'.";
82 break;
83 }
84 case _InvocationMirror._CONSTRUCTOR: {
85 msg = "No constructor '$_memberName' declared in class '$_receiver'.";
86 break;
87 }
88 case _InvocationMirror._TOP_LEVEL: {
89 msg = "No top-level $type_str '$_memberName' declared.";
90 break;
91 }
92 }
93 return msg;
94 }
95
48 /* patch */ String toString() { 96 /* patch */ String toString() {
49 StringBuffer actual_buf = new StringBuffer(); 97 StringBuffer actual_buf = new StringBuffer();
50 int i = 0; 98 int i = 0;
51 if (_arguments != null) { 99 if (_arguments != null) {
52 for (; i < _arguments.length; i++) { 100 for (; i < _arguments.length; i++) {
53 if (i > 0) { 101 if (i > 0) {
54 actual_buf.add(", "); 102 actual_buf.add(", ");
55 } 103 }
56 actual_buf.add(Error.safeToString(_arguments[i])); 104 actual_buf.add(Error.safeToString(_arguments[i]));
57 } 105 }
58 } 106 }
59 if (_namedArguments != null) { 107 if (_namedArguments != null) {
60 _namedArguments.forEach((String key, var value) { 108 _namedArguments.forEach((String key, var value) {
61 if (i > 0) { 109 if (i > 0) {
62 actual_buf.add(", "); 110 actual_buf.add(", ");
63 } 111 }
64 actual_buf.add(key); 112 actual_buf.add(key);
65 actual_buf.add(": "); 113 actual_buf.add(": ");
66 actual_buf.add(Error.safeToString(value)); 114 actual_buf.add(Error.safeToString(value));
67 i++; 115 i++;
68 }); 116 });
69 } 117 }
70 StringBuffer msg_buf = new StringBuffer(); 118 StringBuffer msg_buf = new StringBuffer(_developerMessage());
119 msg_buf.add("\n\n");
71 if (_existingArgumentNames == null) { 120 if (_existingArgumentNames == null) {
72 msg_buf.add( 121 msg_buf.add(
73 "NoSuchMethodError : method not found: '$_memberName'\n" 122 "NoSuchMethodError : method not found: '$_memberName'\n"
74 "Receiver: ${Error.safeToString(_receiver)}\n" 123 "Receiver: ${Error.safeToString(_receiver)}\n"
75 "Arguments: [$actual_buf]"); 124 "Arguments: [$actual_buf]");
76 } else { 125 } else {
77 String actualParameters = actual_buf.toString(); 126 String actualParameters = actual_buf.toString();
78 StringBuffer formal_buf = new StringBuffer(); 127 StringBuffer formal_buf = new StringBuffer();
79 for (int i = 0; i < _existingArgumentNames.length; i++) { 128 for (int i = 0; i < _existingArgumentNames.length; i++) {
80 if (i > 0) { 129 if (i > 0) {
81 formal_buf.add(", "); 130 formal_buf.add(", ");
82 } 131 }
83 formal_buf.add(_existingArgumentNames[i]); 132 formal_buf.add(_existingArgumentNames[i]);
84 } 133 }
85 String formalParameters = formal_buf.toString(); 134 String formalParameters = formal_buf.toString();
86 msg_buf.add( 135 msg_buf.add(
87 "NoSuchMethodError: incorrect number of arguments passed to " 136 "NoSuchMethodError: incorrect number of arguments passed to "
88 "method named '$_memberName'\n" 137 "method named '$_memberName'\n"
89 "Receiver: ${Error.safeToString(_receiver)}\n" 138 "Receiver: ${Error.safeToString(_receiver)}\n"
90 "Tried calling: $_memberName($actualParameters)\n" 139 "Tried calling: $_memberName($actualParameters)\n"
91 "Found: $_memberName($formalParameters)"); 140 "Found: $_memberName($formalParameters)");
92 } 141 }
93 return msg_buf.toString(); 142 return msg_buf.toString();
94 } 143 }
95 } 144 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/invocation_mirror.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698