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

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

Issue 1230903002: fixes #6, refactor to use AnalysisError/Listener throughout dev_compiler (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 5 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 | « lib/src/report.dart ('k') | lib/src/testing.dart » ('j') | 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;
9 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
10 import 'package:analyzer/src/generated/source.dart' show Source;
8 import 'package:source_span/source_span.dart'; 11 import 'package:source_span/source_span.dart';
9 12
10 /// Summary information computed by the DDC checker. 13 /// Summary information computed by the DDC checker.
11 abstract class Summary { 14 abstract class Summary {
12 Map toJsonMap(); 15 Map toJsonMap();
13 16
14 void accept(SummaryVisitor visitor); 17 void accept(SummaryVisitor visitor);
15 } 18 }
16 19
17 /// Summary for the entire program. 20 /// Summary for the entire program.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 90 }
88 91
89 /// A summary at the level of a library. 92 /// A summary at the level of a library.
90 class LibrarySummary implements IndividualSummary { 93 class LibrarySummary implements IndividualSummary {
91 /// Unique name for this library. 94 /// Unique name for this library.
92 final String name; 95 final String name;
93 96
94 /// All messages collected for the library. 97 /// All messages collected for the library.
95 final List<MessageSummary> messages; 98 final List<MessageSummary> messages;
96 99
100 /// All parts of this library. Only used for computing _lines.
101 final _uris = new HashSet<Uri>();
102
103 int _lines;
104
105 LibrarySummary(this.name, {List<MessageSummary> messages, lines})
106 : messages = messages == null ? <MessageSummary>[] : messages,
107 _lines = lines == null ? lines : 0;
108
109 void clear() {
110 _uris.clear();
111 _lines = 0;
112 messages.clear();
113 }
114
97 /// Total lines of code (including all parts of the library). 115 /// Total lines of code (including all parts of the library).
98 int lines; 116 int get lines => _lines;
99
100 LibrarySummary(this.name, [List<MessageSummary> messages, this.lines = 0])
101 : messages = messages == null ? <MessageSummary>[] : messages;
102 117
103 Map toJsonMap() => { 118 Map toJsonMap() => {
104 'library_name': name, 119 'library_name': name,
105 'messages': messages.map((m) => m.toJsonMap()).toList(), 120 'messages': messages.map((m) => m.toJsonMap()).toList(),
106 'lines': lines, 121 'lines': lines,
107 }; 122 };
108 123
124 void countSourceLines(AnalysisContext context, Source source) {
125 if (_uris.add(source.uri)) {
126 // TODO(jmesserly): parsing is serious overkill for this.
127 // Should be cached, but still.
128 // On the other hand, if we are going to parse, we could get a much better
129 // source lines of code estimate by excluding things like comments,
130 // blank lines, and closing braces.
131 var unit = context.parseCompilationUnit(source);
132 _lines += unit.lineInfo.getLocation(unit.endToken.end).lineNumber;
133 }
134 }
135
109 void accept(SummaryVisitor visitor) => visitor.visitLibrary(this); 136 void accept(SummaryVisitor visitor) => visitor.visitLibrary(this);
110 137
111 static LibrarySummary parse(Map json) => new LibrarySummary( 138 static LibrarySummary parse(Map json) => new LibrarySummary(
112 json['library_name'], json['messages'].map(MessageSummary.parse).toList(), 139 json['library_name'],
113 json['lines']); 140 messages: json['messages'].map(MessageSummary.parse).toList(),
141 lines: json['lines']);
114 } 142 }
115 143
116 /// A summary at the level of an HTML file. 144 /// A summary at the level of an HTML file.
117 class HtmlSummary implements IndividualSummary { 145 class HtmlSummary implements IndividualSummary {
118 /// Unique name used to identify the HTML file. 146 /// Unique name used to identify the HTML file.
119 final String name; 147 final String name;
120 148
121 /// All messages collected on the file. 149 /// All messages collected on the file.
122 final List<MessageSummary> messages; 150 final List<MessageSummary> messages;
123 151
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 241 }
214 } 242 }
215 243
216 void visitHtml(HtmlSummary html) { 244 void visitHtml(HtmlSummary html) {
217 for (var msg in html.messages) { 245 for (var msg in html.messages) {
218 msg.accept(this); 246 msg.accept(this);
219 } 247 }
220 } 248 }
221 void visitMessage(MessageSummary message) {} 249 void visitMessage(MessageSummary message) {}
222 } 250 }
OLDNEW
« no previous file with comments | « lib/src/report.dart ('k') | lib/src/testing.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698