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

Side by Side Diff: pkg/stack_trace/lib/src/trace.dart

Issue 180223005: Add Chain.foldFrames to pkg/stack_trace. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 9 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 | « pkg/stack_trace/lib/src/chain.dart ('k') | pkg/stack_trace/pubspec.yaml » ('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) 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 trace; 5 library trace;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'chain.dart'; 10 import 'chain.dart';
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 })); 222 }));
223 } 223 }
224 224
225 /// Returns a new [Trace] based on [this] where multiple stack frames matching 225 /// Returns a new [Trace] based on [this] where multiple stack frames matching
226 /// [predicate] are folded together. This means that whenever there are 226 /// [predicate] are folded together. This means that whenever there are
227 /// multiple frames in a row that match [predicate], only the last one is 227 /// multiple frames in a row that match [predicate], only the last one is
228 /// kept. 228 /// kept.
229 /// 229 ///
230 /// This is useful for limiting the amount of library code that appears in a 230 /// This is useful for limiting the amount of library code that appears in a
231 /// stack trace by only showing user code and code that's called by user code. 231 /// stack trace by only showing user code and code that's called by user code.
232 Trace foldFrames(bool predicate(frame)) { 232 Trace foldFrames(bool predicate(Frame frame)) {
233 var newFrames = <Frame>[]; 233 var newFrames = <Frame>[];
234 for (var frame in frames.reversed) { 234 for (var frame in frames.reversed) {
235 if (!predicate(frame)) { 235 if (!predicate(frame)) {
236 newFrames.add(frame); 236 newFrames.add(frame);
237 } else if (newFrames.isEmpty || !predicate(newFrames.last)) { 237 } else if (newFrames.isEmpty || !predicate(newFrames.last)) {
238 newFrames.add(new Frame( 238 newFrames.add(new Frame(
239 frame.uri, frame.line, frame.column, frame.member)); 239 frame.uri, frame.line, frame.column, frame.member));
240 } 240 }
241 } 241 }
242 242
243 return new Trace(newFrames.reversed); 243 return new Trace(newFrames.reversed);
244 } 244 }
245 245
246 /// Returns a human-readable string representation of [this]. 246 /// Returns a human-readable string representation of [this].
247 String toString() { 247 String toString() {
248 // Figure out the longest path so we know how much to pad. 248 // Figure out the longest path so we know how much to pad.
249 var longest = frames.map((frame) => frame.location.length) 249 var longest = frames.map((frame) => frame.location.length)
250 .fold(0, math.max); 250 .fold(0, math.max);
251 251
252 // Print out the stack trace nicely formatted. 252 // Print out the stack trace nicely formatted.
253 return frames.map((frame) { 253 return frames.map((frame) {
254 return '${padRight(frame.location, longest)} ${frame.member}\n'; 254 return '${padRight(frame.location, longest)} ${frame.member}\n';
255 }).join(); 255 }).join();
256 } 256 }
257 } 257 }
OLDNEW
« no previous file with comments | « pkg/stack_trace/lib/src/chain.dart ('k') | pkg/stack_trace/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698