| 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/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/java_engine.dart'; | 12 import 'package:analyzer/src/generated/java_engine.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:analyzer/src/generated/utilities_collection.dart'; | 14 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| 15 import 'package:analyzer/src/task/model.dart'; | 15 import 'package:analyzer/src/task/model.dart'; |
| 16 import 'package:analyzer/task/model.dart'; | 16 import 'package:analyzer/task/model.dart'; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * The cache results visiting function type. | 19 * The cache results visiting function type. |
| 20 */ | 20 */ |
| 21 typedef void CacheResultVisitor(AnalysisTarget target, ResultData data); | 21 typedef void CacheResultVisitor(AnalysisTarget target, ResultData data); |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Return `true` if the [result] of the [target] should be flushed. | 24 * Return `true` if the [result] of the [target] should be flushed. |
| 25 */ | 25 */ |
| 26 typedef bool FlushResultFilter<V>( | 26 typedef bool FlushResultFilter<V>( |
| 27 AnalysisTarget target, ResultDescriptor<V> result); | 27 AnalysisTarget target, ResultDescriptor<V> result); |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * Return `true` if some results of the [target] should be flushed. | |
| 31 */ | |
| 32 typedef bool FlushTargetFilter<V>(AnalysisTarget target); | |
| 33 | |
| 34 /** | |
| 35 * Return `true` if the given [target] is a priority one. | 30 * Return `true` if the given [target] is a priority one. |
| 36 */ | 31 */ |
| 37 typedef bool IsPriorityAnalysisTarget(AnalysisTarget target); | 32 typedef bool IsPriorityAnalysisTarget(AnalysisTarget target); |
| 38 | 33 |
| 39 /** | 34 /** |
| 40 * An LRU cache of results produced by analysis. | 35 * An LRU cache of results produced by analysis. |
| 41 */ | 36 */ |
| 42 class AnalysisCache { | 37 class AnalysisCache { |
| 43 /** | 38 /** |
| 44 * A flag used to control whether trace information should be produced when | 39 * 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... |
| 111 for (ReentrantSynchronousStreamSubscription subscription | 106 for (ReentrantSynchronousStreamSubscription subscription |
| 112 in onResultInvalidatedPartitionSubscriptions) { | 107 in onResultInvalidatedPartitionSubscriptions) { |
| 113 subscription.cancel(); | 108 subscription.cancel(); |
| 114 } | 109 } |
| 115 for (CachePartition partition in _partitions) { | 110 for (CachePartition partition in _partitions) { |
| 116 partition.containingCaches.remove(this); | 111 partition.containingCaches.remove(this); |
| 117 } | 112 } |
| 118 } | 113 } |
| 119 | 114 |
| 120 /** | 115 /** |
| 121 * Flush results that satisfy the given [targetFilter] and [resultFilter]. | 116 * Flush results that satisfy the given [filter]. |
| 122 */ | 117 */ |
| 123 void flush(FlushTargetFilter targetFilter, FlushResultFilter resultFilter) { | 118 void flush(FlushResultFilter filter) { |
| 124 for (CachePartition partition in _partitions) { | 119 for (CachePartition partition in _partitions) { |
| 125 partition.flush(targetFilter, resultFilter); | 120 partition.flush(filter); |
| 126 } | 121 } |
| 127 } | 122 } |
| 128 | 123 |
| 129 /** | 124 /** |
| 130 * Return the entry associated with the given [target]. | 125 * Return the entry associated with the given [target]. |
| 131 */ | 126 */ |
| 132 CacheEntry get(AnalysisTarget target) { | 127 CacheEntry get(AnalysisTarget target) { |
| 133 int count = _partitions.length; | 128 int count = _partitions.length; |
| 134 for (int i = 0; i < count; i++) { | 129 for (int i = 0; i < count; i++) { |
| 135 CachePartition partition = _partitions[i]; | 130 CachePartition partition = _partitions[i]; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 /** | 398 /** |
| 404 * Fix the state of the [exception] to match the current state of the entry. | 399 * Fix the state of the [exception] to match the current state of the entry. |
| 405 */ | 400 */ |
| 406 void fixExceptionState() { | 401 void fixExceptionState() { |
| 407 if (!hasErrorState()) { | 402 if (!hasErrorState()) { |
| 408 _exception = null; | 403 _exception = null; |
| 409 } | 404 } |
| 410 } | 405 } |
| 411 | 406 |
| 412 /** | 407 /** |
| 413 * Flush results that satisfy the given [targetFilter] and [resultFilter]. | 408 * Flush results that satisfy the given [filter]. |
| 414 */ | 409 */ |
| 415 void flush(FlushTargetFilter targetFilter, FlushResultFilter resultFilter) { | 410 void flush(FlushResultFilter filter) { |
| 416 if (targetFilter(target)) { | 411 _resultMap.forEach((ResultDescriptor result, ResultData data) { |
| 417 _resultMap.forEach((ResultDescriptor result, ResultData data) { | 412 if (filter(target, result)) { |
| 418 if (data.state == CacheState.VALID) { | 413 data.flush(); |
| 419 if (resultFilter(target, result)) { | 414 } |
| 420 data.flush(); | 415 }); |
| 421 } | |
| 422 } | |
| 423 }); | |
| 424 } | |
| 425 } | 416 } |
| 426 | 417 |
| 427 /** | 418 /** |
| 428 * Return the result data associated with the [descriptor], creating one if it | 419 * Return the result data associated with the [descriptor], creating one if it |
| 429 * isn't there. | 420 * isn't there. |
| 430 */ | 421 */ |
| 431 ResultData getResultData(ResultDescriptor descriptor) { | 422 ResultData getResultData(ResultDescriptor descriptor) { |
| 432 return _resultMap.putIfAbsent(descriptor, () => new ResultData(descriptor)); | 423 return _resultMap.putIfAbsent(descriptor, () => new ResultData(descriptor)); |
| 433 } | 424 } |
| 434 | 425 |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 void dispose() { | 1086 void dispose() { |
| 1096 for (CacheEntry entry in entryMap.values) { | 1087 for (CacheEntry entry in entryMap.values) { |
| 1097 entry.dispose(); | 1088 entry.dispose(); |
| 1098 } | 1089 } |
| 1099 entryMap.clear(); | 1090 entryMap.clear(); |
| 1100 sources.clear(); | 1091 sources.clear(); |
| 1101 pathToSource.clear(); | 1092 pathToSource.clear(); |
| 1102 } | 1093 } |
| 1103 | 1094 |
| 1104 /** | 1095 /** |
| 1105 * Flush results that satisfy the given [targetFilter] and [resultFilter]. | 1096 * Flush results that satisfy the given [filter]. |
| 1106 */ | 1097 */ |
| 1107 void flush(FlushTargetFilter targetFilter, FlushResultFilter resultFilter) { | 1098 void flush(FlushResultFilter filter) { |
| 1108 for (CacheEntry entry in entryMap.values) { | 1099 for (CacheEntry entry in entryMap.values) { |
| 1109 entry.flush(targetFilter, resultFilter); | 1100 entry.flush(filter); |
| 1110 } | 1101 } |
| 1111 } | 1102 } |
| 1112 | 1103 |
| 1113 /** | 1104 /** |
| 1114 * Return the entry associated with the given [target]. | 1105 * Return the entry associated with the given [target]. |
| 1115 */ | 1106 */ |
| 1116 CacheEntry get(AnalysisTarget target) => entryMap[target]; | 1107 CacheEntry get(AnalysisTarget target) => entryMap[target]; |
| 1117 | 1108 |
| 1118 /** | 1109 /** |
| 1119 * Return [Source]s whose full path is equal to the given [path]. | 1110 * Return [Source]s whose full path is equal to the given [path]. |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 void resultAccessed(TargetedResult result) {} | 1518 void resultAccessed(TargetedResult result) {} |
| 1528 | 1519 |
| 1529 @override | 1520 @override |
| 1530 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { | 1521 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { |
| 1531 return TargetedResult.EMPTY_LIST; | 1522 return TargetedResult.EMPTY_LIST; |
| 1532 } | 1523 } |
| 1533 | 1524 |
| 1534 @override | 1525 @override |
| 1535 void targetRemoved(AnalysisTarget target) {} | 1526 void targetRemoved(AnalysisTarget target) {} |
| 1536 } | 1527 } |
| OLD | NEW |