| 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'; |
| 11 import 'package:analyzer/dart/ast/ast.dart'; | 11 import 'package:analyzer/dart/ast/ast.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; | 12 import 'package:analyzer/dart/element/element.dart' |
| 13 show CompilationUnitElement, LibraryElement; |
| 13 import 'package:analyzer/error/error.dart'; | 14 import 'package:analyzer/error/error.dart'; |
| 14 import 'package:analyzer/error/listener.dart'; | 15 import 'package:analyzer/error/listener.dart'; |
| 15 import 'package:analyzer/exception/exception.dart'; | 16 import 'package:analyzer/exception/exception.dart'; |
| 16 import 'package:analyzer/file_system/file_system.dart'; | 17 import 'package:analyzer/file_system/file_system.dart'; |
| 17 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 18 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 18 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 19 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 19 import 'package:analyzer/src/dart/analysis/file_tracker.dart'; | 20 import 'package:analyzer/src/dart/analysis/file_tracker.dart'; |
| 20 import 'package:analyzer/src/dart/analysis/index.dart'; | 21 import 'package:analyzer/src/dart/analysis/index.dart'; |
| 21 import 'package:analyzer/src/dart/analysis/library_analyzer.dart'; | 22 import 'package:analyzer/src/dart/analysis/library_analyzer.dart'; |
| 22 import 'package:analyzer/src/dart/analysis/library_context.dart'; | 23 import 'package:analyzer/src/dart/analysis/library_context.dart'; |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 return new Future.value(); | 590 return new Future.value(); |
| 590 } | 591 } |
| 591 var completer = new Completer<AnalysisDriverUnitIndex>(); | 592 var completer = new Completer<AnalysisDriverUnitIndex>(); |
| 592 _indexRequestedFiles | 593 _indexRequestedFiles |
| 593 .putIfAbsent(path, () => <Completer<AnalysisDriverUnitIndex>>[]) | 594 .putIfAbsent(path, () => <Completer<AnalysisDriverUnitIndex>>[]) |
| 594 .add(completer); | 595 .add(completer); |
| 595 _scheduler.notify(this); | 596 _scheduler.notify(this); |
| 596 return completer.future; | 597 return completer.future; |
| 597 } | 598 } |
| 598 | 599 |
| 600 /** |
| 601 * Return a [Future] that completes with the [LibraryElement] for the given |
| 602 * [uri], which is either resynthesized from the provided external summary |
| 603 * store, or built for a file to which the given [uri] is resolved. |
| 604 */ |
| 605 Future<LibraryElement> getLibraryByUri(String uri) async { |
| 606 if (_externalSummaries != null && _externalSummaries.hasUnlinkedUnit(uri)) { |
| 607 return LibraryContext.resynthesizeLibraryElement(analysisOptions, |
| 608 declaredVariables, sourceFactory, _externalSummaries, uri); |
| 609 } |
| 610 Source source = sourceFactory.resolveUri(null, uri); |
| 611 UnitElementResult unitResult = await getUnitElement(source.fullName); |
| 612 return unitResult.element.library; |
| 613 } |
| 614 |
| 599 ApiSignature getResolvedUnitKeyByPath(String path) { | 615 ApiSignature getResolvedUnitKeyByPath(String path) { |
| 600 ApiSignature signature = getUnitKeyByPath(path); | 616 ApiSignature signature = getUnitKeyByPath(path); |
| 601 var file = fsState.getFileForPath(path); | 617 var file = fsState.getFileForPath(path); |
| 602 signature.addString(file.contentHash); | 618 signature.addString(file.contentHash); |
| 603 return signature; | 619 return signature; |
| 604 } | 620 } |
| 605 | 621 |
| 606 /** | 622 /** |
| 607 * Return a [Future] that completes with a [AnalysisResult] for the Dart | 623 * Return a [Future] that completes with a [AnalysisResult] for the Dart |
| 608 * file with the given [path]. If the file is not a Dart file or cannot | 624 * file with the given [path]. If the file is not a Dart file or cannot |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 _fillSalt(); | 1105 _fillSalt(); |
| 1090 _fsState = new FileSystemState(_logger, _byteStore, _contentOverlay, | 1106 _fsState = new FileSystemState(_logger, _byteStore, _contentOverlay, |
| 1091 _resourceProvider, sourceFactory, analysisOptions, _salt, | 1107 _resourceProvider, sourceFactory, analysisOptions, _salt, |
| 1092 externalSummaries: _externalSummaries); | 1108 externalSummaries: _externalSummaries); |
| 1093 _fileTracker = new FileTracker(_logger, _fsState, _changeHook); | 1109 _fileTracker = new FileTracker(_logger, _fsState, _changeHook); |
| 1094 } | 1110 } |
| 1095 | 1111 |
| 1096 /** | 1112 /** |
| 1097 * Return the context in which the [library] should be analyzed. | 1113 * Return the context in which the [library] should be analyzed. |
| 1098 */ | 1114 */ |
| 1099 LibraryContext _createLibraryContext(FileState library) => | 1115 LibraryContext _createLibraryContext(FileState library) { |
| 1100 new LibraryContext.forSingleLibrary( | 1116 _testView.numOfCreatedLibraryContexts++; |
| 1101 library, | 1117 return new LibraryContext.forSingleLibrary( |
| 1102 _logger, | 1118 library, |
| 1103 _sdkBundle, | 1119 _logger, |
| 1104 _byteStore, | 1120 _sdkBundle, |
| 1105 _analysisOptions, | 1121 _byteStore, |
| 1106 declaredVariables, | 1122 _analysisOptions, |
| 1107 _sourceFactory, | 1123 declaredVariables, |
| 1108 _externalSummaries, | 1124 _sourceFactory, |
| 1109 fsState); | 1125 _externalSummaries, |
| 1126 fsState); |
| 1127 } |
| 1110 | 1128 |
| 1111 /** | 1129 /** |
| 1112 * Fill [_salt] with data. | 1130 * Fill [_salt] with data. |
| 1113 */ | 1131 */ |
| 1114 void _fillSalt() { | 1132 void _fillSalt() { |
| 1115 _salt[0] = DATA_VERSION; | 1133 _salt[0] = DATA_VERSION; |
| 1116 List<int> crossContextOptions = _analysisOptions.signature; | 1134 List<int> crossContextOptions = _analysisOptions.signature; |
| 1117 assert(crossContextOptions.length == AnalysisOptions.signatureLength); | 1135 assert(crossContextOptions.length == AnalysisOptions.signatureLength); |
| 1118 for (int i = 0; i < crossContextOptions.length; i++) { | 1136 for (int i = 0; i < crossContextOptions.length; i++) { |
| 1119 _salt[i + 1] = crossContextOptions[i]; | 1137 _salt[i + 1] = crossContextOptions[i]; |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 return new Future.value(); | 1552 return new Future.value(); |
| 1535 } | 1553 } |
| 1536 return new Future.delayed(Duration.ZERO, () => _pumpEventQueue(times - 1)); | 1554 return new Future.delayed(Duration.ZERO, () => _pumpEventQueue(times - 1)); |
| 1537 } | 1555 } |
| 1538 } | 1556 } |
| 1539 | 1557 |
| 1540 @visibleForTesting | 1558 @visibleForTesting |
| 1541 class AnalysisDriverTestView { | 1559 class AnalysisDriverTestView { |
| 1542 final AnalysisDriver driver; | 1560 final AnalysisDriver driver; |
| 1543 | 1561 |
| 1562 int numOfCreatedLibraryContexts = 0; |
| 1563 |
| 1544 int numOfAnalyzedLibraries = 0; | 1564 int numOfAnalyzedLibraries = 0; |
| 1545 | 1565 |
| 1546 AnalysisDriverTestView(this.driver); | 1566 AnalysisDriverTestView(this.driver); |
| 1547 | 1567 |
| 1548 FileTracker get fileTracker => driver._fileTracker; | 1568 FileTracker get fileTracker => driver._fileTracker; |
| 1549 | 1569 |
| 1550 Map<String, AnalysisResult> get priorityResults => driver._priorityResults; | 1570 Map<String, AnalysisResult> get priorityResults => driver._priorityResults; |
| 1551 | 1571 |
| 1552 SummaryDataStore getSummaryStore(String libraryPath) { | 1572 SummaryDataStore getSummaryStore(String libraryPath) { |
| 1553 FileState library = driver.fsState.getFileForPath(libraryPath); | 1573 FileState library = driver.fsState.getFileForPath(libraryPath); |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2081 libraryDeclarations.add(new TopLevelDeclarationInSource( | 2101 libraryDeclarations.add(new TopLevelDeclarationInSource( |
| 2082 file.source, declaration, isExported)); | 2102 file.source, declaration, isExported)); |
| 2083 } | 2103 } |
| 2084 } | 2104 } |
| 2085 } | 2105 } |
| 2086 | 2106 |
| 2087 // We're not done yet. | 2107 // We're not done yet. |
| 2088 return false; | 2108 return false; |
| 2089 } | 2109 } |
| 2090 } | 2110 } |
| OLD | NEW |