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

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

Issue 1419953002: Fix the error message widget (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Rebase Created 5 years, 1 month 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/server/server.dart ('k') | no next file » | 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 /// Summary of error messages produced by a `SummaryReporter`. 5 /// Summary of error messages produced by a `SummaryReporter`.
6 library dev_compiler.src.summary; 6 library dev_compiler.src.summary;
7 7
8 import 'dart:collection' show HashSet; 8 import 'dart:collection' show HashSet;
9 9
10 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
11 import 'package:analyzer/src/generated/source.dart' show Source;
12 import 'package:source_span/source_span.dart'; 10 import 'package:source_span/source_span.dart';
13 11
14 /// Summary information computed by the DDC checker. 12 /// Summary information computed by the DDC checker.
15 abstract class Summary { 13 abstract class Summary {
16 Map toJsonMap(); 14 Map toJsonMap();
17 15
18 void accept(SummaryVisitor visitor); 16 void accept(SummaryVisitor visitor);
19 } 17 }
20 18
21 /// Summary for the entire program. 19 /// Summary for the entire program.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 114
117 /// Total lines of code (including all parts of the library). 115 /// Total lines of code (including all parts of the library).
118 int get lines => _lines; 116 int get lines => _lines;
119 117
120 Map toJsonMap() => { 118 Map toJsonMap() => {
121 'library_name': name, 119 'library_name': name,
122 'messages': messages.map((m) => m.toJsonMap()).toList(), 120 'messages': messages.map((m) => m.toJsonMap()).toList(),
123 'lines': lines, 121 'lines': lines,
124 }; 122 };
125 123
126 void countSourceLines(AnalysisContext context, Source source) { 124 void recordSourceLines(Uri uri, int computeLines()) {
127 if (_uris.add(source.uri)) { 125 if (_uris.add(uri)) {
128 // TODO(jmesserly): parsing is serious overkill for this. 126 _lines += computeLines();
129 // Should be cached, but still.
130 // On the other hand, if we are going to parse, we could get a much better
131 // source lines of code estimate by excluding things like comments,
132 // blank lines, and closing braces.
133 var unit = context.parseCompilationUnit(source);
134 _lines += unit.lineInfo.getLocation(unit.endToken.end).lineNumber;
135 } 127 }
136 } 128 }
137 129
138 void accept(SummaryVisitor visitor) => visitor.visitLibrary(this); 130 void accept(SummaryVisitor visitor) => visitor.visitLibrary(this);
139 131
140 static LibrarySummary parse(Map json) => 132 static LibrarySummary parse(Map json) =>
141 new LibrarySummary(json['library_name'], 133 new LibrarySummary(json['library_name'],
142 messages: json['messages'].map(MessageSummary.parse).toList(), 134 messages: new List<MessageSummary>.from(
135 json['messages'].map(MessageSummary.parse)),
143 lines: json['lines']); 136 lines: json['lines']);
144 } 137 }
145 138
146 /// A summary at the level of an HTML file. 139 /// A summary at the level of an HTML file.
147 class HtmlSummary implements IndividualSummary { 140 class HtmlSummary implements IndividualSummary {
148 /// Unique name used to identify the HTML file. 141 /// Unique name used to identify the HTML file.
149 final String name; 142 final String name;
150 143
151 /// All messages collected on the file. 144 /// All messages collected on the file.
152 final List<MessageSummary> messages; 145 final List<MessageSummary> messages;
153 146
154 HtmlSummary(this.name, [List<MessageSummary> messages]) 147 HtmlSummary(this.name, [List<MessageSummary> messages])
155 : messages = messages == null ? <MessageSummary>[] : messages; 148 : messages = messages == null ? <MessageSummary>[] : messages;
156 149
157 Map toJsonMap() => 150 Map toJsonMap() =>
158 {'name': name, 'messages': messages.map((m) => m.toJsonMap()).toList()}; 151 {'name': name, 'messages': messages.map((m) => m.toJsonMap()).toList()};
159 152
160 void accept(SummaryVisitor visitor) => visitor.visitHtml(this); 153 void accept(SummaryVisitor visitor) => visitor.visitHtml(this);
161 154
162 static HtmlSummary parse(Map json) => new HtmlSummary( 155 static HtmlSummary parse(Map json) => new HtmlSummary(
163 json['name'], json['messages'].map(MessageSummary.parse).toList()); 156 json['name'],
157 new List<MessageSummary>.from(
158 json['messages'].map(MessageSummary.parse)));
164 } 159 }
165 160
166 /// A single message produced by the checker. 161 /// A single message produced by the checker.
167 class MessageSummary implements Summary { 162 class MessageSummary implements Summary {
168 /// The kind of message, currently the name of the StaticInfo type. 163 /// The kind of message, currently the name of the StaticInfo type.
169 final String kind; 164 final String kind;
170 165
171 /// Level (error, warning, etc). 166 /// Level (error, warning, etc).
172 final String level; 167 final String level;
173 168
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 239 }
245 240
246 void visitHtml(HtmlSummary html) { 241 void visitHtml(HtmlSummary html) {
247 for (var msg in html.messages) { 242 for (var msg in html.messages) {
248 msg.accept(this); 243 msg.accept(this);
249 } 244 }
250 } 245 }
251 246
252 void visitMessage(MessageSummary message) {} 247 void visitMessage(MessageSummary message) {}
253 } 248 }
OLDNEW
« no previous file with comments | « lib/src/server/server.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698