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 command_line_config; | 5 library command_line_config; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import '../../../pkg/path/lib/path.dart' as path; | 9 import '../../../pkg/path/lib/path.dart' as path; |
10 import '../../../pkg/unittest/lib/unittest.dart'; | 10 import '../../../pkg/unittest/lib/unittest.dart'; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // Parse out each stack entry. | 76 // Parse out each stack entry. |
77 var stack = []; | 77 var stack = []; |
78 for (var line in stackTrace.split('\n')) { | 78 for (var line in stackTrace.split('\n')) { |
79 if (line.trim() == '') continue; | 79 if (line.trim() == '') continue; |
80 stack.add(new _StackFrame(line)); | 80 stack.add(new _StackFrame(line)); |
81 } | 81 } |
82 | 82 |
83 if (stack.length == 0) return; | 83 if (stack.length == 0) return; |
84 | 84 |
85 // Figure out the longest path so we know how much to pad. | 85 // Figure out the longest path so we know how much to pad. |
86 int longest = stack.mappedBy((frame) => frame.location.length).max(); | 86 int longest = stack.map((frame) => frame.location.length).max(); |
87 | 87 |
88 // Print out the stack trace nicely formatted. | 88 // Print out the stack trace nicely formatted. |
89 for (var frame in stack) { | 89 for (var frame in stack) { |
90 print(' ${_padLeft(frame.location, longest)} ${frame.member}'); | 90 print(' ${_padLeft(frame.location, longest)} ${frame.member}'); |
91 } | 91 } |
92 | 92 |
93 print(''); | 93 print(''); |
94 } | 94 } |
95 | 95 |
96 String _padLeft(String string, int length) { | 96 String _padLeft(String string, int length) { |
97 if (string.length >= length) return string; | 97 if (string.length >= length) return string; |
98 | 98 |
99 var result = new StringBuffer(); | 99 var result = new StringBuffer(); |
100 result.add(string); | 100 result.add(string); |
101 for (var i = 0; i < length - string.length; i++) { | 101 for (var i = 0; i < length - string.length; i++) { |
102 result.add(' '); | 102 result.add(' '); |
103 } | 103 } |
104 | 104 |
105 return result.toString(); | 105 return result.toString(); |
106 } | 106 } |
107 | 107 |
108 String _indent(String str) { | 108 String _indent(String str) { |
109 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. | 109 // TODO(nweiz): Use this simpler code once issue 2980 is fixed. |
110 // return str.replaceAll(new RegExp("^", multiLine: true), " "); | 110 // return str.replaceAll(new RegExp("^", multiLine: true), " "); |
111 return Strings.join(str.split("\n").mappedBy((line) => " $line"), "\n"); | 111 return Strings.join(str.split("\n").map((line) => " $line"), "\n"); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 class _StackFrame { | 115 class _StackFrame { |
116 static final fileRegExp = new RegExp( | 116 static final fileRegExp = new RegExp( |
117 r'#\d+\s+(.*) \(file://(/.+):(\d+):(\d+)\)'); | 117 r'#\d+\s+(.*) \(file://(/.+):(\d+):(\d+)\)'); |
118 static final coreRegExp = new RegExp(r'#\d+\s+(.*) \((.+):(\d+):(\d+)\)'); | 118 static final coreRegExp = new RegExp(r'#\d+\s+(.*) \((.+):(\d+):(\d+)\)'); |
119 | 119 |
120 /// If `true`, then this stack frame is for a library built into Dart and | 120 /// If `true`, then this stack frame is for a library built into Dart and |
121 /// not a regular file path. | 121 /// not a regular file path. |
(...skipping 29 matching lines...) Expand all Loading... |
151 var library = match[2]; | 151 var library = match[2]; |
152 if (!isCore) { | 152 if (!isCore) { |
153 // Make the library path relative to the entrypoint. | 153 // Make the library path relative to the entrypoint. |
154 library = path.relative(library); | 154 library = path.relative(library); |
155 } | 155 } |
156 | 156 |
157 var member = match[1].replaceAll("<anonymous closure>", _LAMBDA); | 157 var member = match[1].replaceAll("<anonymous closure>", _LAMBDA); |
158 return new _StackFrame._(isCore, library, match[3], match[4], member); | 158 return new _StackFrame._(isCore, library, match[3], match[4], member); |
159 } | 159 } |
160 } | 160 } |
OLD | NEW |