| 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 /** |
| 30 * Return `true` if the given [target] is a priority one. | 35 * Return `true` if the given [target] is a priority one. |
| 31 */ | 36 */ |
| 32 typedef bool IsPriorityAnalysisTarget(AnalysisTarget target); | 37 typedef bool IsPriorityAnalysisTarget(AnalysisTarget target); |
| 33 | 38 |
| 34 /** | 39 /** |
| 35 * An LRU cache of results produced by analysis. | 40 * An LRU cache of results produced by analysis. |
| 36 */ | 41 */ |
| 37 class AnalysisCache { | 42 class AnalysisCache { |
| 38 /** | 43 /** |
| 39 * A flag used to control whether trace information should be produced when | 44 * 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... |
| 106 for (ReentrantSynchronousStreamSubscription subscription | 111 for (ReentrantSynchronousStreamSubscription subscription |
| 107 in onResultInvalidatedPartitionSubscriptions) { | 112 in onResultInvalidatedPartitionSubscriptions) { |
| 108 subscription.cancel(); | 113 subscription.cancel(); |
| 109 } | 114 } |
| 110 for (CachePartition partition in _partitions) { | 115 for (CachePartition partition in _partitions) { |
| 111 partition.containingCaches.remove(this); | 116 partition.containingCaches.remove(this); |
| 112 } | 117 } |
| 113 } | 118 } |
| 114 | 119 |
| 115 /** | 120 /** |
| 116 * Flush results that satisfy the given [filter]. | 121 * Flush results that satisfy the given [targetFilter] and [resultFilter]. |
| 117 */ | 122 */ |
| 118 void flush(FlushResultFilter filter) { | 123 void flush(FlushTargetFilter targetFilter, FlushResultFilter resultFilter) { |
| 119 for (CachePartition partition in _partitions) { | 124 for (CachePartition partition in _partitions) { |
| 120 partition.flush(filter); | 125 partition.flush(targetFilter, resultFilter); |
| 121 } | 126 } |
| 122 } | 127 } |
| 123 | 128 |
| 124 /** | 129 /** |
| 125 * Return the entry associated with the given [target]. | 130 * Return the entry associated with the given [target]. |
| 126 */ | 131 */ |
| 127 CacheEntry get(AnalysisTarget target) { | 132 CacheEntry get(AnalysisTarget target) { |
| 128 int count = _partitions.length; | 133 int count = _partitions.length; |
| 129 for (int i = 0; i < count; i++) { | 134 for (int i = 0; i < count; i++) { |
| 130 CachePartition partition = _partitions[i]; | 135 CachePartition partition = _partitions[i]; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 /** | 403 /** |
| 399 * Fix the state of the [exception] to match the current state of the entry. | 404 * Fix the state of the [exception] to match the current state of the entry. |
| 400 */ | 405 */ |
| 401 void fixExceptionState() { | 406 void fixExceptionState() { |
| 402 if (!hasErrorState()) { | 407 if (!hasErrorState()) { |
| 403 _exception = null; | 408 _exception = null; |
| 404 } | 409 } |
| 405 } | 410 } |
| 406 | 411 |
| 407 /** | 412 /** |
| 408 * Flush results that satisfy the given [filter]. | 413 * Flush results that satisfy the given [targetFilter] and [resultFilter]. |
| 409 */ | 414 */ |
| 410 void flush(FlushResultFilter filter) { | 415 void flush(FlushTargetFilter targetFilter, FlushResultFilter resultFilter) { |
| 411 _resultMap.forEach((ResultDescriptor result, ResultData data) { | 416 if (targetFilter(target)) { |
| 412 if (data.state == CacheState.VALID) { | 417 _resultMap.forEach((ResultDescriptor result, ResultData data) { |
| 413 if (filter(target, result)) { | 418 if (data.state == CacheState.VALID) { |
| 414 data.flush(); | 419 if (resultFilter(target, result)) { |
| 420 data.flush(); |
| 421 } |
| 415 } | 422 } |
| 416 } | 423 }); |
| 417 }); | 424 } |
| 418 } | 425 } |
| 419 | 426 |
| 420 /** | 427 /** |
| 421 * Return the result data associated with the [descriptor], creating one if it | 428 * Return the result data associated with the [descriptor], creating one if it |
| 422 * isn't there. | 429 * isn't there. |
| 423 */ | 430 */ |
| 424 ResultData getResultData(ResultDescriptor descriptor) { | 431 ResultData getResultData(ResultDescriptor descriptor) { |
| 425 return _resultMap.putIfAbsent(descriptor, () => new ResultData(descriptor)); | 432 return _resultMap.putIfAbsent(descriptor, () => new ResultData(descriptor)); |
| 426 } | 433 } |
| 427 | 434 |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 void dispose() { | 1092 void dispose() { |
| 1086 for (CacheEntry entry in entryMap.values) { | 1093 for (CacheEntry entry in entryMap.values) { |
| 1087 entry.dispose(); | 1094 entry.dispose(); |
| 1088 } | 1095 } |
| 1089 entryMap.clear(); | 1096 entryMap.clear(); |
| 1090 sources.clear(); | 1097 sources.clear(); |
| 1091 pathToSource.clear(); | 1098 pathToSource.clear(); |
| 1092 } | 1099 } |
| 1093 | 1100 |
| 1094 /** | 1101 /** |
| 1095 * Flush results that satisfy the given [filter]. | 1102 * Flush results that satisfy the given [targetFilter] and [resultFilter]. |
| 1096 */ | 1103 */ |
| 1097 void flush(FlushResultFilter filter) { | 1104 void flush(FlushTargetFilter targetFilter, FlushResultFilter resultFilter) { |
| 1098 for (CacheEntry entry in entryMap.values) { | 1105 for (CacheEntry entry in entryMap.values) { |
| 1099 entry.flush(filter); | 1106 entry.flush(targetFilter, resultFilter); |
| 1100 } | 1107 } |
| 1101 } | 1108 } |
| 1102 | 1109 |
| 1103 /** | 1110 /** |
| 1104 * Return the entry associated with the given [target]. | 1111 * Return the entry associated with the given [target]. |
| 1105 */ | 1112 */ |
| 1106 CacheEntry get(AnalysisTarget target) => entryMap[target]; | 1113 CacheEntry get(AnalysisTarget target) => entryMap[target]; |
| 1107 | 1114 |
| 1108 /** | 1115 /** |
| 1109 * Return [Source]s whose full path is equal to the given [path]. | 1116 * Return [Source]s whose full path is equal to the given [path]. |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 void resultAccessed(TargetedResult result) {} | 1508 void resultAccessed(TargetedResult result) {} |
| 1502 | 1509 |
| 1503 @override | 1510 @override |
| 1504 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { | 1511 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { |
| 1505 return TargetedResult.EMPTY_LIST; | 1512 return TargetedResult.EMPTY_LIST; |
| 1506 } | 1513 } |
| 1507 | 1514 |
| 1508 @override | 1515 @override |
| 1509 void targetRemoved(AnalysisTarget target) {} | 1516 void targetRemoved(AnalysisTarget target) {} |
| 1510 } | 1517 } |
| OLD | NEW |