Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 /** | 201 /** |
| 202 * Return the [Stream] that produces [AnalysisResult]s for added files. | 202 * Return the [Stream] that produces [AnalysisResult]s for added files. |
| 203 * | 203 * |
| 204 * Analysis starts when the client starts listening to the stream, and stops | 204 * Analysis starts when the client starts listening to the stream, and stops |
| 205 * when the client cancels the subscription. | 205 * when the client cancels the subscription. |
| 206 * | 206 * |
| 207 * When the client starts listening, the analysis state transitions to | 207 * When the client starts listening, the analysis state transitions to |
| 208 * "analyzing" and an analysis result is produced for every added file prior | 208 * "analyzing" and an analysis result is produced for every added file prior |
| 209 * to the next time the analysis state transitions to "idle". | 209 * to the next time the analysis state transitions to "idle". |
| 210 * | 210 * |
| 211 * At least one analysis result is produced for every file passed to | |
| 212 * [addFile] or [changeFile] prior to the next time the analysis state | |
| 213 * transitions to "idle", unless the file is later removed from analysis | |
| 214 * using [removeFile]. Analysis results for other files are produced only if | |
| 215 * the changes affect analysis results of other files. | |
| 216 * | |
| 217 * More than one result might be produced for the same file, even if the | 211 * More than one result might be produced for the same file, even if the |
| 218 * client does not change the state of the files. | 212 * client does not change the state of the files. |
| 219 * | 213 * |
| 220 * Results might be produced even for files that have never been added | 214 * Results might be produced even for files that have never been added |
| 221 * using [addFile], for example when [getResult] was called for a file. | 215 * using [addFile], for example when [getResult] was called for a file. |
| 222 */ | 216 */ |
| 223 Stream<AnalysisResult> get results async* { | 217 Stream<AnalysisResult> get results async* { |
| 224 try { | 218 try { |
| 225 PerformanceLogSection analysisSection = null; | 219 PerformanceLogSection analysisSection = null; |
| 226 while (true) { | 220 while (true) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 * Return the stream that produces [AnalysisStatus] events. | 292 * Return the stream that produces [AnalysisStatus] events. |
| 299 */ | 293 */ |
| 300 Stream<AnalysisStatus> get status => _statusController.stream; | 294 Stream<AnalysisStatus> get status => _statusController.stream; |
| 301 | 295 |
| 302 /** | 296 /** |
| 303 * Add the file with the given [path] to the set of files to analyze. | 297 * Add the file with the given [path] to the set of files to analyze. |
| 304 * | 298 * |
| 305 * The [path] must be absolute and normalized. | 299 * The [path] must be absolute and normalized. |
| 306 * | 300 * |
| 307 * The results of analysis are eventually produced by the [results] stream. | 301 * The results of analysis are eventually produced by the [results] stream. |
| 302 * | |
| 303 * Causes the analysis state to transition to "analyzing" (if it is not in | |
| 304 * that state already). At least one analysis result will be produced the | |
| 305 * file prior to the next time the analysis state transitions to "idle", | |
| 306 * unless the file is later removed from analysis using [removeFile]. | |
| 308 */ | 307 */ |
| 309 void addFile(String path) { | 308 void addFile(String path) { |
| 310 _explicitFiles.add(path); | 309 _explicitFiles.add(path); |
| 311 _filesToAnalyze.add(path); | 310 _filesToAnalyze.add(path); |
| 312 _transitionToAnalyzing(); | 311 _transitionToAnalyzing(); |
| 313 _hasWork.notify(); | 312 _hasWork.notify(); |
| 314 } | 313 } |
| 315 | 314 |
| 316 /** | 315 /** |
| 317 * The file with the given [path] might have changed - updated, added or | 316 * The file with the given [path] might have changed - updated, added or |
| 318 * removed. Or not, we don't know. Or it might have, but then changed back. | 317 * removed. Or not, we don't know. Or it might have, but then changed back. |
| 319 * | 318 * |
| 320 * The [path] must be absolute and normalized. | 319 * The [path] must be absolute and normalized. |
| 321 * | 320 * |
| 322 * The [path] can be any file - explicitly or implicitly analyzed, or neither. | 321 * The [path] can be any file - explicitly or implicitly analyzed, or neither. |
| 323 * | 322 * |
| 324 * Causes the analysis state to transition to "analyzing" (if it is not in | 323 * Causes the analysis state to transition to "analyzing" (if it is not in |
| 325 * that state already). Schedules the file contents for [path] to be read | 324 * that state already). Schedules the file contents for [path] to be read |
| 326 * into the current file state prior to the next time the analysis state | 325 * into the current file state prior to the next time the analysis state |
| 327 * transitions to "idle". | 326 * transitions to "idle". |
| 328 * | 327 * |
| 328 * If the file content is the same, no new results will be produced because | |
| 329 * of this notification, including no result for the file itself. Otherwise, | |
| 330 * one or more results will be produced - for the file itself and other | |
| 331 * files that that change in the file might affect. | |
|
Brian Wilkerson
2016/10/31 14:06:04
"that that" --> "that the"
| |
| 332 * | |
| 329 * Invocation of this method will not prevent a [Future] returned from | 333 * Invocation of this method will not prevent a [Future] returned from |
| 330 * [getResult] from completing with a result, but the result is not | 334 * [getResult] from completing with a result, but the result is not |
| 331 * guaranteed to be consistent with the new current file state after this | 335 * guaranteed to be consistent with the new current file state after this |
| 332 * [changeFile] invocation. | 336 * [changeFile] invocation. |
| 333 */ | 337 */ |
| 334 void changeFile(String path) { | 338 void changeFile(String path) { |
| 335 _changedFiles.add(path); | 339 _changedFiles.add(path); |
| 336 if (_explicitFiles.contains(path)) { | 340 if (_explicitFiles.contains(path)) { |
| 337 _filesToAnalyze.add(path); | 341 _filesToAnalyze.add(path); |
| 338 } | 342 } |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 } | 678 } |
| 675 | 679 |
| 676 /** | 680 /** |
| 677 * Verify the API signature for the file with the given [path], and decide | 681 * Verify the API signature for the file with the given [path], and decide |
| 678 * which linked libraries should be invalidated, and files reanalyzed. | 682 * which linked libraries should be invalidated, and files reanalyzed. |
| 679 * | 683 * |
| 680 * TODO(scheglov) I see that adding a local var changes (full) API signature. | 684 * TODO(scheglov) I see that adding a local var changes (full) API signature. |
| 681 */ | 685 */ |
| 682 void _verifyApiSignatureOfChangedFile(String path) { | 686 void _verifyApiSignatureOfChangedFile(String path) { |
| 683 _logger.run('Verify API signature of $path', () { | 687 _logger.run('Verify API signature of $path', () { |
| 688 String oldContentHash = _fileContentHashMap[path]; | |
| 684 String oldSignature = _fileApiSignatureMap[path]; | 689 String oldSignature = _fileApiSignatureMap[path]; |
| 685 // Compute the new API signature. | 690 // Compute the new API signature. |
| 686 // _File.forResolution() also updates the content hash in the cache. | 691 // _File.forResolution() also updates the content hash in the cache. |
| 687 Source source = _sourceForPath(path); | 692 Source source = _sourceForPath(path); |
| 688 _File newFile = new _File.forResolution(this, source); | 693 _File newFile = new _File.forResolution(this, source); |
| 689 String newSignature = newFile.unlinked.apiSignature; | 694 // If the file content hash is the same, we don't need analyzing it. |
|
Brian Wilkerson
2016/10/31 14:06:04
"need analyzing it" --> "need to analyze it"
| |
| 695 if (newFile.contentHash == oldContentHash) { | |
| 696 _filesToAnalyze.remove(path); | |
| 697 return; | |
| 698 } | |
| 690 // If the old API signature is not null, then the file was used to | 699 // If the old API signature is not null, then the file was used to |
| 691 // compute at least one dependency signature. If the new API signature | 700 // compute at least one dependency signature. If the new API signature |
| 692 // is different, then potentially all dependency signatures and | 701 // is different, then potentially all dependency signatures and |
| 693 // resolution results are invalid. | 702 // resolution results are invalid. |
| 703 String newSignature = newFile.unlinked.apiSignature; | |
| 694 if (oldSignature != null && oldSignature != newSignature) { | 704 if (oldSignature != null && oldSignature != newSignature) { |
| 695 _logger.writeln('API signatures mismatch found for $newFile'); | 705 _logger.writeln('API signatures mismatch found for $newFile'); |
| 696 _dependencySignatureMap.clear(); | 706 _dependencySignatureMap.clear(); |
| 697 _filesToAnalyze.addAll(_explicitFiles); | 707 _filesToAnalyze.addAll(_explicitFiles); |
| 698 } | 708 } |
| 699 }); | 709 }); |
| 700 } | 710 } |
| 701 | 711 |
| 702 /** | 712 /** |
| 703 * Remove and return the first item in the given [set]. | 713 * Remove and return the first item in the given [set]. |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 } | 1207 } |
| 1198 } | 1208 } |
| 1199 for (UnlinkedExportPublic export in unit.publicNamespace.exports) { | 1209 for (UnlinkedExportPublic export in unit.publicNamespace.exports) { |
| 1200 referenced.exported.add(export.uri); | 1210 referenced.exported.add(export.uri); |
| 1201 } | 1211 } |
| 1202 return referenced; | 1212 return referenced; |
| 1203 } | 1213 } |
| 1204 | 1214 |
| 1205 _ReferencedUris._(); | 1215 _ReferencedUris._(); |
| 1206 } | 1216 } |
| OLD | NEW |