| 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:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 import 'package:analyzer/context/context_root.dart'; | 9 import 'package:analyzer/context/context_root.dart'; |
| 10 import 'package:analyzer/context/declared_variables.dart'; | 10 import 'package:analyzer/context/declared_variables.dart'; |
| (...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 var state = exception as _ExceptionState; | 1306 var state = exception as _ExceptionState; |
| 1307 exception = state.exception; | 1307 exception = state.exception; |
| 1308 stackTrace = state.stackTrace; | 1308 stackTrace = state.stackTrace; |
| 1309 contextKey = state.contextKey; | 1309 contextKey = state.contextKey; |
| 1310 } | 1310 } |
| 1311 CaughtException caught = new CaughtException(exception, stackTrace); | 1311 CaughtException caught = new CaughtException(exception, stackTrace); |
| 1312 _exceptionController.add(new ExceptionResult(path, caught, contextKey)); | 1312 _exceptionController.add(new ExceptionResult(path, caught, contextKey)); |
| 1313 } | 1313 } |
| 1314 | 1314 |
| 1315 /** | 1315 /** |
| 1316 * Tests need a reliable way to simulate file changes during analysis. | 1316 * Runs any asynchronous work that was injected as part of a test using |
| 1317 * [AnalysisDriverTestView.workToWaitAfterComputingResult]. |
| 1317 * | 1318 * |
| 1318 * When a change happens, the driver must make sure that [getResult] produces | 1319 * If the test view indicates that there is work to do, performs the work |
| 1319 * results that include these changes. It is OK for the [results] stream | 1320 * and returns a [Future] that will be signaled when the work completes. |
| 1320 * to produce stale results as long as it eventually produces results that | 1321 * |
| 1321 * also include the changes. | 1322 * This gives tests a reliable way to simulate file changes during analysis. |
| 1322 */ | 1323 */ |
| 1323 Future _runTestAsyncWorkDuringAnalysis(String path) { | 1324 Future _runTestAsyncWorkDuringAnalysis(String path) { |
| 1324 var work = _testView.workToWaitAfterComputingResult; | 1325 var work = _testView.workToWaitAfterComputingResult; |
| 1325 _testView.workToWaitAfterComputingResult = null; | 1326 _testView.workToWaitAfterComputingResult = null; |
| 1326 return work != null ? work(path) : null; | 1327 return work != null ? work(path) : new Future.value(); |
| 1327 } | 1328 } |
| 1328 | 1329 |
| 1329 /** | 1330 /** |
| 1330 * Serialize the given [resolvedUnit] errors and index into bytes. | 1331 * Serialize the given [resolvedUnit] errors and index into bytes. |
| 1331 */ | 1332 */ |
| 1332 List<int> _serializeResolvedUnit( | 1333 List<int> _serializeResolvedUnit( |
| 1333 CompilationUnit resolvedUnit, List<AnalysisError> errors) { | 1334 CompilationUnit resolvedUnit, List<AnalysisError> errors) { |
| 1334 AnalysisDriverUnitIndexBuilder index = indexUnit(resolvedUnit); | 1335 AnalysisDriverUnitIndexBuilder index = indexUnit(resolvedUnit); |
| 1335 return new AnalysisDriverResolvedUnitBuilder( | 1336 return new AnalysisDriverResolvedUnitBuilder( |
| 1336 errors: errors | 1337 errors: errors |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1668 } | 1669 } |
| 1669 | 1670 |
| 1670 @visibleForTesting | 1671 @visibleForTesting |
| 1671 class AnalysisDriverTestView { | 1672 class AnalysisDriverTestView { |
| 1672 final AnalysisDriver driver; | 1673 final AnalysisDriver driver; |
| 1673 | 1674 |
| 1674 int numOfCreatedLibraryContexts = 0; | 1675 int numOfCreatedLibraryContexts = 0; |
| 1675 | 1676 |
| 1676 int numOfAnalyzedLibraries = 0; | 1677 int numOfAnalyzedLibraries = 0; |
| 1677 | 1678 |
| 1679 /** |
| 1680 * If non-null, a function that should be executed asynchronously after |
| 1681 * the next result is computed. |
| 1682 * |
| 1683 * This can be used by a test to simulate file changes during analysis. |
| 1684 */ |
| 1678 Future<Null> Function(String path) workToWaitAfterComputingResult; | 1685 Future<Null> Function(String path) workToWaitAfterComputingResult; |
| 1679 | 1686 |
| 1680 AnalysisDriverTestView(this.driver); | 1687 AnalysisDriverTestView(this.driver); |
| 1681 | 1688 |
| 1682 FileTracker get fileTracker => driver._fileTracker; | 1689 FileTracker get fileTracker => driver._fileTracker; |
| 1683 | 1690 |
| 1684 Map<String, AnalysisResult> get priorityResults => driver._priorityResults; | 1691 Map<String, AnalysisResult> get priorityResults => driver._priorityResults; |
| 1685 | 1692 |
| 1686 Future<SummaryDataStore> getSummaryStore(String libraryPath) async { | 1693 Future<SummaryDataStore> getSummaryStore(String libraryPath) async { |
| 1687 FileState library = driver.fsState.getFileForPath(libraryPath); | 1694 FileState library = driver.fsState.getFileForPath(libraryPath); |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2107 libraryDeclarations.add(new TopLevelDeclarationInSource( | 2114 libraryDeclarations.add(new TopLevelDeclarationInSource( |
| 2108 file.source, declaration, isExported)); | 2115 file.source, declaration, isExported)); |
| 2109 } | 2116 } |
| 2110 } | 2117 } |
| 2111 } | 2118 } |
| 2112 | 2119 |
| 2113 // We're not done yet. | 2120 // We're not done yet. |
| 2114 return false; | 2121 return false; |
| 2115 } | 2122 } |
| 2116 } | 2123 } |
| OLD | NEW |