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:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; | 10 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; |
| 11 import 'package:analyzer/error/error.dart'; | 11 import 'package:analyzer/error/error.dart'; |
| 12 import 'package:analyzer/error/listener.dart'; | 12 import 'package:analyzer/error/listener.dart'; |
| 13 import 'package:analyzer/exception/exception.dart'; | 13 import 'package:analyzer/exception/exception.dart'; |
| 14 import 'package:analyzer/file_system/file_system.dart'; | 14 import 'package:analyzer/file_system/file_system.dart'; |
| 15 import 'package:analyzer/src/context/context.dart'; | 15 import 'package:analyzer/src/context/context.dart'; |
| 16 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 16 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
| 17 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 17 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 18 import 'package:analyzer/src/dart/analysis/index.dart'; | 18 import 'package:analyzer/src/dart/analysis/index.dart'; |
| 19 import 'package:analyzer/src/dart/analysis/search.dart'; | 19 import 'package:analyzer/src/dart/analysis/search.dart'; |
| 20 import 'package:analyzer/src/dart/analysis/status.dart'; | 20 import 'package:analyzer/src/dart/analysis/status.dart'; |
| 21 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; | 21 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; |
| 22 import 'package:analyzer/src/generated/engine.dart' | 22 import 'package:analyzer/src/generated/engine.dart' |
| 23 show AnalysisContext, AnalysisEngine, AnalysisOptions, ChangeSet; | 23 show AnalysisContext, AnalysisEngine, AnalysisOptions; |
| 24 import 'package:analyzer/src/generated/source.dart'; | 24 import 'package:analyzer/src/generated/source.dart'; |
| 25 import 'package:analyzer/src/services/lint.dart'; | 25 import 'package:analyzer/src/services/lint.dart'; |
| 26 import 'package:analyzer/src/summary/api_signature.dart'; | 26 import 'package:analyzer/src/summary/api_signature.dart'; |
| 27 import 'package:analyzer/src/summary/format.dart'; | 27 import 'package:analyzer/src/summary/format.dart'; |
| 28 import 'package:analyzer/src/summary/idl.dart'; | 28 import 'package:analyzer/src/summary/idl.dart'; |
| 29 import 'package:analyzer/src/summary/link.dart'; | 29 import 'package:analyzer/src/summary/link.dart'; |
| 30 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 30 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 31 import 'package:analyzer/src/task/dart.dart' show COMPILATION_UNIT_ELEMENT; | 31 import 'package:analyzer/src/task/dart.dart' show COMPILATION_UNIT_ELEMENT; |
| 32 import 'package:analyzer/task/dart.dart' show LibrarySpecificUnit; | 32 import 'package:analyzer/task/dart.dart' show LibrarySpecificUnit; |
| 33 import 'package:meta/meta.dart'; | 33 import 'package:meta/meta.dart'; |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 | 676 |
| 677 // Prepare the library file - the file itself, or the known library. | 677 // Prepare the library file - the file itself, or the known library. |
| 678 FileState libraryFile = getLibraryFile(file); | 678 FileState libraryFile = getLibraryFile(file); |
| 679 if (libraryFile == null) { | 679 if (libraryFile == null) { |
| 680 return null; | 680 return null; |
| 681 } | 681 } |
| 682 | 682 |
| 683 _LibraryContext libraryContext = _createLibraryContext(libraryFile); | 683 _LibraryContext libraryContext = _createLibraryContext(libraryFile); |
| 684 AnalysisContext analysisContext = _createAnalysisContext(libraryContext); | 684 AnalysisContext analysisContext = _createAnalysisContext(libraryContext); |
| 685 try { | 685 try { |
| 686 analysisContext.setContents(file.source, file.content); | |
| 687 | |
| 688 // TODO(scheglov) Remove this. | |
| 689 // https://github.com/dart-lang/sdk/issues/28110 | |
| 690 analysisContext.setContents(libraryFile.source, libraryFile.content); | |
| 691 for (FileState part in libraryFile.partedFiles) { | |
| 692 if (part.exists) { | |
| 693 analysisContext.setContents(part.source, part.content); | |
| 694 } | |
| 695 } | |
| 696 | |
| 697 CompilationUnit resolvedUnit = analysisContext.resolveCompilationUnit2( | 686 CompilationUnit resolvedUnit = analysisContext.resolveCompilationUnit2( |
| 698 file.source, libraryFile.source); | 687 file.source, libraryFile.source); |
| 699 List<AnalysisError> errors = analysisContext.computeErrors(file.source); | 688 List<AnalysisError> errors = analysisContext.computeErrors(file.source); |
| 700 AnalysisDriverUnitIndexBuilder index = indexUnit(resolvedUnit); | 689 AnalysisDriverUnitIndexBuilder index = indexUnit(resolvedUnit); |
| 701 | 690 |
| 702 // Store the result into the cache. | 691 // Store the result into the cache. |
| 703 List<int> bytes; | 692 List<int> bytes; |
| 704 { | 693 { |
| 705 bytes = new AnalysisDriverResolvedUnitBuilder( | 694 bytes = new AnalysisDriverResolvedUnitBuilder( |
| 706 errors: errors | 695 errors: errors |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 COMPILATION_UNIT_ELEMENT); | 743 COMPILATION_UNIT_ELEMENT); |
| 755 } finally { | 744 } finally { |
| 756 analysisContext.dispose(); | 745 analysisContext.dispose(); |
| 757 } | 746 } |
| 758 } | 747 } |
| 759 | 748 |
| 760 AnalysisContext _createAnalysisContext(_LibraryContext libraryContext) { | 749 AnalysisContext _createAnalysisContext(_LibraryContext libraryContext) { |
| 761 AnalysisContextImpl analysisContext = | 750 AnalysisContextImpl analysisContext = |
| 762 AnalysisEngine.instance.createAnalysisContext(); | 751 AnalysisEngine.instance.createAnalysisContext(); |
| 763 analysisContext.analysisOptions = _analysisOptions; | 752 analysisContext.analysisOptions = _analysisOptions; |
| 764 | |
| 765 analysisContext.sourceFactory = _sourceFactory.clone(); | 753 analysisContext.sourceFactory = _sourceFactory.clone(); |
| 754 analysisContext.contentCache = new _ContentCacheWrapper(_fsState); | |
| 766 analysisContext.resultProvider = | 755 analysisContext.resultProvider = |
| 767 new InputPackagesResultProvider(analysisContext, libraryContext.store); | 756 new InputPackagesResultProvider(analysisContext, libraryContext.store); |
| 768 analysisContext | |
| 769 .applyChanges(new ChangeSet()..addedSource(libraryContext.file.source)); | |
| 770 return analysisContext; | 757 return analysisContext; |
| 771 } | 758 } |
| 772 | 759 |
| 773 /** | 760 /** |
| 774 * Return the context in which the [library] should be analyzed it. | 761 * Return the context in which the [library] should be analyzed it. |
| 775 */ | 762 */ |
| 776 _LibraryContext _createLibraryContext(FileState library) { | 763 _LibraryContext _createLibraryContext(FileState library) { |
| 777 return _logger.run('Create library context', () { | 764 return _logger.run('Create library context', () { |
| 778 Map<String, FileState> libraries = <String, FileState>{}; | 765 Map<String, FileState> libraries = <String, FileState>{}; |
| 779 SummaryDataStore store = new SummaryDataStore(const <String>[]); | 766 SummaryDataStore store = new SummaryDataStore(const <String>[]); |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1524 */ | 1511 */ |
| 1525 void exit() { | 1512 void exit() { |
| 1526 _timer.stop(); | 1513 _timer.stop(); |
| 1527 _logger._level--; | 1514 _logger._level--; |
| 1528 int ms = _timer.elapsedMilliseconds; | 1515 int ms = _timer.elapsedMilliseconds; |
| 1529 _logger.writeln('--- $_msg in $ms ms.'); | 1516 _logger.writeln('--- $_msg in $ms ms.'); |
| 1530 } | 1517 } |
| 1531 } | 1518 } |
| 1532 | 1519 |
| 1533 /** | 1520 /** |
| 1521 * [ContentCache] wrapper around [FileContentOverlay]. | |
| 1522 */ | |
| 1523 class _ContentCacheWrapper implements ContentCache { | |
| 1524 final FileSystemState fsState; | |
| 1525 | |
| 1526 _ContentCacheWrapper(this.fsState); | |
| 1527 | |
| 1528 @override | |
| 1529 void accept(ContentCacheVisitor visitor) { | |
| 1530 throw new UnimplementedError(); | |
| 1531 } | |
| 1532 | |
| 1533 @override | |
| 1534 String getContents(Source source) { | |
| 1535 return _getFileForSource(source).content; | |
| 1536 } | |
| 1537 | |
| 1538 @override | |
| 1539 bool getExists(Source source) { | |
| 1540 return _getFileForSource(source).exists; | |
| 1541 } | |
| 1542 | |
| 1543 @override | |
| 1544 int getModificationStamp(Source source) { | |
| 1545 return getExists(source) ? 0 : -1; | |
|
Paul Berry
2017/01/04 20:50:50
Since the contract for `getExists` says it might r
| |
| 1546 } | |
| 1547 | |
| 1548 @override | |
| 1549 String setContents(Source source, String contents) { | |
| 1550 throw new UnimplementedError(); | |
| 1551 } | |
| 1552 | |
| 1553 FileState _getFileForSource(Source source) { | |
| 1554 String path = source.fullName; | |
| 1555 return fsState.getFileForPath(path); | |
| 1556 } | |
| 1557 } | |
| 1558 | |
| 1559 /** | |
| 1534 * Task that computes the list of files that were added to the driver and | 1560 * Task that computes the list of files that were added to the driver and |
| 1535 * have at least one reference to an identifier [name] defined outside of the | 1561 * have at least one reference to an identifier [name] defined outside of the |
| 1536 * file. | 1562 * file. |
| 1537 */ | 1563 */ |
| 1538 class _FilesReferencingNameTask { | 1564 class _FilesReferencingNameTask { |
| 1539 static const int _MS_WORK_INTERVAL = 5; | 1565 static const int _MS_WORK_INTERVAL = 5; |
| 1540 | 1566 |
| 1541 final AnalysisDriver driver; | 1567 final AnalysisDriver driver; |
| 1542 final String name; | 1568 final String name; |
| 1543 final Completer<List<String>> completer = new Completer<List<String>>(); | 1569 final Completer<List<String>> completer = new Completer<List<String>>(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1649 libraryDeclarations.add(new TopLevelDeclarationInSource( | 1675 libraryDeclarations.add(new TopLevelDeclarationInSource( |
| 1650 file.source, declaration, isExported)); | 1676 file.source, declaration, isExported)); |
| 1651 } | 1677 } |
| 1652 } | 1678 } |
| 1653 } | 1679 } |
| 1654 | 1680 |
| 1655 // We're not done yet. | 1681 // We're not done yet. |
| 1656 return false; | 1682 return false; |
| 1657 } | 1683 } |
| 1658 } | 1684 } |
| OLD | NEW |