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/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 * contexts. | 109 * contexts. |
| 110 */ | 110 */ |
| 111 CachePartition _privatePartition; | 111 CachePartition _privatePartition; |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * The cache in which information about the results associated with targets | 114 * The cache in which information about the results associated with targets |
| 115 * are stored. | 115 * are stored. |
| 116 */ | 116 */ |
| 117 AnalysisCache _cache; | 117 AnalysisCache _cache; |
| 118 | 118 |
| 119 @override | |
| 120 final ReentrantSynchronousStream<InvalidatedResult> onResultInvalidated = | |
| 121 new ReentrantSynchronousStream<InvalidatedResult>(); | |
| 122 | |
| 123 ReentrantSynchronousStreamSubscription onResultInvalidatedSubscription = null; | |
| 124 | |
| 119 /** | 125 /** |
| 120 * Configuration data associated with this context. | 126 * Configuration data associated with this context. |
| 121 */ | 127 */ |
| 122 final HashMap<ResultDescriptor, Object> _configurationData = | 128 final HashMap<ResultDescriptor, Object> _configurationData = |
| 123 new HashMap<ResultDescriptor, Object>(); | 129 new HashMap<ResultDescriptor, Object>(); |
| 124 | 130 |
| 125 /** | 131 /** |
| 126 * The task manager used to manage the tasks used to analyze code. | 132 * The task manager used to manage the tasks used to analyze code. |
| 127 */ | 133 */ |
| 128 TaskManager _taskManager; | 134 TaskManager _taskManager; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 return; | 420 return; |
| 415 } else if (factory.context != null) { | 421 } else if (factory.context != null) { |
| 416 throw new IllegalStateException( | 422 throw new IllegalStateException( |
| 417 "Source factories cannot be shared between contexts"); | 423 "Source factories cannot be shared between contexts"); |
| 418 } | 424 } |
| 419 if (_sourceFactory != null) { | 425 if (_sourceFactory != null) { |
| 420 _sourceFactory.context = null; | 426 _sourceFactory.context = null; |
| 421 } | 427 } |
| 422 factory.context = this; | 428 factory.context = this; |
| 423 _sourceFactory = factory; | 429 _sourceFactory = factory; |
| 430 _cache?.dispose(); | |
| 424 _cache = createCacheFromSourceFactory(factory); | 431 _cache = createCacheFromSourceFactory(factory); |
| 425 for (WorkManager workManager in workManagers) { | 432 for (WorkManager workManager in workManagers) { |
| 426 workManager.onSourceFactoryChanged(); | 433 workManager.onSourceFactoryChanged(); |
| 427 } | 434 } |
| 428 } | 435 } |
| 429 | 436 |
| 430 @override | 437 @override |
| 431 List<Source> get sources { | 438 List<Source> get sources { |
| 432 return _cache.sources.toList(); | 439 return _cache.sources.toList(); |
| 433 } | 440 } |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 throw new AnalysisException( | 678 throw new AnalysisException( |
| 672 'Cannot compute $descriptor for $target', entry.exception); | 679 'Cannot compute $descriptor for $target', entry.exception); |
| 673 } | 680 } |
| 674 return entry.getValue(descriptor); | 681 return entry.getValue(descriptor); |
| 675 } | 682 } |
| 676 | 683 |
| 677 /** | 684 /** |
| 678 * Create an analysis cache based on the given source [factory]. | 685 * Create an analysis cache based on the given source [factory]. |
| 679 */ | 686 */ |
| 680 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { | 687 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { |
| 681 if (factory == null) { | 688 AnalysisCache createCache() { |
| 682 return new AnalysisCache(<CachePartition>[_privatePartition]); | 689 if (factory == null) { |
| 690 return new AnalysisCache(<CachePartition>[_privatePartition]); | |
| 691 } | |
| 692 DartSdk sdk = factory.dartSdk; | |
| 693 if (sdk == null) { | |
| 694 return new AnalysisCache(<CachePartition>[_privatePartition]); | |
| 695 } | |
| 696 return new AnalysisCache(<CachePartition>[ | |
| 697 AnalysisEngine.instance.partitionManager.forSdk(sdk), | |
| 698 _privatePartition | |
| 699 ]); | |
| 683 } | 700 } |
| 684 DartSdk sdk = factory.dartSdk; | 701 |
| 685 if (sdk == null) { | 702 AnalysisCache cache = createCache(); |
| 686 return new AnalysisCache(<CachePartition>[_privatePartition]); | 703 if (onResultInvalidatedSubscription != null) { |
| 704 onResultInvalidatedSubscription.cancel(); | |
|
scheglov
2016/05/25 01:44:44
We could use here:
onResultInvalidatedSubscription
Brian Wilkerson
2016/05/25 14:42:33
Done
| |
| 687 } | 705 } |
| 688 AnalysisCache cache = new AnalysisCache(<CachePartition>[ | 706 onResultInvalidatedSubscription = cache.onResultInvalidated.listen((Invalida tedResult event) { |
| 689 AnalysisEngine.instance.partitionManager.forSdk(sdk), | 707 onResultInvalidated.add(event); |
| 690 _privatePartition | |
| 691 ]); | |
| 692 cache.onResultInvalidated.listen((InvalidatedResult event) { | |
| 693 StreamController<ResultChangedEvent> controller = | 708 StreamController<ResultChangedEvent> controller = |
| 694 _resultChangedControllers[event.descriptor]; | 709 _resultChangedControllers[event.descriptor]; |
| 695 if (controller != null) { | 710 if (controller != null) { |
| 696 controller.add(new ResultChangedEvent( | 711 controller.add(new ResultChangedEvent( |
| 697 this, event.entry.target, event.descriptor, event.value, false)); | 712 this, event.entry.target, event.descriptor, event.value, false)); |
| 698 } | 713 } |
| 699 }); | 714 }); |
| 700 return cache; | 715 return cache; |
| 701 } | 716 } |
| 702 | 717 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 .add(new SourcesChangedEvent.changedContent(source, newContents)); | 1087 .add(new SourcesChangedEvent.changedContent(source, newContents)); |
| 1073 } | 1088 } |
| 1074 return changed; | 1089 return changed; |
| 1075 } | 1090 } |
| 1076 | 1091 |
| 1077 /** | 1092 /** |
| 1078 * Invalidate analysis cache and notify work managers that they have work | 1093 * Invalidate analysis cache and notify work managers that they have work |
| 1079 * to do. | 1094 * to do. |
| 1080 */ | 1095 */ |
| 1081 void invalidateCachedResults() { | 1096 void invalidateCachedResults() { |
| 1097 _cache?.dispose(); | |
| 1082 _cache = createCacheFromSourceFactory(_sourceFactory); | 1098 _cache = createCacheFromSourceFactory(_sourceFactory); |
| 1083 for (WorkManager workManager in workManagers) { | 1099 for (WorkManager workManager in workManagers) { |
| 1084 workManager.onAnalysisOptionsChanged(); | 1100 workManager.onAnalysisOptionsChanged(); |
| 1085 } | 1101 } |
| 1086 } | 1102 } |
| 1087 | 1103 |
| 1088 @override | 1104 @override |
| 1089 void invalidateLibraryHints(Source librarySource) { | 1105 void invalidateLibraryHints(Source librarySource) { |
| 1090 List<Source> sources = getResult(librarySource, UNITS); | 1106 List<Source> sources = getResult(librarySource, UNITS); |
| 1091 if (sources != null) { | 1107 if (sources != null) { |
| (...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2198 } | 2214 } |
| 2199 DartSdk sdk = factory.dartSdk; | 2215 DartSdk sdk = factory.dartSdk; |
| 2200 if (sdk == null) { | 2216 if (sdk == null) { |
| 2201 throw new IllegalArgumentException( | 2217 throw new IllegalArgumentException( |
| 2202 "The source factory for an SDK analysis context must have a DartUriRes olver"); | 2218 "The source factory for an SDK analysis context must have a DartUriRes olver"); |
| 2203 } | 2219 } |
| 2204 return new AnalysisCache( | 2220 return new AnalysisCache( |
| 2205 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); | 2221 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); |
| 2206 } | 2222 } |
| 2207 } | 2223 } |
| OLD | NEW |