Chromium Code Reviews| 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/instrumentation/instrumentation.dart'; | 10 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 * The [TypeProvider] for this context, `null` if not yet created. | 160 * The [TypeProvider] for this context, `null` if not yet created. |
| 161 */ | 161 */ |
| 162 TypeProvider _typeProvider; | 162 TypeProvider _typeProvider; |
| 163 | 163 |
| 164 /** | 164 /** |
| 165 * The controller for sending [SourcesChangedEvent]s. | 165 * The controller for sending [SourcesChangedEvent]s. |
| 166 */ | 166 */ |
| 167 StreamController<SourcesChangedEvent> _onSourcesChangedController; | 167 StreamController<SourcesChangedEvent> _onSourcesChangedController; |
| 168 | 168 |
| 169 /** | 169 /** |
| 170 * A subscription for a stream of events indicating when files are (and are | |
| 171 * not) being implicitly analyzed. | |
| 172 */ | |
| 173 StreamController<AnalyzedSourcesEvent> _analyzedSourcesController; | |
|
Paul Berry
2015/07/15 19:50:01
How about naming this "_implicitlyAnalyzedSourcesC
| |
| 174 | |
| 175 /** | |
| 170 * The listeners that are to be notified when various analysis results are | 176 * The listeners that are to be notified when various analysis results are |
| 171 * produced in this context. | 177 * produced in this context. |
| 172 */ | 178 */ |
| 173 List<AnalysisListener> _listeners = new List<AnalysisListener>(); | 179 List<AnalysisListener> _listeners = new List<AnalysisListener>(); |
| 174 | 180 |
| 175 /** | 181 /** |
| 176 * The most recently incrementally resolved source, or `null` when it was | 182 * The most recently incrementally resolved source, or `null` when it was |
| 177 * already validated, or the most recent change was not incrementally resolved . | 183 * already validated, or the most recent change was not incrementally resolved . |
| 178 */ | 184 */ |
| 179 Source incrementalResolutionValidation_lastUnitSource; | 185 Source incrementalResolutionValidation_lastUnitSource; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 _privatePartition = new UniversalCachePartition(this); | 219 _privatePartition = new UniversalCachePartition(this); |
| 214 _cache = createCacheFromSourceFactory(null); | 220 _cache = createCacheFromSourceFactory(null); |
| 215 _taskManager = AnalysisEngine.instance.taskManager; | 221 _taskManager = AnalysisEngine.instance.taskManager; |
| 216 // TODO(scheglov) Get WorkManager(Factory)(s) from plugins. | 222 // TODO(scheglov) Get WorkManager(Factory)(s) from plugins. |
| 217 dartWorkManager = new DartWorkManager(this); | 223 dartWorkManager = new DartWorkManager(this); |
| 218 htmlWorkManager = new HtmlWorkManager(this); | 224 htmlWorkManager = new HtmlWorkManager(this); |
| 219 driver = new AnalysisDriver( | 225 driver = new AnalysisDriver( |
| 220 _taskManager, <WorkManager>[dartWorkManager, htmlWorkManager], this); | 226 _taskManager, <WorkManager>[dartWorkManager, htmlWorkManager], this); |
| 221 _onSourcesChangedController = | 227 _onSourcesChangedController = |
| 222 new StreamController<SourcesChangedEvent>.broadcast(); | 228 new StreamController<SourcesChangedEvent>.broadcast(); |
| 229 _analyzedSourcesController = | |
| 230 new StreamController<AnalyzedSourcesEvent>.broadcast(); | |
| 223 } | 231 } |
| 224 | 232 |
| 225 @override | 233 @override |
| 226 AnalysisCache get analysisCache => _cache; | 234 AnalysisCache get analysisCache => _cache; |
| 227 | 235 |
| 228 @override | 236 @override |
| 229 AnalysisOptions get analysisOptions => _options; | 237 AnalysisOptions get analysisOptions => _options; |
| 230 | 238 |
| 231 @override | 239 @override |
| 232 void set analysisOptions(AnalysisOptions options) { | 240 void set analysisOptions(AnalysisOptions options) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 _priorityOrder = Source.EMPTY_LIST; | 282 _priorityOrder = Source.EMPTY_LIST; |
| 275 } else { | 283 } else { |
| 276 _priorityOrder = sources; | 284 _priorityOrder = sources; |
| 277 } | 285 } |
| 278 } | 286 } |
| 279 dartWorkManager.applyPriorityTargets(_priorityOrder); | 287 dartWorkManager.applyPriorityTargets(_priorityOrder); |
| 280 htmlWorkManager.applyPriorityTargets(_priorityOrder); | 288 htmlWorkManager.applyPriorityTargets(_priorityOrder); |
| 281 } | 289 } |
| 282 | 290 |
| 283 @override | 291 @override |
| 292 Stream<AnalyzedSourcesEvent> get analyzedSources => | |
| 293 _analyzedSourcesController.stream; | |
| 294 | |
| 295 @override | |
| 284 set contentCache(ContentCache value) { | 296 set contentCache(ContentCache value) { |
| 285 _contentCache = value; | 297 _contentCache = value; |
| 286 } | 298 } |
| 287 | 299 |
| 288 @override | 300 @override |
| 289 DeclaredVariables get declaredVariables => _declaredVariables; | 301 DeclaredVariables get declaredVariables => _declaredVariables; |
| 290 | 302 |
| 291 @override | 303 @override |
| 292 List<AnalysisTarget> get explicitTargets { | 304 List<AnalysisTarget> get explicitTargets { |
| 293 List<AnalysisTarget> targets = <AnalysisTarget>[]; | 305 List<AnalysisTarget> targets = <AnalysisTarget>[]; |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 | 733 |
| 722 @override | 734 @override |
| 723 CacheEntry getCacheEntry(AnalysisTarget target) { | 735 CacheEntry getCacheEntry(AnalysisTarget target) { |
| 724 CacheEntry entry = _cache.get(target); | 736 CacheEntry entry = _cache.get(target); |
| 725 if (entry == null) { | 737 if (entry == null) { |
| 726 entry = new CacheEntry(target); | 738 entry = new CacheEntry(target); |
| 727 if (target is Source) { | 739 if (target is Source) { |
| 728 entry.modificationTime = getModificationStamp(target); | 740 entry.modificationTime = getModificationStamp(target); |
| 729 } | 741 } |
| 730 _cache.put(entry); | 742 _cache.put(entry); |
| 743 if (target is Source) { | |
| 744 _analyzedSourcesController.add(new AnalyzedSourcesEvent(target, true)); | |
| 745 } | |
| 731 } | 746 } |
| 732 return entry; | 747 return entry; |
| 733 } | 748 } |
| 734 | 749 |
| 735 @override | 750 @override |
| 736 CompilationUnitElement getCompilationUnitElement( | 751 CompilationUnitElement getCompilationUnitElement( |
| 737 Source unitSource, Source librarySource) { | 752 Source unitSource, Source librarySource) { |
| 738 AnalysisTarget target = new LibrarySpecificUnit(librarySource, unitSource); | 753 AnalysisTarget target = new LibrarySpecificUnit(librarySource, unitSource); |
| 739 return _cache.getValue(target, COMPILATION_UNIT_ELEMENT); | 754 return _cache.getValue(target, COMPILATION_UNIT_ELEMENT); |
| 740 } | 755 } |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1212 } | 1227 } |
| 1213 } | 1228 } |
| 1214 } | 1229 } |
| 1215 for (Source source in changedSources) { | 1230 for (Source source in changedSources) { |
| 1216 _sourceChanged(source); | 1231 _sourceChanged(source); |
| 1217 } | 1232 } |
| 1218 int removalCount = 0; | 1233 int removalCount = 0; |
| 1219 for (Source source in missingSources) { | 1234 for (Source source in missingSources) { |
| 1220 if (getLibrariesContaining(source).isEmpty && | 1235 if (getLibrariesContaining(source).isEmpty && |
| 1221 getLibrariesDependingOn(source).isEmpty) { | 1236 getLibrariesDependingOn(source).isEmpty) { |
| 1222 _cache.remove(source); | 1237 _removeFromCache(source); |
| 1223 removalCount++; | 1238 removalCount++; |
| 1224 } | 1239 } |
| 1225 } | 1240 } |
| 1226 int consistencyCheckEnd = JavaSystem.nanoTime(); | 1241 int consistencyCheckEnd = JavaSystem.nanoTime(); |
| 1227 if (changedSources.length > 0 || missingSources.length > 0) { | 1242 if (changedSources.length > 0 || missingSources.length > 0) { |
| 1228 StringBuffer buffer = new StringBuffer(); | 1243 StringBuffer buffer = new StringBuffer(); |
| 1229 buffer.write("Consistency check took "); | 1244 buffer.write("Consistency check took "); |
| 1230 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0); | 1245 buffer.write((consistencyCheckEnd - consistencyCheckStart) / 1000000.0); |
| 1231 buffer.writeln(" ms and found"); | 1246 buffer.writeln(" ms and found"); |
| 1232 buffer.write(" "); | 1247 buffer.write(" "); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1420 /** | 1435 /** |
| 1421 * Create a cache entry for the given [source]. The source was explicitly | 1436 * Create a cache entry for the given [source]. The source was explicitly |
| 1422 * added to this context if [explicitlyAdded] is `true`. Return the cache | 1437 * added to this context if [explicitlyAdded] is `true`. Return the cache |
| 1423 * entry that was created. | 1438 * entry that was created. |
| 1424 */ | 1439 */ |
| 1425 CacheEntry _createCacheEntry(Source source, bool explicitlyAdded) { | 1440 CacheEntry _createCacheEntry(Source source, bool explicitlyAdded) { |
| 1426 CacheEntry entry = new CacheEntry(source); | 1441 CacheEntry entry = new CacheEntry(source); |
| 1427 entry.modificationTime = getModificationStamp(source); | 1442 entry.modificationTime = getModificationStamp(source); |
| 1428 entry.explicitlyAdded = explicitlyAdded; | 1443 entry.explicitlyAdded = explicitlyAdded; |
| 1429 _cache.put(entry); | 1444 _cache.put(entry); |
| 1445 if (!explicitlyAdded) { | |
| 1446 _analyzedSourcesController.add(new AnalyzedSourcesEvent(source, true)); | |
| 1447 } | |
| 1430 return entry; | 1448 return entry; |
| 1431 } | 1449 } |
| 1432 | 1450 |
| 1433 /** | 1451 /** |
| 1434 * Return a list containing all of the cache entries for targets associated | 1452 * Return a list containing all of the cache entries for targets associated |
| 1435 * with the given [source]. | 1453 * with the given [source]. |
| 1436 */ | 1454 */ |
| 1437 List<CacheEntry> _entriesFor(Source source) { | 1455 List<CacheEntry> _entriesFor(Source source) { |
| 1438 List<CacheEntry> entries = <CacheEntry>[]; | 1456 List<CacheEntry> entries = <CacheEntry>[]; |
| 1439 MapIterator<AnalysisTarget, CacheEntry> iterator = _cache.iterator(); | 1457 MapIterator<AnalysisTarget, CacheEntry> iterator = _cache.iterator(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1630 * given [source] has been updated to the given [errors]. | 1648 * given [source] has been updated to the given [errors]. |
| 1631 */ | 1649 */ |
| 1632 void _notifyErrors( | 1650 void _notifyErrors( |
| 1633 Source source, List<AnalysisError> errors, LineInfo lineInfo) { | 1651 Source source, List<AnalysisError> errors, LineInfo lineInfo) { |
| 1634 int count = _listeners.length; | 1652 int count = _listeners.length; |
| 1635 for (int i = 0; i < count; i++) { | 1653 for (int i = 0; i < count; i++) { |
| 1636 _listeners[i].computedErrors(this, source, errors, lineInfo); | 1654 _listeners[i].computedErrors(this, source, errors, lineInfo); |
| 1637 } | 1655 } |
| 1638 } | 1656 } |
| 1639 | 1657 |
| 1658 void _removeFromCache(Source source) { | |
| 1659 CacheEntry entry = _cache.remove(source); | |
| 1660 if (entry != null && entry.explicitlyAdded) { | |
| 1661 _analyzedSourcesController.add(new AnalyzedSourcesEvent(source, false)); | |
| 1662 } | |
| 1663 } | |
| 1664 | |
| 1640 /** | 1665 /** |
| 1641 * Remove the given [source] from the priority order if it is in the list. | 1666 * Remove the given [source] from the priority order if it is in the list. |
| 1642 */ | 1667 */ |
| 1643 void _removeFromPriorityOrder(Source source) { | 1668 void _removeFromPriorityOrder(Source source) { |
| 1644 int count = _priorityOrder.length; | 1669 int count = _priorityOrder.length; |
| 1645 List<Source> newOrder = <Source>[]; | 1670 List<Source> newOrder = <Source>[]; |
| 1646 for (int i = 0; i < count; i++) { | 1671 for (int i = 0; i < count; i++) { |
| 1647 if (_priorityOrder[i] != source) { | 1672 if (_priorityOrder[i] != source) { |
| 1648 newOrder.add(_priorityOrder[i]); | 1673 newOrder.add(_priorityOrder[i]); |
| 1649 } | 1674 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1762 // new AnalysisException("This source was marked as being deleted"), | 1787 // new AnalysisException("This source was marked as being deleted"), |
| 1763 // null)); | 1788 // null)); |
| 1764 // } | 1789 // } |
| 1765 _removeFromPriorityOrder(source); | 1790 _removeFromPriorityOrder(source); |
| 1766 } | 1791 } |
| 1767 | 1792 |
| 1768 /** | 1793 /** |
| 1769 * Record that the given [source] has been removed. | 1794 * Record that the given [source] has been removed. |
| 1770 */ | 1795 */ |
| 1771 void _sourceRemoved(Source source) { | 1796 void _sourceRemoved(Source source) { |
| 1772 _cache.remove(source); | 1797 _removeFromCache(source); |
| 1773 _removeFromPriorityOrder(source); | 1798 _removeFromPriorityOrder(source); |
| 1774 } | 1799 } |
| 1775 | 1800 |
| 1776 /** | 1801 /** |
| 1777 * TODO(scheglov) A hackish, limited incremental resolution implementation. | 1802 * TODO(scheglov) A hackish, limited incremental resolution implementation. |
| 1778 */ | 1803 */ |
| 1779 bool _tryPoorMansIncrementalResolution(Source unitSource, String newCode) { | 1804 bool _tryPoorMansIncrementalResolution(Source unitSource, String newCode) { |
| 1780 return PerformanceStatistics.incrementalAnalysis.makeCurrentWhile(() { | 1805 return PerformanceStatistics.incrementalAnalysis.makeCurrentWhile(() { |
| 1781 incrementalResolutionValidation_lastUnitSource = null; | 1806 incrementalResolutionValidation_lastUnitSource = null; |
| 1782 incrementalResolutionValidation_lastLibrarySource = null; | 1807 incrementalResolutionValidation_lastLibrarySource = null; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2022 new PendingFuture<T>(_context, target, computeValue); | 2047 new PendingFuture<T>(_context, target, computeValue); |
| 2023 if (!pendingFuture.evaluate(entry)) { | 2048 if (!pendingFuture.evaluate(entry)) { |
| 2024 _context._pendingFutureTargets | 2049 _context._pendingFutureTargets |
| 2025 .putIfAbsent(target, () => <PendingFuture>[]) | 2050 .putIfAbsent(target, () => <PendingFuture>[]) |
| 2026 .add(pendingFuture); | 2051 .add(pendingFuture); |
| 2027 scheduleComputation(); | 2052 scheduleComputation(); |
| 2028 } | 2053 } |
| 2029 return pendingFuture.future; | 2054 return pendingFuture.future; |
| 2030 } | 2055 } |
| 2031 } | 2056 } |
| OLD | NEW |