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

Side by Side Diff: lib/src/report.dart

Issue 1299993004: sort errors so they appear in stable order (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: fix html messages Created 5 years, 4 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
« no previous file with comments | « lib/src/compiler.dart ('k') | test/codegen/expect/js_test.txt » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// Summarizes the information produced by the checker. 5 /// Summarizes the information produced by the checker.
6 library dev_compiler.src.report; 6 library dev_compiler.src.report;
7 7
8 import 'dart:math' show max; 8 import 'dart:math' show max;
9 9
10 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; 10 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
11 import 'package:analyzer/src/generated/error.dart'; 11 import 'package:analyzer/src/generated/error.dart';
12 import 'package:logging/logging.dart'; 12 import 'package:logging/logging.dart';
13 import 'package:path/path.dart' as path; 13 import 'package:path/path.dart' as path;
14 import 'package:source_span/source_span.dart'; 14 import 'package:source_span/source_span.dart';
15 15
16 import 'utils.dart'; 16 import 'utils.dart';
17 import 'summary.dart'; 17 import 'summary.dart';
18 18
19 final _checkerLogger = new Logger('dev_compiler.checker'); 19 final _checkerLogger = new Logger('dev_compiler.checker');
20 20
21 /// Collects errors, and then sorts them and sends them
22 class ErrorCollector implements AnalysisErrorListener {
23 final AnalysisErrorListener listener;
24 final List<AnalysisError> _errors = [];
25
26 ErrorCollector(this.listener);
27
28 /// Flushes errors to the log. Until this is called, errors are buffered.
29 void flush() {
30 // TODO(jmesserly): this code was taken from analyzer_cli.
31 // sort errors
32 _errors.sort((AnalysisError error1, AnalysisError error2) {
33 // severity
34 var severity1 = _strongModeErrorSeverity(error1);
35 var severity2 = _strongModeErrorSeverity(error2);
36 int compare = severity2.compareTo(severity1);
37 if (compare != 0) {
38 return compare;
39 }
40 // path
41 compare = Comparable.compare(error1.source.fullName.toLowerCase(),
42 error2.source.fullName.toLowerCase());
43 if (compare != 0) {
44 return compare;
45 }
46 // offset
47 return error1.offset - error2.offset;
48 });
49
50 _errors.forEach(listener.onError);
51 _errors.clear();
52 }
53
54 void onError(AnalysisError error) {
55 _errors.add(error);
56 }
57 }
58
59 ErrorSeverity _strongModeErrorSeverity(AnalysisError error) {
60 // Upgrade analyzer warnings to errors.
61 // TODO(jmesserly: reconcile this with analyzer_cli
62 var severity = error.errorCode.errorSeverity;
63 if (!error.errorCode.name.startsWith('dev_compiler.') &&
64 severity == ErrorSeverity.WARNING) {
65 return ErrorSeverity.ERROR;
66 }
67 return severity;
68 }
69
21 /// Simple reporter that logs checker messages as they are seen. 70 /// Simple reporter that logs checker messages as they are seen.
22 class LogReporter implements AnalysisErrorListener { 71 class LogReporter implements AnalysisErrorListener {
23 final AnalysisContext _context; 72 final AnalysisContext _context;
24 final bool useColors; 73 final bool useColors;
74 final List<AnalysisError> _errors = [];
25 75
26 LogReporter(this._context, {this.useColors: false}); 76 LogReporter(this._context, {this.useColors: false});
27 77
28 // TODO(jmesserly): these messages seem to come out in a different order if
29 // a new message gets added or removed. We may want to collect them and sort,
30 // like analyzer_cli does.
31 void onError(AnalysisError error) { 78 void onError(AnalysisError error) {
32 var level = _severityToLevel[error.errorCode.errorSeverity]; 79 var level = _severityToLevel[_strongModeErrorSeverity(error)];
33
34 // Upgrade analyzer warnings to errors.
35 // TODO(jmesserly: reconcile this with analyzer_cli
36 if (!error.errorCode.name.startsWith('dev_compiler.') &&
37 level == Level.WARNING) {
38 level = Level.SEVERE;
39 }
40 80
41 // TODO(jmesserly): figure out what to do with the error's name. 81 // TODO(jmesserly): figure out what to do with the error's name.
42 var lineInfo = _context.computeLineInfo(error.source); 82 var lineInfo = _context.computeLineInfo(error.source);
43 var location = lineInfo.getLocation(error.offset); 83 var location = lineInfo.getLocation(error.offset);
44 84
45 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2) 85 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2)
46 var text = new StringBuffer() 86 var text = new StringBuffer()
47 ..write('[${errorCodeName(error.errorCode)}] ') 87 ..write('[${errorCodeName(error.errorCode)}] ')
48 ..write(error.message) 88 ..write(error.message)
49 ..write(' (${path.prettyUri(error.source.uri)}') 89 ..write(' (${path.prettyUri(error.source.uri)}')
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 351
312 visitMessage(MessageSummary message) { 352 visitMessage(MessageSummary message) {
313 var kind = message.kind; 353 var kind = message.kind;
314 errorCount.putIfAbsent(currentPackage, () => <String, int>{}); 354 errorCount.putIfAbsent(currentPackage, () => <String, int>{});
315 errorCount[currentPackage].putIfAbsent(kind, () => 0); 355 errorCount[currentPackage].putIfAbsent(kind, () => 0);
316 errorCount[currentPackage][kind]++; 356 errorCount[currentPackage][kind]++;
317 totals.putIfAbsent(kind, () => 0); 357 totals.putIfAbsent(kind, () => 0);
318 totals[kind]++; 358 totals[kind]++;
319 } 359 }
320 } 360 }
OLDNEW
« no previous file with comments | « lib/src/compiler.dart ('k') | test/codegen/expect/js_test.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698