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'; |
11 import 'package:analyzer/src/context/cache.dart' as cache; | 11 import 'package:analyzer/src/context/cache.dart' as cache; |
12 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
13 import 'package:analyzer/src/generated/constant.dart'; | 13 import 'package:analyzer/src/generated/constant.dart'; |
14 import 'package:analyzer/src/generated/element.dart'; | 14 import 'package:analyzer/src/generated/element.dart'; |
15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart' hide WorkManager; |
16 import 'package:analyzer/src/generated/error.dart'; | 16 import 'package:analyzer/src/generated/error.dart'; |
17 import 'package:analyzer/src/generated/html.dart' as ht; | 17 import 'package:analyzer/src/generated/html.dart' as ht; |
18 import 'package:analyzer/src/generated/java_core.dart'; | 18 import 'package:analyzer/src/generated/java_core.dart'; |
19 import 'package:analyzer/src/generated/java_engine.dart'; | 19 import 'package:analyzer/src/generated/java_engine.dart'; |
20 import 'package:analyzer/src/generated/resolver.dart'; | 20 import 'package:analyzer/src/generated/resolver.dart'; |
21 import 'package:analyzer/src/generated/scanner.dart'; | 21 import 'package:analyzer/src/generated/scanner.dart'; |
22 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; | 22 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; |
23 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
24 import 'package:analyzer/src/generated/utilities_collection.dart'; | 24 import 'package:analyzer/src/generated/utilities_collection.dart'; |
25 import 'package:analyzer/src/task/dart.dart'; | 25 import 'package:analyzer/src/task/dart.dart'; |
| 26 import 'package:analyzer/src/task/dart_work_manager.dart'; |
26 import 'package:analyzer/src/task/driver.dart'; | 27 import 'package:analyzer/src/task/driver.dart'; |
27 import 'package:analyzer/src/task/manager.dart'; | 28 import 'package:analyzer/src/task/manager.dart'; |
28 import 'package:analyzer/task/dart.dart'; | 29 import 'package:analyzer/task/dart.dart'; |
29 import 'package:analyzer/task/general.dart'; | 30 import 'package:analyzer/task/general.dart'; |
30 import 'package:analyzer/task/model.dart'; | 31 import 'package:analyzer/task/model.dart'; |
31 | 32 |
32 /** | 33 /** |
33 * Type of callback functions used by PendingFuture. Functions of this type | 34 * Type of callback functions used by PendingFuture. Functions of this type |
34 * should perform a computation based on the data in [entry] and return it. If | 35 * should perform a computation based on the data in [entry] and return it. If |
35 * the computation can't be performed yet because more analysis is needed, | 36 * the computation can't be performed yet because more analysis is needed, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 * are stored. | 92 * are stored. |
92 */ | 93 */ |
93 cache.AnalysisCache _cache; | 94 cache.AnalysisCache _cache; |
94 | 95 |
95 /** | 96 /** |
96 * The task manager used to manage the tasks used to analyze code. | 97 * The task manager used to manage the tasks used to analyze code. |
97 */ | 98 */ |
98 TaskManager _taskManager; | 99 TaskManager _taskManager; |
99 | 100 |
100 /** | 101 /** |
| 102 * The [DartWorkManager] instance that performs Dart specific scheduling. |
| 103 */ |
| 104 DartWorkManager dartWorkManager; |
| 105 |
| 106 /** |
101 * The analysis driver used to perform analysis. | 107 * The analysis driver used to perform analysis. |
102 */ | 108 */ |
103 AnalysisDriver _driver; | 109 AnalysisDriver driver; |
104 | 110 |
105 /** | 111 /** |
106 * A list containing sources for which data should not be flushed. | 112 * A list containing sources for which data should not be flushed. |
107 */ | 113 */ |
108 List<Source> _priorityOrder = <Source>[]; | 114 List<Source> _priorityOrder = <Source>[]; |
109 | 115 |
110 /** | 116 /** |
111 * A map from all sources for which there are futures pending to a list of | 117 * 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 | 118 * the corresponding PendingFuture objects. These sources will be analyzed |
113 * in the same way as priority sources, except with higher priority. | 119 * in the same way as priority sources, except with higher priority. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 */ | 183 */ |
178 LibraryResolverFactory libraryResolverFactory; | 184 LibraryResolverFactory libraryResolverFactory; |
179 | 185 |
180 /** | 186 /** |
181 * Initialize a newly created analysis context. | 187 * Initialize a newly created analysis context. |
182 */ | 188 */ |
183 AnalysisContextImpl() { | 189 AnalysisContextImpl() { |
184 _privatePartition = new cache.UniversalCachePartition(this); | 190 _privatePartition = new cache.UniversalCachePartition(this); |
185 _cache = createCacheFromSourceFactory(null); | 191 _cache = createCacheFromSourceFactory(null); |
186 _taskManager = AnalysisEngine.instance.taskManager; | 192 _taskManager = AnalysisEngine.instance.taskManager; |
187 _driver = new AnalysisDriver(_taskManager, this); | 193 // TODO(scheglov) Get WorkManager(Factory)(s) from plugins. |
| 194 dartWorkManager = new DartWorkManager(this); |
| 195 driver = |
| 196 new AnalysisDriver(_taskManager, <WorkManager>[dartWorkManager], this); |
188 _onSourcesChangedController = | 197 _onSourcesChangedController = |
189 new StreamController<SourcesChangedEvent>.broadcast(); | 198 new StreamController<SourcesChangedEvent>.broadcast(); |
190 } | 199 } |
191 | 200 |
192 @override | 201 @override |
193 cache.AnalysisCache get analysisCache => _cache; | 202 cache.AnalysisCache get analysisCache => _cache; |
194 | 203 |
195 @override | 204 @override |
196 AnalysisOptions get analysisOptions => _options; | 205 AnalysisOptions get analysisOptions => _options; |
197 | 206 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 .forEach((Source source, ChangeSet_ContentChange change) { | 497 .forEach((Source source, ChangeSet_ContentChange change) { |
489 _contentRangeChanged(source, change.contents, change.offset, | 498 _contentRangeChanged(source, change.contents, change.offset, |
490 change.oldLength, change.newLength); | 499 change.oldLength, change.newLength); |
491 }); | 500 }); |
492 for (Source source in changeSet.deletedSources) { | 501 for (Source source in changeSet.deletedSources) { |
493 _sourceDeleted(source); | 502 _sourceDeleted(source); |
494 } | 503 } |
495 for (Source source in removedSources) { | 504 for (Source source in removedSources) { |
496 _sourceRemoved(source); | 505 _sourceRemoved(source); |
497 } | 506 } |
| 507 dartWorkManager.applyChange( |
| 508 changeSet.addedSources, changeSet.changedSources, removedSources); |
498 _onSourcesChangedController.add(new SourcesChangedEvent(changeSet)); | 509 _onSourcesChangedController.add(new SourcesChangedEvent(changeSet)); |
499 } | 510 } |
500 | 511 |
501 @override | 512 @override |
502 String computeDocumentationComment(Element element) { | 513 String computeDocumentationComment(Element element) { |
503 if (element == null) { | 514 if (element == null) { |
504 return null; | 515 return null; |
505 } | 516 } |
506 Source source = element.source; | 517 Source source = element.source; |
507 if (source == null) { | 518 if (source == null) { |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 if (!AnalysisEngine.isHtmlFileName(source.shortName)) { | 1068 if (!AnalysisEngine.isHtmlFileName(source.shortName)) { |
1058 return null; | 1069 return null; |
1059 } | 1070 } |
1060 // TODO(brianwilkerson) Implement HTML analysis. | 1071 // TODO(brianwilkerson) Implement HTML analysis. |
1061 return null; //_computeResult(source, null); | 1072 return null; //_computeResult(source, null); |
1062 } | 1073 } |
1063 | 1074 |
1064 @override | 1075 @override |
1065 AnalysisResult performAnalysisTask() { | 1076 AnalysisResult performAnalysisTask() { |
1066 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() { | 1077 return PerformanceStatistics.performAnaysis.makeCurrentWhile(() { |
1067 bool done = !_driver.performAnalysisTask(); | 1078 bool done = !driver.performAnalysisTask(); |
1068 if (done) { | 1079 if (done) { |
1069 done = !_validateCacheConsistency(); | 1080 done = !_validateCacheConsistency(); |
1070 } | 1081 } |
1071 List<ChangeNotice> notices = _getChangeNotices(done); | 1082 List<ChangeNotice> notices = _getChangeNotices(done); |
1072 if (notices != null) { | 1083 if (notices != null) { |
1073 int noticeCount = notices.length; | 1084 int noticeCount = notices.length; |
1074 for (int i = 0; i < noticeCount; i++) { | 1085 for (int i = 0; i < noticeCount; i++) { |
1075 ChangeNotice notice = notices[i]; | 1086 ChangeNotice notice = notices[i]; |
1076 _notifyErrors(notice.source, notice.errors, notice.lineInfo); | 1087 _notifyErrors(notice.source, notice.errors, notice.lineInfo); |
1077 } | 1088 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 int oldLength, int newLength) { | 1189 int oldLength, int newLength) { |
1179 if (_contentRangeChanged(source, contents, offset, oldLength, newLength)) { | 1190 if (_contentRangeChanged(source, contents, offset, oldLength, newLength)) { |
1180 _onSourcesChangedController.add(new SourcesChangedEvent.changedRange( | 1191 _onSourcesChangedController.add(new SourcesChangedEvent.changedRange( |
1181 source, contents, offset, oldLength, newLength)); | 1192 source, contents, offset, oldLength, newLength)); |
1182 } | 1193 } |
1183 } | 1194 } |
1184 | 1195 |
1185 @override | 1196 @override |
1186 void setContents(Source source, String contents) { | 1197 void setContents(Source source, String contents) { |
1187 _contentsChanged(source, contents, true); | 1198 _contentsChanged(source, contents, true); |
| 1199 dartWorkManager.applyChange( |
| 1200 Source.EMPTY_LIST, <Source>[source], Source.EMPTY_LIST); |
1188 } | 1201 } |
1189 | 1202 |
1190 @override | 1203 @override |
1191 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, | 1204 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, |
1192 DataDescriptor rowDesc, CacheState state)) { | 1205 DataDescriptor rowDesc, CacheState state)) { |
1193 // TODO(brianwilkerson) Figure out where this is used and adjust the call | 1206 // TODO(brianwilkerson) Figure out where this is used and adjust the call |
1194 // sites to use CacheEntry's. | 1207 // sites to use CacheEntry's. |
1195 // bool hintsEnabled = _options.hint; | 1208 // bool hintsEnabled = _options.hint; |
1196 // bool lintsEnabled = _options.lint; | 1209 // bool lintsEnabled = _options.lint; |
1197 // MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator()
; | 1210 // MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator()
; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 return SourcePriority.NORMAL_PART; | 1314 return SourcePriority.NORMAL_PART; |
1302 } | 1315 } |
1303 return SourcePriority.UNKNOWN; | 1316 return SourcePriority.UNKNOWN; |
1304 } | 1317 } |
1305 | 1318 |
1306 Object /*V*/ _computeResult( | 1319 Object /*V*/ _computeResult( |
1307 AnalysisTarget target, ResultDescriptor /*<V>*/ descriptor) { | 1320 AnalysisTarget target, ResultDescriptor /*<V>*/ descriptor) { |
1308 cache.CacheEntry entry = getCacheEntry(target); | 1321 cache.CacheEntry entry = getCacheEntry(target); |
1309 CacheState state = entry.getState(descriptor); | 1322 CacheState state = entry.getState(descriptor); |
1310 if (state == CacheState.FLUSHED || state == CacheState.INVALID) { | 1323 if (state == CacheState.FLUSHED || state == CacheState.INVALID) { |
1311 _driver.computeResult(target, descriptor); | 1324 driver.computeResult(target, descriptor); |
1312 } | 1325 } |
1313 state = entry.getState(descriptor); | 1326 state = entry.getState(descriptor); |
1314 if (state == CacheState.ERROR) { | 1327 if (state == CacheState.ERROR) { |
1315 throw new AnalysisException( | 1328 throw new AnalysisException( |
1316 'Cannot compute $descriptor for $target', entry.exception); | 1329 'Cannot compute $descriptor for $target', entry.exception); |
1317 } | 1330 } |
1318 return entry.getValue(descriptor); | 1331 return entry.getValue(descriptor); |
1319 } | 1332 } |
1320 | 1333 |
1321 /** | 1334 /** |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 PendingFuture pendingFuture = | 2084 PendingFuture pendingFuture = |
2072 new PendingFuture<T>(_context, target, computeValue); | 2085 new PendingFuture<T>(_context, target, computeValue); |
2073 if (!pendingFuture.evaluate(entry)) { | 2086 if (!pendingFuture.evaluate(entry)) { |
2074 _context._pendingFutureTargets | 2087 _context._pendingFutureTargets |
2075 .putIfAbsent(target, () => <PendingFuture>[]) | 2088 .putIfAbsent(target, () => <PendingFuture>[]) |
2076 .add(pendingFuture); | 2089 .add(pendingFuture); |
2077 } | 2090 } |
2078 return pendingFuture.future; | 2091 return pendingFuture.future; |
2079 } | 2092 } |
2080 } | 2093 } |
OLD | NEW |