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

Side by Side Diff: analyzer/lib/src/error.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 | « analyzer/lib/src/context/context.dart ('k') | analyzer/lib/src/generated/ast.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 library error;
5
6 import 'dart:collection';
7
8 import 'generated/error.dart';
9
10 /// The maximum line length when printing extracted source code when converting
11 /// an [AnalyzerError] to a string.
12 final _MAX_ERROR_LINE_LENGTH = 120;
13
14 /// A wrapper around [AnalysisError] that provides a more user-friendly string
15 /// representation.
16 class AnalyzerError implements Exception {
17 final AnalysisError error;
18
19 AnalyzerError(this.error);
20
21 String get message => toString();
22
23 String toString() {
24 var builder = new StringBuffer();
25
26 // Print a less friendly string representation to ensure that
27 // error.source.contents is not executed, as .contents it isn't async
28 builder.write("Error in ${error.source.shortName}: ${error.message}");
29
30 // var content = error.source.contents.data;
31 // var beforeError = content.substring(0, error.offset);
32 // var lineNumber = "\n".allMatches(beforeError).length + 1;
33 // builder.writeln("Error on line $lineNumber of ${error.source.fullName}: "
34 // "${error.message}");
35
36 // var errorLineIndex = beforeError.lastIndexOf("\n") + 1;
37 // var errorEndOfLineIndex = content.indexOf("\n", error.offset);
38 // if (errorEndOfLineIndex == -1) errorEndOfLineIndex = content.length;
39 // var errorLine = content.substring(
40 // errorLineIndex, errorEndOfLineIndex);
41 // var errorColumn = error.offset - errorLineIndex;
42 // var errorLength = error.length;
43 //
44 // // Ensure that the error line we display isn't too long.
45 // if (errorLine.length > _MAX_ERROR_LINE_LENGTH) {
46 // var leftLength = errorColumn;
47 // var rightLength = errorLine.length - leftLength;
48 // if (leftLength > _MAX_ERROR_LINE_LENGTH ~/ 2 &&
49 // rightLength > _MAX_ERROR_LINE_LENGTH ~/ 2) {
50 // errorLine = "..." + errorLine.substring(
51 // errorColumn - _MAX_ERROR_LINE_LENGTH ~/ 2 + 3,
52 // errorColumn + _MAX_ERROR_LINE_LENGTH ~/ 2 - 3)
53 // + "...";
54 // errorColumn = _MAX_ERROR_LINE_LENGTH ~/ 2;
55 // } else if (rightLength > _MAX_ERROR_LINE_LENGTH ~/ 2) {
56 // errorLine = errorLine.substring(0, _MAX_ERROR_LINE_LENGTH - 3) + "..." ;
57 // } else {
58 // assert(leftLength > _MAX_ERROR_LINE_LENGTH ~/ 2);
59 // errorColumn -= errorLine.length - _MAX_ERROR_LINE_LENGTH;
60 // errorLine = "..." + errorLine.substring(
61 // errorLine.length - _MAX_ERROR_LINE_LENGTH + 3, errorLine.length);
62 // }
63 // errorLength = math.min(errorLength, _MAX_ERROR_LINE_LENGTH - errorColumn );
64 // }
65 // builder.writeln(errorLine);
66 //
67 // for (var i = 0; i < errorColumn; i++) builder.write(" ");
68 // for (var i = 0; i < errorLength; i++) builder.write("^");
69 builder.writeln();
70
71 return builder.toString();
72 }
73 }
74
75 /// An error class that collects multiple [AnalyzerError]s that are emitted
76 /// during a single analysis.
77 class AnalyzerErrorGroup implements Exception {
78 final List<AnalyzerError> _errors;
79 AnalyzerErrorGroup(Iterable<AnalyzerError> errors)
80 : _errors = errors.toList();
81
82 /// Creates an [AnalyzerErrorGroup] from a list of lower-level
83 /// [AnalysisError]s.
84 AnalyzerErrorGroup.fromAnalysisErrors(Iterable<AnalysisError> errors)
85 : this(errors.map((e) => new AnalyzerError(e)));
86
87 /// The errors in this collection.
88 List<AnalyzerError> get errors =>
89 new UnmodifiableListView<AnalyzerError>(_errors);
90
91 String get message => toString();
92 String toString() => errors.join("\n");
93 }
OLDNEW
« no previous file with comments | « analyzer/lib/src/context/context.dart ('k') | analyzer/lib/src/generated/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698