| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 pretty_print; | 5 library pretty_print; |
| 6 | 6 |
| 7 import 'utils.dart'; | 7 import 'utils.dart'; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Returns a pretty-printed representation of [object]. | 10 * Returns a pretty-printed representation of [object]. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 singleLine.length + indent <= maxLineLength) && | 41 singleLine.length + indent <= maxLineLength) && |
| 42 !singleLine.contains("\n")) { | 42 !singleLine.contains("\n")) { |
| 43 return singleLine; | 43 return singleLine; |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Otherwise, print each member on its own line. | 46 // Otherwise, print each member on its own line. |
| 47 return "$type[\n" + strings.map((string) { | 47 return "$type[\n" + strings.map((string) { |
| 48 return _indent(indent + 2) + string; | 48 return _indent(indent + 2) + string; |
| 49 }).join(",\n") + "\n" + _indent(indent) + "]"; | 49 }).join(",\n") + "\n" + _indent(indent) + "]"; |
| 50 } else if (object is Map) { | 50 } else if (object is Map) { |
| 51 // TODO(nweiz): This re-assignment is necessary to work around issue |
| 52 // 10721. Remove it when that issue is fixed. |
| 53 var map = object; |
| 54 |
| 51 // Convert the contents of the map to string representations. | 55 // Convert the contents of the map to string representations. |
| 52 var strings = object.keys.map((key) { | 56 var strings = map.keys.map((key) { |
| 53 return '${pp(key)}: ${pp(object[key])}'; | 57 return '${pp(key)}: ${pp(map[key])}'; |
| 54 }).toList(); | 58 }).toList(); |
| 55 | 59 |
| 56 // Truncate the list of strings if it's longer than [maxItems]. | 60 // Truncate the list of strings if it's longer than [maxItems]. |
| 57 if (maxItems != null && strings.length > maxItems) { | 61 if (maxItems != null && strings.length > maxItems) { |
| 58 strings.replaceRange(maxItems - 1, strings.length, ['...']); | 62 strings.replaceRange(maxItems - 1, strings.length, ['...']); |
| 59 } | 63 } |
| 60 | 64 |
| 61 // If the printed string is short and doesn't contain a newline, print it | 65 // If the printed string is short and doesn't contain a newline, print it |
| 62 // as a single line. | 66 // as a single line. |
| 63 var singleLine = "{${strings.join(", ")}}"; | 67 var singleLine = "{${strings.join(", ")}}"; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 93 } else { | 97 } else { |
| 94 return "${typeName(object)}:$value"; | 98 return "${typeName(object)}:$value"; |
| 95 } | 99 } |
| 96 } | 100 } |
| 97 } | 101 } |
| 98 | 102 |
| 99 return _prettyPrint(object, 0, new Set(), true); | 103 return _prettyPrint(object, 0, new Set(), true); |
| 100 } | 104 } |
| 101 | 105 |
| 102 String _indent(int length) => new List.filled(length, ' ').join(''); | 106 String _indent(int length) => new List.filled(length, ' ').join(''); |
| OLD | NEW |