| 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/declared_variables.dart'; | 9 import 'package:analyzer/context/declared_variables.dart'; |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 * results are "eventually consistent" with the file system by simply calling | 67 * results are "eventually consistent" with the file system by simply calling |
| 68 * [changeFile] any time the contents of a file on the file system have changed. | 68 * [changeFile] any time the contents of a file on the file system have changed. |
| 69 * | 69 * |
| 70 * | 70 * |
| 71 * TODO(scheglov) Clean up the list of implicitly analyzed files. | 71 * TODO(scheglov) Clean up the list of implicitly analyzed files. |
| 72 */ | 72 */ |
| 73 class AnalysisDriver { | 73 class AnalysisDriver { |
| 74 /** | 74 /** |
| 75 * The version of data format, should be incremented on every format change. | 75 * The version of data format, should be incremented on every format change. |
| 76 */ | 76 */ |
| 77 static const int DATA_VERSION = 13; | 77 static const int DATA_VERSION = 14; |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * The name of the driver, e.g. the name of the folder. | 80 * The name of the driver, e.g. the name of the folder. |
| 81 */ | 81 */ |
| 82 final String name; | 82 final String name; |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * The scheduler that schedules analysis work in this, and possibly other | 85 * The scheduler that schedules analysis work in this, and possibly other |
| 86 * analysis drivers. | 86 * analysis drivers. |
| 87 */ | 87 */ |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 * | 625 * |
| 626 * The result will have the fully resolved unit and will always be newly | 626 * The result will have the fully resolved unit and will always be newly |
| 627 * compute only if [withUnit] is `true`. | 627 * compute only if [withUnit] is `true`. |
| 628 * | 628 * |
| 629 * Return `null` if the file is a part of an unknown library, so cannot be | 629 * Return `null` if the file is a part of an unknown library, so cannot be |
| 630 * analyzed yet. But [asIsIfPartWithoutLibrary] is `true`, then the file is | 630 * analyzed yet. But [asIsIfPartWithoutLibrary] is `true`, then the file is |
| 631 * analyzed anyway, even without a library. | 631 * analyzed anyway, even without a library. |
| 632 */ | 632 */ |
| 633 AnalysisResult _computeAnalysisResult(String path, | 633 AnalysisResult _computeAnalysisResult(String path, |
| 634 {bool withUnit: false, bool asIsIfPartWithoutLibrary: false}) { | 634 {bool withUnit: false, bool asIsIfPartWithoutLibrary: false}) { |
| 635 if (!_fsState.hasUri(path)) { |
| 636 throw new StateError('The file $path has no URI.'); |
| 637 } |
| 638 |
| 635 /** | 639 /** |
| 636 * If the [file] is a library, return the [file] itself. | 640 * If the [file] is a library, return the [file] itself. |
| 637 * If the [file] is a part, return a library it is known to be a part of. | 641 * If the [file] is a part, return a library it is known to be a part of. |
| 638 * If there is no such library, return `null`. | 642 * If there is no such library, return `null`. |
| 639 */ | 643 */ |
| 640 FileState getLibraryFile(FileState file) { | 644 FileState getLibraryFile(FileState file) { |
| 641 FileState libraryFile = file.isPart ? file.library : file; | 645 FileState libraryFile = file.isPart ? file.library : file; |
| 642 if (libraryFile == null && asIsIfPartWithoutLibrary) { | 646 if (libraryFile == null && asIsIfPartWithoutLibrary) { |
| 643 libraryFile = file; | 647 libraryFile = file; |
| 644 } | 648 } |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 if (_fsState.knownFilePaths.contains(path)) { | 937 if (_fsState.knownFilePaths.contains(path)) { |
| 934 _verifyApiSignature(path); | 938 _verifyApiSignature(path); |
| 935 } | 939 } |
| 936 return; | 940 return; |
| 937 } | 941 } |
| 938 | 942 |
| 939 // Analyze a requested file. | 943 // Analyze a requested file. |
| 940 if (_requestedFiles.isNotEmpty) { | 944 if (_requestedFiles.isNotEmpty) { |
| 941 String path = _requestedFiles.keys.first; | 945 String path = _requestedFiles.keys.first; |
| 942 try { | 946 try { |
| 943 AnalysisResult result = _computeAnalysisResult(path, withUnit: true); | 947 AnalysisResult result; |
| 944 // If a part without a library, delay its analysis. | 948 if (_fsState.hasUri(path)) { |
| 945 if (result == null) { | 949 result = _computeAnalysisResult(path, withUnit: true); |
| 946 _requestedParts | 950 // If a part without a library, delay its analysis. |
| 947 .putIfAbsent(path, () => []) | 951 if (result == null) { |
| 948 .addAll(_requestedFiles.remove(path)); | 952 _requestedParts |
| 949 return; | 953 .putIfAbsent(path, () => []) |
| 954 .addAll(_requestedFiles.remove(path)); |
| 955 return; |
| 956 } |
| 957 // Produce the result. |
| 958 _resultController.add(result); |
| 959 } else { |
| 960 result = null; |
| 950 } | 961 } |
| 951 // Notify the completers. | 962 // Notify the completers. |
| 952 _requestedFiles.remove(path).forEach((completer) { | 963 _requestedFiles.remove(path).forEach((completer) { |
| 953 completer.complete(result); | 964 completer.complete(result); |
| 954 }); | 965 }); |
| 955 // Remove from to be analyzed and produce it now. | 966 // Remove from to be analyzed and produce it now. |
| 956 _filesToAnalyze.remove(path); | 967 _filesToAnalyze.remove(path); |
| 957 _resultController.add(result); | |
| 958 } catch (exception, stackTrace) { | 968 } catch (exception, stackTrace) { |
| 959 _filesToAnalyze.remove(path); | 969 _filesToAnalyze.remove(path); |
| 960 _requestedFiles.remove(path).forEach((completer) { | 970 _requestedFiles.remove(path).forEach((completer) { |
| 961 completer.completeError(exception, stackTrace); | 971 completer.completeError(exception, stackTrace); |
| 962 }); | 972 }); |
| 963 } | 973 } |
| 964 return; | 974 return; |
| 965 } | 975 } |
| 966 | 976 |
| 967 // Process an index request. | 977 // Process an index request. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 if (isDone) { | 1011 if (isDone) { |
| 1002 _topLevelNameDeclarationsTasks.remove(task); | 1012 _topLevelNameDeclarationsTasks.remove(task); |
| 1003 } | 1013 } |
| 1004 return; | 1014 return; |
| 1005 } | 1015 } |
| 1006 | 1016 |
| 1007 // Analyze a priority file. | 1017 // Analyze a priority file. |
| 1008 if (_priorityFiles.isNotEmpty) { | 1018 if (_priorityFiles.isNotEmpty) { |
| 1009 for (String path in _priorityFiles) { | 1019 for (String path in _priorityFiles) { |
| 1010 if (_filesToAnalyze.remove(path)) { | 1020 if (_filesToAnalyze.remove(path)) { |
| 1011 try { | 1021 if (_fsState.hasUri(path)) { |
| 1012 AnalysisResult result = | 1022 try { |
| 1013 _computeAnalysisResult(path, withUnit: true); | 1023 AnalysisResult result = |
| 1014 if (result == null) { | 1024 _computeAnalysisResult(path, withUnit: true); |
| 1015 _partsToAnalyze.add(path); | 1025 if (result == null) { |
| 1016 } else { | 1026 _partsToAnalyze.add(path); |
| 1017 _resultController.add(result); | 1027 } else { |
| 1028 _resultController.add(result); |
| 1029 } |
| 1030 } catch (exception, stackTrace) { |
| 1031 _reportError(path, exception, stackTrace); |
| 1018 } | 1032 } |
| 1019 } catch (exception, stackTrace) { | |
| 1020 _reportError(path, exception, stackTrace); | |
| 1021 } | 1033 } |
| 1022 return; | 1034 return; |
| 1023 } | 1035 } |
| 1024 } | 1036 } |
| 1025 } | 1037 } |
| 1026 | 1038 |
| 1027 // Analyze a general file. | 1039 // Analyze a general file. |
| 1028 if (_filesToAnalyze.isNotEmpty) { | 1040 if (_filesToAnalyze.isNotEmpty) { |
| 1029 String path = _removeFirst(_filesToAnalyze); | 1041 String path = _removeFirst(_filesToAnalyze); |
| 1030 try { | 1042 if (_fsState.hasUri(path)) { |
| 1031 AnalysisResult result = _computeAnalysisResult(path, withUnit: false); | 1043 try { |
| 1032 if (result == null) { | 1044 AnalysisResult result = _computeAnalysisResult(path, withUnit: false); |
| 1033 _partsToAnalyze.add(path); | 1045 if (result == null) { |
| 1034 } else { | 1046 _partsToAnalyze.add(path); |
| 1035 _resultController.add(result); | 1047 } else { |
| 1048 _resultController.add(result); |
| 1049 } |
| 1050 } catch (exception, stackTrace) { |
| 1051 _reportError(path, exception, stackTrace); |
| 1036 } | 1052 } |
| 1037 } catch (exception, stackTrace) { | |
| 1038 _reportError(path, exception, stackTrace); | |
| 1039 } | 1053 } |
| 1040 return; | 1054 return; |
| 1041 } | 1055 } |
| 1042 | 1056 |
| 1043 // Analyze a requested part file. | 1057 // Analyze a requested part file. |
| 1044 if (_requestedParts.isNotEmpty) { | 1058 if (_requestedParts.isNotEmpty) { |
| 1045 String path = _requestedParts.keys.first; | 1059 String path = _requestedParts.keys.first; |
| 1046 try { | 1060 try { |
| 1047 AnalysisResult result = _computeAnalysisResult(path, | 1061 AnalysisResult result = _computeAnalysisResult(path, |
| 1048 withUnit: true, asIsIfPartWithoutLibrary: true); | 1062 withUnit: true, asIsIfPartWithoutLibrary: true); |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 libraryDeclarations.add(new TopLevelDeclarationInSource( | 1695 libraryDeclarations.add(new TopLevelDeclarationInSource( |
| 1682 file.source, declaration, isExported)); | 1696 file.source, declaration, isExported)); |
| 1683 } | 1697 } |
| 1684 } | 1698 } |
| 1685 } | 1699 } |
| 1686 | 1700 |
| 1687 // We're not done yet. | 1701 // We're not done yet. |
| 1688 return false; | 1702 return false; |
| 1689 } | 1703 } |
| 1690 } | 1704 } |
| OLD | NEW |