| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.src.context.context; | 5 library analyzer.src.context.context; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/cancelable_future.dart'; | 10 import 'package:analyzer/src/cancelable_future.dart'; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 TaskManager _taskManager; | 98 TaskManager _taskManager; |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * The analysis driver used to perform analysis. | 101 * The analysis driver used to perform analysis. |
| 102 */ | 102 */ |
| 103 AnalysisDriver _driver; | 103 AnalysisDriver _driver; |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * A list containing sources for which data should not be flushed. | 106 * A list containing sources for which data should not be flushed. |
| 107 */ | 107 */ |
| 108 List<Source> _priorityOrder = Source.EMPTY_ARRAY; | 108 List<Source> _priorityOrder = <Source>[]; |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * A map from all sources for which there are futures pending to a list of | 111 * A map from all sources for which there are futures pending to a list of |
| 112 * the corresponding PendingFuture objects. These sources will be analyzed | 112 * the corresponding PendingFuture objects. These sources will be analyzed |
| 113 * in the same way as priority sources, except with higher priority. | 113 * in the same way as priority sources, except with higher priority. |
| 114 */ | 114 */ |
| 115 HashMap<AnalysisTarget, List<PendingFuture>> _pendingFutureTargets = | 115 HashMap<AnalysisTarget, List<PendingFuture>> _pendingFutureTargets = |
| 116 new HashMap<AnalysisTarget, List<PendingFuture>>(); | 116 new HashMap<AnalysisTarget, List<PendingFuture>>(); |
| 117 | 117 |
| 118 /** | 118 /** |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 bool changed = newContents != originalContents; | 952 bool changed = newContents != originalContents; |
| 953 if (newContents != null) { | 953 if (newContents != null) { |
| 954 if (newContents != originalContents) { | 954 if (newContents != originalContents) { |
| 955 _incrementalAnalysisCache = | 955 _incrementalAnalysisCache = |
| 956 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source); | 956 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source); |
| 957 if (!analysisOptions.incremental || | 957 if (!analysisOptions.incremental || |
| 958 !_tryPoorMansIncrementalResolution(source, newContents)) { | 958 !_tryPoorMansIncrementalResolution(source, newContents)) { |
| 959 _sourceChanged(source); | 959 _sourceChanged(source); |
| 960 } | 960 } |
| 961 entry.modificationTime = _contentCache.getModificationStamp(source); | 961 entry.modificationTime = _contentCache.getModificationStamp(source); |
| 962 entry.setValue(CONTENT, newContents); | 962 entry.setValue(CONTENT, newContents, cache.TargetedResult.EMPTY_LIST); |
| 963 } else { | 963 } else { |
| 964 entry.modificationTime = _contentCache.getModificationStamp(source); | 964 entry.modificationTime = _contentCache.getModificationStamp(source); |
| 965 } | 965 } |
| 966 } else if (originalContents != null) { | 966 } else if (originalContents != null) { |
| 967 _incrementalAnalysisCache = | 967 _incrementalAnalysisCache = |
| 968 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source); | 968 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source); |
| 969 changed = newContents != originalContents; | 969 changed = newContents != originalContents; |
| 970 // We are removing the overlay for the file, check if the file's | 970 // We are removing the overlay for the file, check if the file's |
| 971 // contents is the same as it was in the overlay. | 971 // contents is the same as it was in the overlay. |
| 972 try { | 972 try { |
| 973 TimestampedData<String> fileContents = getContents(source); | 973 TimestampedData<String> fileContents = getContents(source); |
| 974 String fileContentsData = fileContents.data; | 974 String fileContentsData = fileContents.data; |
| 975 if (fileContentsData == originalContents) { | 975 if (fileContentsData == originalContents) { |
| 976 entry.setValue(CONTENT, fileContentsData); | 976 entry.setValue( |
| 977 CONTENT, fileContentsData, cache.TargetedResult.EMPTY_LIST); |
| 977 entry.modificationTime = fileContents.modificationTime; | 978 entry.modificationTime = fileContents.modificationTime; |
| 978 changed = false; | 979 changed = false; |
| 979 } | 980 } |
| 980 } catch (e) {} | 981 } catch (e) {} |
| 981 // If not the same content (e.g. the file is being closed without save), | 982 // If not the same content (e.g. the file is being closed without save), |
| 982 // then force analysis. | 983 // then force analysis. |
| 983 if (changed) { | 984 if (changed) { |
| 984 _sourceChanged(source); | 985 _sourceChanged(source); |
| 985 } | 986 } |
| 986 } | 987 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 }); | 1059 }); |
| 1059 } | 1060 } |
| 1060 | 1061 |
| 1061 @override | 1062 @override |
| 1062 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { | 1063 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
| 1063 elementMap.forEach((Source librarySource, LibraryElement library) { | 1064 elementMap.forEach((Source librarySource, LibraryElement library) { |
| 1064 // | 1065 // |
| 1065 // Cache the element in the library's info. | 1066 // Cache the element in the library's info. |
| 1066 // | 1067 // |
| 1067 cache.CacheEntry entry = getCacheEntry(librarySource); | 1068 cache.CacheEntry entry = getCacheEntry(librarySource); |
| 1068 entry.setValue(BUILD_DIRECTIVES_ERRORS, AnalysisError.NO_ERRORS); | 1069 setValue(ResultDescriptor result, value) { |
| 1069 entry.setValue( | 1070 entry.setValue(result, value, cache.TargetedResult.EMPTY_LIST); |
| 1070 BUILD_FUNCTION_TYPE_ALIASES_ERRORS, AnalysisError.NO_ERRORS); | 1071 } |
| 1071 entry.setValue(BUILD_LIBRARY_ERRORS, AnalysisError.NO_ERRORS); | 1072 setValue(BUILD_DIRECTIVES_ERRORS, AnalysisError.NO_ERRORS); |
| 1073 setValue(BUILD_FUNCTION_TYPE_ALIASES_ERRORS, AnalysisError.NO_ERRORS); |
| 1074 setValue(BUILD_LIBRARY_ERRORS, AnalysisError.NO_ERRORS); |
| 1072 // CLASS_ELEMENTS | 1075 // CLASS_ELEMENTS |
| 1073 entry.setValue(COMPILATION_UNIT_ELEMENT, library.definingCompilationUnit); | 1076 setValue(COMPILATION_UNIT_ELEMENT, library.definingCompilationUnit); |
| 1074 // CONSTRUCTORS | 1077 // CONSTRUCTORS |
| 1075 // CONSTRUCTORS_ERRORS | 1078 // CONSTRUCTORS_ERRORS |
| 1076 entry.setState(CONTENT, CacheState.FLUSHED); | 1079 entry.setState(CONTENT, CacheState.FLUSHED); |
| 1077 entry.setValue(EXPORTED_LIBRARIES, Source.EMPTY_ARRAY); | 1080 setValue(EXPORTED_LIBRARIES, Source.EMPTY_ARRAY); |
| 1078 // EXPORT_SOURCE_CLOSURE | 1081 // EXPORT_SOURCE_CLOSURE |
| 1079 entry.setValue(IMPORTED_LIBRARIES, Source.EMPTY_ARRAY); | 1082 setValue(IMPORTED_LIBRARIES, Source.EMPTY_ARRAY); |
| 1080 // IMPORT_SOURCE_CLOSURE | 1083 // IMPORT_SOURCE_CLOSURE |
| 1081 entry.setValue(INCLUDED_PARTS, Source.EMPTY_ARRAY); | 1084 setValue(INCLUDED_PARTS, Source.EMPTY_ARRAY); |
| 1082 entry.setValue(IS_CLIENT, true); | 1085 setValue(IS_CLIENT, true); |
| 1083 entry.setValue(IS_LAUNCHABLE, false); | 1086 setValue(IS_LAUNCHABLE, false); |
| 1084 entry.setValue(LIBRARY_ELEMENT, library); | 1087 setValue(LIBRARY_ELEMENT, library); |
| 1085 entry.setValue(LIBRARY_ELEMENT1, library); | 1088 setValue(LIBRARY_ELEMENT1, library); |
| 1086 entry.setValue(LIBRARY_ELEMENT2, library); | 1089 setValue(LIBRARY_ELEMENT2, library); |
| 1087 entry.setValue(LIBRARY_ELEMENT3, library); | 1090 setValue(LIBRARY_ELEMENT3, library); |
| 1088 entry.setValue(LIBRARY_ELEMENT4, library); | 1091 setValue(LIBRARY_ELEMENT4, library); |
| 1089 entry.setValue(LIBRARY_ELEMENT5, library); | 1092 setValue(LIBRARY_ELEMENT5, library); |
| 1090 entry.setValue(LINE_INFO, new LineInfo(<int>[0])); | 1093 setValue(LINE_INFO, new LineInfo(<int>[0])); |
| 1091 entry.setValue(PARSE_ERRORS, AnalysisError.NO_ERRORS); | 1094 setValue(PARSE_ERRORS, AnalysisError.NO_ERRORS); |
| 1092 entry.setState(PARSED_UNIT, CacheState.FLUSHED); | 1095 entry.setState(PARSED_UNIT, CacheState.FLUSHED); |
| 1093 entry.setState(RESOLVE_TYPE_NAMES_ERRORS, CacheState.FLUSHED); | 1096 entry.setState(RESOLVE_TYPE_NAMES_ERRORS, CacheState.FLUSHED); |
| 1094 entry.setValue(SCAN_ERRORS, AnalysisError.NO_ERRORS); | 1097 setValue(SCAN_ERRORS, AnalysisError.NO_ERRORS); |
| 1095 entry.setValue(SOURCE_KIND, SourceKind.LIBRARY); | 1098 setValue(SOURCE_KIND, SourceKind.LIBRARY); |
| 1096 entry.setState(TOKEN_STREAM, CacheState.FLUSHED); | 1099 entry.setState(TOKEN_STREAM, CacheState.FLUSHED); |
| 1097 entry.setValue(UNITS, <Source>[librarySource]); | 1100 setValue(UNITS, <Source>[librarySource]); |
| 1098 | 1101 |
| 1099 LibrarySpecificUnit unit = | 1102 LibrarySpecificUnit unit = |
| 1100 new LibrarySpecificUnit(librarySource, librarySource); | 1103 new LibrarySpecificUnit(librarySource, librarySource); |
| 1101 entry = getCacheEntry(unit); | 1104 entry = getCacheEntry(unit); |
| 1102 entry.setValue(HINTS, AnalysisError.NO_ERRORS); | 1105 setValue(HINTS, AnalysisError.NO_ERRORS); |
| 1103 // dartEntry.setValue(LINTS, AnalysisError.NO_ERRORS); | 1106 // dartEntry.setValue(LINTS, AnalysisError.NO_ERRORS); |
| 1104 entry.setState(RESOLVE_REFERENCES_ERRORS, CacheState.FLUSHED); | 1107 entry.setState(RESOLVE_REFERENCES_ERRORS, CacheState.FLUSHED); |
| 1105 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED); | 1108 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED); |
| 1106 entry.setState(RESOLVED_UNIT1, CacheState.FLUSHED); | 1109 entry.setState(RESOLVED_UNIT1, CacheState.FLUSHED); |
| 1107 entry.setState(RESOLVED_UNIT2, CacheState.FLUSHED); | 1110 entry.setState(RESOLVED_UNIT2, CacheState.FLUSHED); |
| 1108 entry.setState(RESOLVED_UNIT3, CacheState.FLUSHED); | 1111 entry.setState(RESOLVED_UNIT3, CacheState.FLUSHED); |
| 1109 entry.setState(RESOLVED_UNIT4, CacheState.FLUSHED); | 1112 entry.setState(RESOLVED_UNIT4, CacheState.FLUSHED); |
| 1110 entry.setState(RESOLVED_UNIT5, CacheState.FLUSHED); | 1113 entry.setState(RESOLVED_UNIT5, CacheState.FLUSHED); |
| 1111 // USED_IMPORTED_ELEMENTS | 1114 // USED_IMPORTED_ELEMENTS |
| 1112 // USED_LOCAL_ELEMENTS | 1115 // USED_LOCAL_ELEMENTS |
| 1113 entry.setValue(VERIFY_ERRORS, AnalysisError.NO_ERRORS); | 1116 setValue(VERIFY_ERRORS, AnalysisError.NO_ERRORS); |
| 1114 }); | 1117 }); |
| 1115 | 1118 |
| 1116 cache.CacheEntry entry = getCacheEntry(AnalysisContextTarget.request); | 1119 cache.CacheEntry entry = getCacheEntry(AnalysisContextTarget.request); |
| 1117 entry.setValue(TYPE_PROVIDER, typeProvider); | 1120 entry.setValue( |
| 1121 TYPE_PROVIDER, typeProvider, cache.TargetedResult.EMPTY_LIST); |
| 1118 } | 1122 } |
| 1119 | 1123 |
| 1120 @override | 1124 @override |
| 1121 void removeListener(AnalysisListener listener) { | 1125 void removeListener(AnalysisListener listener) { |
| 1122 _listeners.remove(listener); | 1126 _listeners.remove(listener); |
| 1123 } | 1127 } |
| 1124 | 1128 |
| 1125 @override | 1129 @override |
| 1126 CompilationUnit resolveCompilationUnit( | 1130 CompilationUnit resolveCompilationUnit( |
| 1127 Source unitSource, LibraryElement library) { | 1131 Source unitSource, LibraryElement library) { |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 // if (_options.incremental) { | 1355 // if (_options.incremental) { |
| 1352 // _incrementalAnalysisCache = IncrementalAnalysisCache.update( | 1356 // _incrementalAnalysisCache = IncrementalAnalysisCache.update( |
| 1353 // _incrementalAnalysisCache, source, originalContents, contents, | 1357 // _incrementalAnalysisCache, source, originalContents, contents, |
| 1354 // offset, oldLength, newLength, _cache.get(source)); | 1358 // offset, oldLength, newLength, _cache.get(source)); |
| 1355 // } | 1359 // } |
| 1356 _sourceChanged(source); | 1360 _sourceChanged(source); |
| 1357 changed = true; | 1361 changed = true; |
| 1358 cache.CacheEntry entry = _cache.get(source); | 1362 cache.CacheEntry entry = _cache.get(source); |
| 1359 if (entry != null) { | 1363 if (entry != null) { |
| 1360 entry.modificationTime = _contentCache.getModificationStamp(source); | 1364 entry.modificationTime = _contentCache.getModificationStamp(source); |
| 1361 entry.setValue(CONTENT, contents); | 1365 entry.setValue(CONTENT, contents, cache.TargetedResult.EMPTY_LIST); |
| 1362 } | 1366 } |
| 1363 } | 1367 } |
| 1364 } else if (originalContents != null) { | 1368 } else if (originalContents != null) { |
| 1365 _incrementalAnalysisCache = | 1369 _incrementalAnalysisCache = |
| 1366 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source); | 1370 IncrementalAnalysisCache.clear(_incrementalAnalysisCache, source); |
| 1367 _sourceChanged(source); | 1371 _sourceChanged(source); |
| 1368 changed = true; | 1372 changed = true; |
| 1369 } | 1373 } |
| 1370 return changed; | 1374 return changed; |
| 1371 } | 1375 } |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 PendingFuture pendingFuture = | 2139 PendingFuture pendingFuture = |
| 2136 new PendingFuture<T>(_context, target, computeValue); | 2140 new PendingFuture<T>(_context, target, computeValue); |
| 2137 if (!pendingFuture.evaluate(entry)) { | 2141 if (!pendingFuture.evaluate(entry)) { |
| 2138 _context._pendingFutureTargets | 2142 _context._pendingFutureTargets |
| 2139 .putIfAbsent(target, () => <PendingFuture>[]) | 2143 .putIfAbsent(target, () => <PendingFuture>[]) |
| 2140 .add(pendingFuture); | 2144 .add(pendingFuture); |
| 2141 } | 2145 } |
| 2142 return pendingFuture.future; | 2146 return pendingFuture.future; |
| 2143 } | 2147 } |
| 2144 } | 2148 } |
| OLD | NEW |