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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/compiler.dart ('k') | test/codegen/expect/js_test.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/report.dart
diff --git a/lib/src/report.dart b/lib/src/report.dart
index d7cc1ae8f74e41935d20138dbfa447a41880edab..7448158108ca43b81d417392fd1a4a8204f0aa61 100644
--- a/lib/src/report.dart
+++ b/lib/src/report.dart
@@ -18,25 +18,65 @@ import 'summary.dart';
final _checkerLogger = new Logger('dev_compiler.checker');
+/// Collects errors, and then sorts them and sends them
+class ErrorCollector implements AnalysisErrorListener {
+ final AnalysisErrorListener listener;
+ final List<AnalysisError> _errors = [];
+
+ ErrorCollector(this.listener);
+
+ /// Flushes errors to the log. Until this is called, errors are buffered.
+ void flush() {
+ // TODO(jmesserly): this code was taken from analyzer_cli.
+ // sort errors
+ _errors.sort((AnalysisError error1, AnalysisError error2) {
+ // severity
+ var severity1 = _strongModeErrorSeverity(error1);
+ var severity2 = _strongModeErrorSeverity(error2);
+ int compare = severity2.compareTo(severity1);
+ if (compare != 0) {
+ return compare;
+ }
+ // path
+ compare = Comparable.compare(error1.source.fullName.toLowerCase(),
+ error2.source.fullName.toLowerCase());
+ if (compare != 0) {
+ return compare;
+ }
+ // offset
+ return error1.offset - error2.offset;
+ });
+
+ _errors.forEach(listener.onError);
+ _errors.clear();
+ }
+
+ void onError(AnalysisError error) {
+ _errors.add(error);
+ }
+}
+
+ErrorSeverity _strongModeErrorSeverity(AnalysisError error) {
+ // Upgrade analyzer warnings to errors.
+ // TODO(jmesserly: reconcile this with analyzer_cli
+ var severity = error.errorCode.errorSeverity;
+ if (!error.errorCode.name.startsWith('dev_compiler.') &&
+ severity == ErrorSeverity.WARNING) {
+ return ErrorSeverity.ERROR;
+ }
+ return severity;
+}
+
/// Simple reporter that logs checker messages as they are seen.
class LogReporter implements AnalysisErrorListener {
final AnalysisContext _context;
final bool useColors;
+ final List<AnalysisError> _errors = [];
LogReporter(this._context, {this.useColors: false});
- // TODO(jmesserly): these messages seem to come out in a different order if
- // a new message gets added or removed. We may want to collect them and sort,
- // like analyzer_cli does.
void onError(AnalysisError error) {
- var level = _severityToLevel[error.errorCode.errorSeverity];
-
- // Upgrade analyzer warnings to errors.
- // TODO(jmesserly: reconcile this with analyzer_cli
- if (!error.errorCode.name.startsWith('dev_compiler.') &&
- level == Level.WARNING) {
- level = Level.SEVERE;
- }
+ var level = _severityToLevel[_strongModeErrorSeverity(error)];
// TODO(jmesserly): figure out what to do with the error's name.
var lineInfo = _context.computeLineInfo(error.source);
« 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