OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 /// A library for code coverage support for Dart. | 5 /// A library for code coverage support for Dart. |
6 library runtime.coverage.impl; | 6 library runtime.coverage.impl; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:collection' show SplayTreeMap; | 9 import 'dart:collection' show SplayTreeMap; |
10 import 'dart:io'; | 10 import 'dart:io'; |
11 | 11 |
12 import 'package:path/path.dart' as pathos; | 12 import 'package:path/path.dart' as pathos; |
13 | 13 |
14 import 'package:analyzer_experimental/src/generated/java_core.dart' show CharSeq
uence; | 14 import 'package:analyzer/src/generated/java_core.dart' show CharSequence; |
15 import 'package:analyzer_experimental/src/generated/scanner.dart' show CharSeque
nceReader, Scanner; | 15 import 'package:analyzer/src/generated/scanner.dart' show CharSequenceReader, Sc
anner; |
16 import 'package:analyzer_experimental/src/generated/parser.dart' show Parser; | 16 import 'package:analyzer/src/generated/parser.dart' show Parser; |
17 import 'package:analyzer_experimental/src/generated/ast.dart'; | 17 import 'package:analyzer/src/generated/ast.dart'; |
18 import 'package:analyzer_experimental/src/generated/engine.dart' show RecordingE
rrorListener; | 18 import 'package:analyzer/src/generated/engine.dart' show RecordingErrorListener; |
19 | 19 |
20 import '../log.dart' as log; | 20 import '../log.dart' as log; |
21 import 'models.dart'; | 21 import 'models.dart'; |
22 | 22 |
23 /// Run the [targetPath] with code coverage rewriting. | 23 /// Run the [targetPath] with code coverage rewriting. |
24 /// Redirects stdandard process streams. | 24 /// Redirects stdandard process streams. |
25 /// On process exit dumps coverage statistics into the [outPath]. | 25 /// On process exit dumps coverage statistics into the [outPath]. |
26 void runServerApplication(String targetPath, String outPath) { | 26 void runServerApplication(String targetPath, String outPath) { |
27 var targetFolder = pathos.dirname(targetPath); | 27 var targetFolder = pathos.dirname(targetPath); |
28 var targetName = pathos.basename(targetPath); | 28 var targetName = pathos.basename(targetPath); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 return null; | 200 return null; |
201 } | 201 } |
202 | 202 |
203 bool shouldRewriteFile(String path) { | 203 bool shouldRewriteFile(String path) { |
204 if (pathos.extension(path).toLowerCase() != '.dart') return false; | 204 if (pathos.extension(path).toLowerCase() != '.dart') return false; |
205 // Rewrite target itself, only to send statistics. | 205 // Rewrite target itself, only to send statistics. |
206 if (path == targetPath) { | 206 if (path == targetPath) { |
207 return true; | 207 return true; |
208 } | 208 } |
209 // TODO(scheglov) use configuration | 209 // TODO(scheglov) use configuration |
210 return path.contains('/packages/analyzer_experimental/'); | 210 return path.contains('/packages/analyzer/'); |
211 } | 211 } |
212 | 212 |
213 String rewriteFileContent(String path, String code) { | 213 String rewriteFileContent(String path, String code) { |
214 var unit = _parseCode(code); | 214 var unit = _parseCode(code); |
215 log.finest('[$path] Parsed.'); | 215 log.finest('[$path] Parsed.'); |
216 var injector = new CodeInjector(code); | 216 var injector = new CodeInjector(code); |
217 // Inject imports. | 217 // Inject imports. |
218 var directives = unit.directives; | 218 var directives = unit.directives; |
219 if (directives.isNotEmpty && directives[0] is LibraryDirective) { | 219 if (directives.isNotEmpty && directives[0] is LibraryDirective) { |
220 injector.inject(directives[0].end, | 220 injector.inject(directives[0].end, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 var lastOffset = 0; | 332 var lastOffset = 0; |
333 offsetFragmentMap.forEach((offset, fragment) { | 333 offsetFragmentMap.forEach((offset, fragment) { |
334 sb.write(_code.substring(lastOffset, offset)); | 334 sb.write(_code.substring(lastOffset, offset)); |
335 sb.write(fragment); | 335 sb.write(fragment); |
336 lastOffset = offset; | 336 lastOffset = offset; |
337 }); | 337 }); |
338 sb.write(_code.substring(lastOffset, _code.length)); | 338 sb.write(_code.substring(lastOffset, _code.length)); |
339 return sb.toString(); | 339 return sb.toString(); |
340 } | 340 } |
341 } | 341 } |
OLD | NEW |