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:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/src/dart/element/element.dart' | 10 import 'package:analyzer/src/dart/element/element.dart' |
11 show ElementImpl, Modifier; | 11 show ElementImpl, Modifier; |
12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
13 import 'package:analyzer/src/generated/java_engine.dart'; | 13 import 'package:analyzer/src/generated/java_engine.dart'; |
14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
15 import 'package:analyzer/src/generated/utilities_collection.dart'; | 15 import 'package:analyzer/src/generated/utilities_collection.dart'; |
16 import 'package:analyzer/src/task/model.dart'; | 16 import 'package:analyzer/src/task/model.dart'; |
17 import 'package:analyzer/task/model.dart'; | 17 import 'package:analyzer/task/model.dart'; |
18 | 18 |
19 /** | 19 /** |
| 20 * Return `true` if the [result] of the [target] should be flushed. |
| 21 */ |
| 22 typedef bool FlushResultFilter<V>( |
| 23 AnalysisTarget target, ResultDescriptor<V> result); |
| 24 |
| 25 /** |
20 * Return `true` if the given [target] is a priority one. | 26 * Return `true` if the given [target] is a priority one. |
21 */ | 27 */ |
22 typedef bool IsPriorityAnalysisTarget(AnalysisTarget target); | 28 typedef bool IsPriorityAnalysisTarget(AnalysisTarget target); |
23 | 29 |
24 /** | 30 /** |
25 * An LRU cache of results produced by analysis. | 31 * An LRU cache of results produced by analysis. |
26 */ | 32 */ |
27 class AnalysisCache { | 33 class AnalysisCache { |
28 /** | 34 /** |
29 * A flag used to control whether trace information should be produced when | 35 * A flag used to control whether trace information should be produced when |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 for (ReentrantSynchronousStreamSubscription subscription | 102 for (ReentrantSynchronousStreamSubscription subscription |
97 in onResultInvalidatedPartitionSubscriptions) { | 103 in onResultInvalidatedPartitionSubscriptions) { |
98 subscription.cancel(); | 104 subscription.cancel(); |
99 } | 105 } |
100 for (CachePartition partition in _partitions) { | 106 for (CachePartition partition in _partitions) { |
101 partition.containingCaches.remove(this); | 107 partition.containingCaches.remove(this); |
102 } | 108 } |
103 } | 109 } |
104 | 110 |
105 /** | 111 /** |
| 112 * Flush results that satisfy the given [filter]. |
| 113 */ |
| 114 void flush(FlushResultFilter filter) { |
| 115 for (CachePartition partition in _partitions) { |
| 116 partition.flush(filter); |
| 117 } |
| 118 } |
| 119 |
| 120 /** |
106 * Return the entry associated with the given [target]. | 121 * Return the entry associated with the given [target]. |
107 */ | 122 */ |
108 CacheEntry get(AnalysisTarget target) { | 123 CacheEntry get(AnalysisTarget target) { |
109 int count = _partitions.length; | 124 int count = _partitions.length; |
110 for (int i = 0; i < count; i++) { | 125 for (int i = 0; i < count; i++) { |
111 CachePartition partition = _partitions[i]; | 126 CachePartition partition = _partitions[i]; |
112 if (partition.isResponsibleFor(target)) { | 127 if (partition.isResponsibleFor(target)) { |
113 return partition.get(target); | 128 return partition.get(target); |
114 } | 129 } |
115 } | 130 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 /** | 400 /** |
386 * Fix the state of the [exception] to match the current state of the entry. | 401 * Fix the state of the [exception] to match the current state of the entry. |
387 */ | 402 */ |
388 void fixExceptionState() { | 403 void fixExceptionState() { |
389 if (!hasErrorState()) { | 404 if (!hasErrorState()) { |
390 _exception = null; | 405 _exception = null; |
391 } | 406 } |
392 } | 407 } |
393 | 408 |
394 /** | 409 /** |
| 410 * Flush results that satisfy the given [filter]. |
| 411 */ |
| 412 void flush(FlushResultFilter filter) { |
| 413 _resultMap.forEach((ResultDescriptor result, ResultData data) { |
| 414 if (filter(target, result)) { |
| 415 data.flush(); |
| 416 } |
| 417 }); |
| 418 } |
| 419 |
| 420 /** |
395 * Return the result data associated with the [descriptor], creating one if it | 421 * Return the result data associated with the [descriptor], creating one if it |
396 * isn't there. | 422 * isn't there. |
397 */ | 423 */ |
398 ResultData getResultData(ResultDescriptor descriptor) { | 424 ResultData getResultData(ResultDescriptor descriptor) { |
399 return _resultMap.putIfAbsent(descriptor, () => new ResultData(descriptor)); | 425 return _resultMap.putIfAbsent(descriptor, () => new ResultData(descriptor)); |
400 } | 426 } |
401 | 427 |
402 /** | 428 /** |
403 * Return the result data associated with the [descriptor], or `null` if there | 429 * Return the result data associated with the [descriptor], or `null` if there |
404 * is no data currently associated with the descriptor. | 430 * is no data currently associated with the descriptor. |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 void dispose() { | 1017 void dispose() { |
992 for (CacheEntry entry in entryMap.values) { | 1018 for (CacheEntry entry in entryMap.values) { |
993 entry.dispose(); | 1019 entry.dispose(); |
994 } | 1020 } |
995 entryMap.clear(); | 1021 entryMap.clear(); |
996 sources.clear(); | 1022 sources.clear(); |
997 pathToSource.clear(); | 1023 pathToSource.clear(); |
998 } | 1024 } |
999 | 1025 |
1000 /** | 1026 /** |
| 1027 * Flush results that satisfy the given [filter]. |
| 1028 */ |
| 1029 void flush(FlushResultFilter filter) { |
| 1030 for (CacheEntry entry in entryMap.values) { |
| 1031 entry.flush(filter); |
| 1032 } |
| 1033 } |
| 1034 |
| 1035 /** |
1001 * Return the entry associated with the given [target]. | 1036 * Return the entry associated with the given [target]. |
1002 */ | 1037 */ |
1003 CacheEntry get(AnalysisTarget target) => entryMap[target]; | 1038 CacheEntry get(AnalysisTarget target) => entryMap[target]; |
1004 | 1039 |
1005 /** | 1040 /** |
1006 * Return [Source]s whose full path is equal to the given [path]. | 1041 * Return [Source]s whose full path is equal to the given [path]. |
1007 * Maybe empty, but not `null`. | 1042 * Maybe empty, but not `null`. |
1008 */ | 1043 */ |
1009 List<Source> getSourcesWithFullName(String path) { | 1044 List<Source> getSourcesWithFullName(String path) { |
1010 List<Source> sources = pathToSource[path]; | 1045 List<Source> sources = pathToSource[path]; |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 void resultAccessed(TargetedResult result) {} | 1395 void resultAccessed(TargetedResult result) {} |
1361 | 1396 |
1362 @override | 1397 @override |
1363 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { | 1398 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { |
1364 return TargetedResult.EMPTY_LIST; | 1399 return TargetedResult.EMPTY_LIST; |
1365 } | 1400 } |
1366 | 1401 |
1367 @override | 1402 @override |
1368 void targetRemoved(AnalysisTarget target) {} | 1403 void targetRemoved(AnalysisTarget target) {} |
1369 } | 1404 } |
OLD | NEW |