| 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.cache; | 5 library analyzer.src.context.cache; |
| 6 | 6 |
| 7 import 'dart:async'; |
| 7 import 'dart:collection'; | 8 import 'dart:collection'; |
| 8 | 9 |
| 9 import 'package:analyzer/src/generated/engine.dart' | 10 import 'package:analyzer/src/generated/engine.dart' |
| 10 show AnalysisEngine, CacheState, InternalAnalysisContext, RetentionPriority; | 11 show AnalysisEngine, CacheState, InternalAnalysisContext, RetentionPriority; |
| 11 import 'package:analyzer/src/generated/java_engine.dart'; | 12 import 'package:analyzer/src/generated/java_engine.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 13 import 'package:analyzer/src/generated/utilities_collection.dart'; | 14 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 14 import 'package:analyzer/src/generated/utilities_general.dart'; | 15 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 15 import 'package:analyzer/src/task/model.dart'; | 16 import 'package:analyzer/src/task/model.dart'; |
| 16 import 'package:analyzer/task/model.dart'; | 17 import 'package:analyzer/task/model.dart'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 29 * the content of the cache is modified. | 30 * the content of the cache is modified. |
| 30 */ | 31 */ |
| 31 static bool _TRACE_CHANGES = false; | 32 static bool _TRACE_CHANGES = false; |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * An array containing the partitions of which this cache is comprised. | 35 * An array containing the partitions of which this cache is comprised. |
| 35 */ | 36 */ |
| 36 final List<CachePartition> _partitions; | 37 final List<CachePartition> _partitions; |
| 37 | 38 |
| 38 /** | 39 /** |
| 40 * The [StreamController] reporting [InvalidatedResult]s. |
| 41 */ |
| 42 final StreamController<InvalidatedResult> _onResultInvalidated = |
| 43 new StreamController<InvalidatedResult>.broadcast(sync: true); |
| 44 |
| 45 /** |
| 39 * Initialize a newly created cache to have the given [partitions]. The | 46 * Initialize a newly created cache to have the given [partitions]. The |
| 40 * partitions will be searched in the order in which they appear in the array, | 47 * partitions will be searched in the order in which they appear in the array, |
| 41 * so the most specific partition (usually an [SdkCachePartition]) should be | 48 * so the most specific partition (usually an [SdkCachePartition]) should be |
| 42 * first and the most general (usually a [UniversalCachePartition]) last. | 49 * first and the most general (usually a [UniversalCachePartition]) last. |
| 43 */ | 50 */ |
| 44 AnalysisCache(this._partitions); | 51 AnalysisCache(this._partitions) { |
| 52 for (CachePartition partition in _partitions) { |
| 53 partition.onResultInvalidated.listen((InvalidatedResult event) { |
| 54 _onResultInvalidated.add(event); |
| 55 }); |
| 56 } |
| 57 } |
| 58 |
| 59 /** |
| 60 * Return the stream that is notified when a value is invalidated. |
| 61 */ |
| 62 Stream<InvalidatedResult> get onResultInvalidated => |
| 63 _onResultInvalidated.stream; |
| 45 | 64 |
| 46 // TODO(brianwilkerson) Implement or delete this. | 65 // TODO(brianwilkerson) Implement or delete this. |
| 47 // /** | 66 // /** |
| 48 // * Return information about each of the partitions in this cache. | 67 // * Return information about each of the partitions in this cache. |
| 49 // */ | 68 // */ |
| 50 // List<AnalysisContextStatistics_PartitionData> get partitionData { | 69 // List<AnalysisContextStatistics_PartitionData> get partitionData { |
| 51 // int count = _partitions.length; | 70 // int count = _partitions.length; |
| 52 // List<AnalysisContextStatistics_PartitionData> data = | 71 // List<AnalysisContextStatistics_PartitionData> data = |
| 53 // new List<AnalysisContextStatistics_PartitionData>(count); | 72 // new List<AnalysisContextStatistics_PartitionData>(count); |
| 54 // for (int i = 0; i < count; i++) { | 73 // for (int i = 0; i < count; i++) { |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 CacheEntry entry = _partition.get(dependentResult.target); | 512 CacheEntry entry = _partition.get(dependentResult.target); |
| 494 if (entry != null) { | 513 if (entry != null) { |
| 495 entry._invalidate(dependentResult.result); | 514 entry._invalidate(dependentResult.result); |
| 496 } | 515 } |
| 497 }); | 516 }); |
| 498 // If empty, remove the entry altogether. | 517 // If empty, remove the entry altogether. |
| 499 if (_resultMap.isEmpty) { | 518 if (_resultMap.isEmpty) { |
| 500 _partition._targetMap.remove(target); | 519 _partition._targetMap.remove(target); |
| 501 _partition._removeIfSource(target); | 520 _partition._removeIfSource(target); |
| 502 } | 521 } |
| 522 // Notify controller. |
| 523 _partition._onResultInvalidated |
| 524 .add(new InvalidatedResult(this, descriptor)); |
| 503 } | 525 } |
| 504 | 526 |
| 505 /** | 527 /** |
| 506 * Invalidates all the results of this entry, with propagation. | 528 * Invalidates all the results of this entry, with propagation. |
| 507 */ | 529 */ |
| 508 void _invalidateAll() { | 530 void _invalidateAll() { |
| 509 List<ResultDescriptor> results = _resultMap.keys.toList(); | 531 List<ResultDescriptor> results = _resultMap.keys.toList(); |
| 510 for (ResultDescriptor result in results) { | 532 for (ResultDescriptor result in results) { |
| 511 _invalidate(result); | 533 _invalidate(result); |
| 512 } | 534 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 */ | 759 */ |
| 738 final InternalAnalysisContext context; | 760 final InternalAnalysisContext context; |
| 739 | 761 |
| 740 /** | 762 /** |
| 741 * A table mapping caching policies to the cache flush managers. | 763 * A table mapping caching policies to the cache flush managers. |
| 742 */ | 764 */ |
| 743 final HashMap<ResultCachingPolicy, CacheFlushManager> _flushManagerMap = | 765 final HashMap<ResultCachingPolicy, CacheFlushManager> _flushManagerMap = |
| 744 new HashMap<ResultCachingPolicy, CacheFlushManager>(); | 766 new HashMap<ResultCachingPolicy, CacheFlushManager>(); |
| 745 | 767 |
| 746 /** | 768 /** |
| 769 * The [StreamController] reporting [InvalidatedResult]s. |
| 770 */ |
| 771 final StreamController<InvalidatedResult> _onResultInvalidated = |
| 772 new StreamController<InvalidatedResult>.broadcast(sync: true); |
| 773 |
| 774 /** |
| 747 * A table mapping the targets belonging to this partition to the information | 775 * A table mapping the targets belonging to this partition to the information |
| 748 * known about those targets. | 776 * known about those targets. |
| 749 */ | 777 */ |
| 750 HashMap<AnalysisTarget, CacheEntry> _targetMap = | 778 HashMap<AnalysisTarget, CacheEntry> _targetMap = |
| 751 new HashMap<AnalysisTarget, CacheEntry>(); | 779 new HashMap<AnalysisTarget, CacheEntry>(); |
| 752 | 780 |
| 753 /** | 781 /** |
| 754 * A set of the [Source] targets. | 782 * A set of the [Source] targets. |
| 755 */ | 783 */ |
| 756 final HashSet<Source> _sources = new HashSet<Source>(); | 784 final HashSet<Source> _sources = new HashSet<Source>(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 769 /** | 797 /** |
| 770 * Return a table mapping the targets known to the context to the information | 798 * Return a table mapping the targets known to the context to the information |
| 771 * known about the target. | 799 * known about the target. |
| 772 * | 800 * |
| 773 * <b>Note:</b> This method is only visible for use by [AnalysisCache] and | 801 * <b>Note:</b> This method is only visible for use by [AnalysisCache] and |
| 774 * should not be used for any other purpose. | 802 * should not be used for any other purpose. |
| 775 */ | 803 */ |
| 776 Map<AnalysisTarget, CacheEntry> get map => _targetMap; | 804 Map<AnalysisTarget, CacheEntry> get map => _targetMap; |
| 777 | 805 |
| 778 /** | 806 /** |
| 807 * Return the stream that is notified when a value is invalidated. |
| 808 */ |
| 809 Stream<InvalidatedResult> get onResultInvalidated => |
| 810 _onResultInvalidated.stream; |
| 811 |
| 812 /** |
| 779 * Return the entry associated with the given [target]. | 813 * Return the entry associated with the given [target]. |
| 780 */ | 814 */ |
| 781 CacheEntry get(AnalysisTarget target) => _targetMap[target]; | 815 CacheEntry get(AnalysisTarget target) => _targetMap[target]; |
| 782 | 816 |
| 783 /** | 817 /** |
| 784 * Return [Source]s whose full path is equal to the given [path]. | 818 * Return [Source]s whose full path is equal to the given [path]. |
| 785 * Maybe empty, but not `null`. | 819 * Maybe empty, but not `null`. |
| 786 */ | 820 */ |
| 787 List<Source> getSourcesWithFullName(String path) { | 821 List<Source> getSourcesWithFullName(String path) { |
| 788 List<Source> sources = _pathToSources[path]; | 822 List<Source> sources = _pathToSources[path]; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 if (sources.isEmpty) { | 953 if (sources.isEmpty) { |
| 920 _pathToSources.remove(fullName); | 954 _pathToSources.remove(fullName); |
| 921 } | 955 } |
| 922 } | 956 } |
| 923 } | 957 } |
| 924 } | 958 } |
| 925 } | 959 } |
| 926 } | 960 } |
| 927 | 961 |
| 928 /** | 962 /** |
| 963 * [InvalidatedResult] describes an invalidated result. |
| 964 */ |
| 965 class InvalidatedResult { |
| 966 /** |
| 967 * The target in which the result was invalidated. |
| 968 */ |
| 969 final CacheEntry entry; |
| 970 |
| 971 /** |
| 972 * The descriptor of the result which was invalidated. |
| 973 */ |
| 974 final ResultDescriptor descriptor; |
| 975 |
| 976 InvalidatedResult(this.entry, this.descriptor); |
| 977 |
| 978 @override |
| 979 String toString() => '$descriptor of ${entry.target}'; |
| 980 } |
| 981 |
| 982 /** |
| 929 * The data about a single analysis result that is stored in a [CacheEntry]. | 983 * The data about a single analysis result that is stored in a [CacheEntry]. |
| 930 */ | 984 */ |
| 931 // TODO(brianwilkerson) Consider making this a generic class so that the value | 985 // TODO(brianwilkerson) Consider making this a generic class so that the value |
| 932 // can be typed. | 986 // can be typed. |
| 933 class ResultData { | 987 class ResultData { |
| 934 /** | 988 /** |
| 935 * The [ResultDescriptor] this result is for. | 989 * The [ResultDescriptor] this result is for. |
| 936 */ | 990 */ |
| 937 final ResultDescriptor descriptor; | 991 final ResultDescriptor descriptor; |
| 938 | 992 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 void resultAccessed(TargetedResult result) {} | 1115 void resultAccessed(TargetedResult result) {} |
| 1062 | 1116 |
| 1063 @override | 1117 @override |
| 1064 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { | 1118 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { |
| 1065 return TargetedResult.EMPTY_LIST; | 1119 return TargetedResult.EMPTY_LIST; |
| 1066 } | 1120 } |
| 1067 | 1121 |
| 1068 @override | 1122 @override |
| 1069 void targetRemoved(AnalysisTarget target) {} | 1123 void targetRemoved(AnalysisTarget target) {} |
| 1070 } | 1124 } |
| OLD | NEW |