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

Unified Diff: lib/src/compiler/error_helpers.dart

Issue 1879373004: Implement modular compilation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 8 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/element_loader.dart ('k') | lib/src/compiler/extension_types.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/error_helpers.dart
diff --git a/lib/src/report.dart b/lib/src/compiler/error_helpers.dart
similarity index 68%
rename from lib/src/report.dart
rename to lib/src/compiler/error_helpers.dart
index 9d7df27f81f9a2f9974cd4faf1b727ddf18223f8..b0ab067ce8219a65d513ade54f7c9c938e4bf90f 100644
--- a/lib/src/report.dart
+++ b/lib/src/compiler/error_helpers.dart
@@ -1,54 +1,55 @@
-// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'package:analyzer/analyzer.dart'
+ show AnalysisError, ErrorSeverity, StaticWarningCode;
+import 'package:analyzer/source/error_processor.dart' show ErrorProcessor;
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
-import 'package:analyzer/src/generated/error.dart';
-import 'package:logging/logging.dart';
import 'package:path/path.dart' as path;
-import 'package:analyzer/source/error_processor.dart';
-final _checkerLogger = new Logger('dev_compiler.checker');
-
-/// Collects errors, and then sorts them and sends them
-class ErrorCollector implements AnalysisErrorListener {
- final AnalysisContext _context;
- final AnalysisErrorListener listener;
- final List<AnalysisError> _errors = [];
-
- ErrorCollector(this._context, 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 = errorSeverity(_context, error1);
- var severity2 = errorSeverity(_context, 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
- compare = error1.offset - error2.offset;
- if (compare != 0) return compare;
-
- // compare message, in worst case.
- return error1.message.compareTo(error2.message);
- });
-
- _errors.forEach(listener.onError);
- _errors.clear();
- }
+// TODO(jmesserly): this code was taken from analyzer_cli.
+// It really should be in some common place so we can share it.
+// TODO(jmesserly): this shouldn't depend on `context` but we need it to compute
+// `errorSeverity` due to some APIs that need fixing.
+void sortErrors(AnalysisContext context, List<AnalysisError> errors) {
+ errors.sort((AnalysisError error1, AnalysisError error2) {
+ // severity
+ var severity1 = errorSeverity(context, error1);
+ var severity2 = errorSeverity(context, 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
+ compare = error1.offset - error2.offset;
+ if (compare != 0) return compare;
+
+ // compare message, in worst case.
+ return error1.message.compareTo(error2.message);
+ });
+}
- void onError(AnalysisError error) {
- _errors.add(error);
- }
+// TODO(jmesserly): this was from analyzer_cli, we should factor it differently.
+String formatError(AnalysisContext context, AnalysisError error) {
+ var severity = errorSeverity(context, error);
+ // Skip hints, some like TODOs are not useful.
+ if (severity.ordinal <= ErrorSeverity.INFO.ordinal) return null;
+
+ var lineInfo = context.computeLineInfo(error.source);
+ var location = lineInfo.getLocation(error.offset);
+
+ // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2)
+ return (new StringBuffer()
+ ..write('[${severity.displayName}] ')
+ ..write(error.message)
+ ..write(' (${path.prettyUri(error.source.uri)}')
+ ..write(', line ${location.lineNumber}, col ${location.columnNumber})'))
+ .toString();
}
ErrorSeverity errorSeverity(AnalysisContext context, AnalysisError error) {
@@ -180,37 +181,3 @@ ErrorSeverity errorSeverity(AnalysisContext context, AnalysisError error) {
return ErrorProcessor.getProcessor(context, error)?.severity ??
error.errorCode.errorSeverity;
}
-
-/// 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});
-
- void onError(AnalysisError error) {
- var level = _severityToLevel[errorSeverity(_context, error)];
-
- // TODO(jmesserly): figure out what to do with the error's name.
- var lineInfo = _context.computeLineInfo(error.source);
- var location = lineInfo.getLocation(error.offset);
-
- // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2)
- var text = new StringBuffer()
- ..write('[${error.errorCode.name}] ')
- ..write(error.message)
- ..write(' (${path.prettyUri(error.source.uri)}')
- ..write(', line ${location.lineNumber}, col ${location.columnNumber})');
-
- // TODO(jmesserly): just print these instead of sending through logger?
- _checkerLogger.log(level, text);
- }
-}
-
-// TODO(jmesserly): remove log levels, instead just use severity.
-const _severityToLevel = const {
- ErrorSeverity.ERROR: Level.SEVERE,
- ErrorSeverity.WARNING: Level.WARNING,
- ErrorSeverity.INFO: Level.INFO
-};
« no previous file with comments | « lib/src/compiler/element_loader.dart ('k') | lib/src/compiler/extension_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698