| 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:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
| 10 show AnalysisEngine, CacheState, InternalAnalysisContext, RetentionPriority; | 10 show AnalysisEngine, CacheState, InternalAnalysisContext, RetentionPriority; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // in which case the target should always be part of the SDK. | 104 // in which case the target should always be part of the SDK. |
| 105 // | 105 // |
| 106 // TODO(brianwilkerson) Throw an exception here. | 106 // TODO(brianwilkerson) Throw an exception here. |
| 107 AnalysisEngine.instance.logger.logInformation( | 107 AnalysisEngine.instance.logger.logInformation( |
| 108 'Could not find context for $target', | 108 'Could not find context for $target', |
| 109 new CaughtException(new AnalysisException(), null)); | 109 new CaughtException(new AnalysisException(), null)); |
| 110 return null; | 110 return null; |
| 111 } | 111 } |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * Return [Source]s whose full path is equal to the given [path]. |
| 115 * Maybe empty, but not `null`. |
| 116 */ |
| 117 List<Source> getSourcesWithFullName(String path) { |
| 118 List<Source> sources = <Source>[]; |
| 119 for (CachePartition partition in _partitions) { |
| 120 List<Source> partitionSources = partition.getSourcesWithFullName(path); |
| 121 sources.addAll(partitionSources); |
| 122 } |
| 123 return sources; |
| 124 } |
| 125 |
| 126 /** |
| 114 * Return the state of the given [result] for the given [target]. | 127 * Return the state of the given [result] for the given [target]. |
| 115 * | 128 * |
| 116 * It does not update the cache, if the corresponding [CacheEntry] does not | 129 * It does not update the cache, if the corresponding [CacheEntry] does not |
| 117 * exist, then [CacheState.INVALID] is returned. | 130 * exist, then [CacheState.INVALID] is returned. |
| 118 */ | 131 */ |
| 119 CacheState getState(AnalysisTarget target, ResultDescriptor result) { | 132 CacheState getState(AnalysisTarget target, ResultDescriptor result) { |
| 120 CacheEntry entry = get(target); | 133 CacheEntry entry = get(target); |
| 121 if (entry == null) { | 134 if (entry == null) { |
| 122 return CacheState.INVALID; | 135 return CacheState.INVALID; |
| 123 } | 136 } |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 */ | 734 */ |
| 722 HashMap<AnalysisTarget, CacheEntry> _targetMap = | 735 HashMap<AnalysisTarget, CacheEntry> _targetMap = |
| 723 new HashMap<AnalysisTarget, CacheEntry>(); | 736 new HashMap<AnalysisTarget, CacheEntry>(); |
| 724 | 737 |
| 725 /** | 738 /** |
| 726 * A set of the [Source] targets. | 739 * A set of the [Source] targets. |
| 727 */ | 740 */ |
| 728 final HashSet<Source> _sources = new HashSet<Source>(); | 741 final HashSet<Source> _sources = new HashSet<Source>(); |
| 729 | 742 |
| 730 /** | 743 /** |
| 744 * A table mapping full paths to lists of [Source]s with these full paths. |
| 745 */ |
| 746 final Map<String, List<Source>> _pathToSources = <String, List<Source>>{}; |
| 747 |
| 748 /** |
| 731 * Initialize a newly created cache partition, belonging to the given | 749 * Initialize a newly created cache partition, belonging to the given |
| 732 * [context]. | 750 * [context]. |
| 733 */ | 751 */ |
| 734 CachePartition(this.context); | 752 CachePartition(this.context); |
| 735 | 753 |
| 736 /** | 754 /** |
| 737 * Return a table mapping the targets known to the context to the information | 755 * Return a table mapping the targets known to the context to the information |
| 738 * known about the target. | 756 * known about the target. |
| 739 * | 757 * |
| 740 * <b>Note:</b> This method is only visible for use by [AnalysisCache] and | 758 * <b>Note:</b> This method is only visible for use by [AnalysisCache] and |
| 741 * should not be used for any other purpose. | 759 * should not be used for any other purpose. |
| 742 */ | 760 */ |
| 743 Map<AnalysisTarget, CacheEntry> get map => _targetMap; | 761 Map<AnalysisTarget, CacheEntry> get map => _targetMap; |
| 744 | 762 |
| 745 /** | 763 /** |
| 746 * Return the entry associated with the given [target]. | 764 * Return the entry associated with the given [target]. |
| 747 */ | 765 */ |
| 748 CacheEntry get(AnalysisTarget target) => _targetMap[target]; | 766 CacheEntry get(AnalysisTarget target) => _targetMap[target]; |
| 749 | 767 |
| 750 /** | 768 /** |
| 769 * Return [Source]s whose full path is equal to the given [path]. |
| 770 * Maybe empty, but not `null`. |
| 771 */ |
| 772 List<Source> getSourcesWithFullName(String path) { |
| 773 List<Source> sources = _pathToSources[path]; |
| 774 return sources != null ? sources : Source.EMPTY_LIST; |
| 775 } |
| 776 |
| 777 /** |
| 751 * Return `true` if this partition is responsible for the given [target]. | 778 * Return `true` if this partition is responsible for the given [target]. |
| 752 */ | 779 */ |
| 753 bool isResponsibleFor(AnalysisTarget target); | 780 bool isResponsibleFor(AnalysisTarget target); |
| 754 | 781 |
| 755 /** | 782 /** |
| 756 * Return an iterator returning all of the map entries mapping targets to | 783 * Return an iterator returning all of the map entries mapping targets to |
| 757 * cache entries. | 784 * cache entries. |
| 758 */ | 785 */ |
| 759 MapIterator<AnalysisTarget, CacheEntry> iterator() => | 786 MapIterator<AnalysisTarget, CacheEntry> iterator() => |
| 760 new SingleMapIterator<AnalysisTarget, CacheEntry>(_targetMap); | 787 new SingleMapIterator<AnalysisTarget, CacheEntry>(_targetMap); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 * Return the number of targets that are mapped to cache entries. | 847 * Return the number of targets that are mapped to cache entries. |
| 821 */ | 848 */ |
| 822 int size() => _targetMap.length; | 849 int size() => _targetMap.length; |
| 823 | 850 |
| 824 /** | 851 /** |
| 825 * If the given [target] is a [Source], adds it to [_sources]. | 852 * If the given [target] is a [Source], adds it to [_sources]. |
| 826 */ | 853 */ |
| 827 void _addIfSource(AnalysisTarget target) { | 854 void _addIfSource(AnalysisTarget target) { |
| 828 if (target is Source) { | 855 if (target is Source) { |
| 829 _sources.add(target); | 856 _sources.add(target); |
| 857 { |
| 858 String fullName = target.fullName; |
| 859 _pathToSources.putIfAbsent(fullName, () => <Source>[]).add(target); |
| 860 } |
| 830 } | 861 } |
| 831 } | 862 } |
| 832 | 863 |
| 833 ResultData _getDataFor(TargetedResult result, {bool orNull: false}) { | 864 ResultData _getDataFor(TargetedResult result, {bool orNull: false}) { |
| 834 CacheEntry entry = context.analysisCache.get(result.target); | 865 CacheEntry entry = context.analysisCache.get(result.target); |
| 835 if (orNull) { | 866 if (orNull) { |
| 836 return entry != null ? entry._resultMap[result.result] : null; | 867 return entry != null ? entry._resultMap[result.result] : null; |
| 837 } else { | 868 } else { |
| 838 return entry._getResultData(result.result); | 869 return entry._getResultData(result.result); |
| 839 } | 870 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 851 bool _isPriorityAnalysisTarget(AnalysisTarget target) { | 882 bool _isPriorityAnalysisTarget(AnalysisTarget target) { |
| 852 return context.priorityTargets.contains(target); | 883 return context.priorityTargets.contains(target); |
| 853 } | 884 } |
| 854 | 885 |
| 855 /** | 886 /** |
| 856 * If the given [target] is a [Source], removes it from [_sources]. | 887 * If the given [target] is a [Source], removes it from [_sources]. |
| 857 */ | 888 */ |
| 858 void _removeIfSource(AnalysisTarget target) { | 889 void _removeIfSource(AnalysisTarget target) { |
| 859 if (target is Source) { | 890 if (target is Source) { |
| 860 _sources.remove(target); | 891 _sources.remove(target); |
| 892 { |
| 893 String fullName = target.fullName; |
| 894 List<Source> sources = _pathToSources[fullName]; |
| 895 if (sources != null) { |
| 896 sources.remove(target); |
| 897 if (sources.isEmpty) { |
| 898 _pathToSources.remove(fullName); |
| 899 } |
| 900 } |
| 901 } |
| 861 } | 902 } |
| 862 } | 903 } |
| 863 } | 904 } |
| 864 | 905 |
| 865 /** | 906 /** |
| 866 * The data about a single analysis result that is stored in a [CacheEntry]. | 907 * The data about a single analysis result that is stored in a [CacheEntry]. |
| 867 */ | 908 */ |
| 868 // TODO(brianwilkerson) Consider making this a generic class so that the value | 909 // TODO(brianwilkerson) Consider making this a generic class so that the value |
| 869 // can be typed. | 910 // can be typed. |
| 870 class ResultData { | 911 class ResultData { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 class UniversalCachePartition extends CachePartition { | 1019 class UniversalCachePartition extends CachePartition { |
| 979 /** | 1020 /** |
| 980 * Initialize a newly created cache partition, belonging to the given | 1021 * Initialize a newly created cache partition, belonging to the given |
| 981 * [context]. | 1022 * [context]. |
| 982 */ | 1023 */ |
| 983 UniversalCachePartition(InternalAnalysisContext context) : super(context); | 1024 UniversalCachePartition(InternalAnalysisContext context) : super(context); |
| 984 | 1025 |
| 985 @override | 1026 @override |
| 986 bool isResponsibleFor(AnalysisTarget target) => true; | 1027 bool isResponsibleFor(AnalysisTarget target) => true; |
| 987 } | 1028 } |
| OLD | NEW |