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

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: 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;
vsm 2015/10/21 22:37:09 This file is used by the widget, so need to minimi
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 // TODO(jmesserly): parsing is serious overkill for this.
129 // Should be cached, but still. 127 // Should be cached, but still.
130 // On the other hand, if we are going to parse, we could get a much better 128 // 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, 129 // source lines of code estimate by excluding things like comments,
132 // blank lines, and closing braces. 130 // blank lines, and closing braces.
133 var unit = context.parseCompilationUnit(source); 131 _lines += computeLines();
134 _lines += unit.lineInfo.getLocation(unit.endToken.end).lineNumber;
135 } 132 }
136 } 133 }
137 134
138 void accept(SummaryVisitor visitor) => visitor.visitLibrary(this); 135 void accept(SummaryVisitor visitor) => visitor.visitLibrary(this);
139 136
140 static LibrarySummary parse(Map json) => 137 static LibrarySummary parse(Map json) =>
141 new LibrarySummary(json['library_name'], 138 new LibrarySummary(json['library_name'],
142 messages: json['messages'].map(MessageSummary.parse).toList(), 139 messages: new List<MessageSummary>.from(
140 json['messages'].map(MessageSummary.parse)),
143 lines: json['lines']); 141 lines: json['lines']);
144 } 142 }
145 143
146 /// A summary at the level of an HTML file. 144 /// A summary at the level of an HTML file.
147 class HtmlSummary implements IndividualSummary { 145 class HtmlSummary implements IndividualSummary {
148 /// Unique name used to identify the HTML file. 146 /// Unique name used to identify the HTML file.
149 final String name; 147 final String name;
150 148
151 /// All messages collected on the file. 149 /// All messages collected on the file.
152 final List<MessageSummary> messages; 150 final List<MessageSummary> messages;
153 151
154 HtmlSummary(this.name, [List<MessageSummary> messages]) 152 HtmlSummary(this.name, [List<MessageSummary> messages])
155 : messages = messages == null ? <MessageSummary>[] : messages; 153 : messages = messages == null ? <MessageSummary>[] : messages;
156 154
157 Map toJsonMap() => 155 Map toJsonMap() =>
158 {'name': name, 'messages': messages.map((m) => m.toJsonMap()).toList()}; 156 {'name': name, 'messages': messages.map((m) => m.toJsonMap()).toList()};
159 157
160 void accept(SummaryVisitor visitor) => visitor.visitHtml(this); 158 void accept(SummaryVisitor visitor) => visitor.visitHtml(this);
161 159
162 static HtmlSummary parse(Map json) => new HtmlSummary( 160 static HtmlSummary parse(Map json) => new HtmlSummary(
163 json['name'], json['messages'].map(MessageSummary.parse).toList()); 161 json['name'],
162 new List<MessageSummary>.from(
163 json['messages'].map(MessageSummary.parse)));
164 } 164 }
165 165
166 /// A single message produced by the checker. 166 /// A single message produced by the checker.
167 class MessageSummary implements Summary { 167 class MessageSummary implements Summary {
168 /// The kind of message, currently the name of the StaticInfo type. 168 /// The kind of message, currently the name of the StaticInfo type.
169 final String kind; 169 final String kind;
170 170
171 /// Level (error, warning, etc). 171 /// Level (error, warning, etc).
172 final String level; 172 final String level;
173 173
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 245
246 void visitHtml(HtmlSummary html) { 246 void visitHtml(HtmlSummary html) {
247 for (var msg in html.messages) { 247 for (var msg in html.messages) {
248 msg.accept(this); 248 msg.accept(this);
249 } 249 }
250 } 250 }
251 251
252 void visitMessage(MessageSummary message) {} 252 void visitMessage(MessageSummary message) {}
253 } 253 }
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