| 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/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart' | 10 import 'package:analyzer/src/generated/engine.dart' |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 342 |
| 343 /** | 343 /** |
| 344 * Invalidate all of the information associated with this entry's target. | 344 * Invalidate all of the information associated with this entry's target. |
| 345 */ | 345 */ |
| 346 void invalidateAllInformation() { | 346 void invalidateAllInformation() { |
| 347 _resultMap.clear(); | 347 _resultMap.clear(); |
| 348 _exception = null; | 348 _exception = null; |
| 349 } | 349 } |
| 350 | 350 |
| 351 /** | 351 /** |
| 352 * Return `true` if the state of the result represented by the given |
| 353 * [descriptor] is [CacheState.INVALID]. |
| 354 */ |
| 355 bool isInvalid(ResultDescriptor descriptor) => |
| 356 getState(descriptor) == CacheState.INVALID; |
| 357 |
| 358 /** |
| 359 * Return `true` if the state of the result represented by the given |
| 360 * [descriptor] is [CacheState.VALID]. |
| 361 */ |
| 362 bool isValid(ResultDescriptor descriptor) => |
| 363 getState(descriptor) == CacheState.VALID; |
| 364 |
| 365 /** |
| 352 * Set the [CacheState.ERROR] state for given [descriptors], their values to | 366 * Set the [CacheState.ERROR] state for given [descriptors], their values to |
| 353 * the corresponding default values, and remember the [exception] that caused | 367 * the corresponding default values, and remember the [exception] that caused |
| 354 * this state. | 368 * this state. |
| 355 */ | 369 */ |
| 356 void setErrorState( | 370 void setErrorState( |
| 357 CaughtException exception, List<ResultDescriptor> descriptors) { | 371 CaughtException exception, List<ResultDescriptor> descriptors) { |
| 358 if (descriptors == null || descriptors.isEmpty) { | 372 if (descriptors == null || descriptors.isEmpty) { |
| 359 throw new ArgumentError('at least one descriptor is expected'); | 373 throw new ArgumentError('at least one descriptor is expected'); |
| 360 } | 374 } |
| 361 if (exception == null) { | 375 if (exception == null) { |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 // TODO(brianwilkerson) Consider making this a generic class so that the value | 770 // TODO(brianwilkerson) Consider making this a generic class so that the value |
| 757 // can be typed. | 771 // can be typed. |
| 758 class ResultData { | 772 class ResultData { |
| 759 /** | 773 /** |
| 760 * The state of the cached value. | 774 * The state of the cached value. |
| 761 */ | 775 */ |
| 762 CacheState state; | 776 CacheState state; |
| 763 | 777 |
| 764 /** | 778 /** |
| 765 * The value being cached, or the default value for the result if there is no | 779 * The value being cached, or the default value for the result if there is no |
| 766 * value (for example, when the [state] is [CacheState.INVALID]. | 780 * value (for example, when the [state] is [CacheState.INVALID]). |
| 767 */ | 781 */ |
| 768 Object value; | 782 Object value; |
| 769 | 783 |
| 770 /** | 784 /** |
| 771 * Initialize a newly created result holder to represent the value of data | 785 * Initialize a newly created result holder to represent the value of data |
| 772 * described by the given [descriptor]. | 786 * described by the given [descriptor]. |
| 773 */ | 787 */ |
| 774 ResultData(ResultDescriptor descriptor) { | 788 ResultData(ResultDescriptor descriptor) { |
| 775 state = CacheState.INVALID; | 789 state = CacheState.INVALID; |
| 776 value = descriptor.defaultValue; | 790 value = descriptor.defaultValue; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 806 * structures in the cache, using the [retentionPolicy] to determine which | 820 * structures in the cache, using the [retentionPolicy] to determine which |
| 807 * AST structures to flush. | 821 * AST structures to flush. |
| 808 */ | 822 */ |
| 809 UniversalCachePartition(InternalAnalysisContext context, int maxCacheSize, | 823 UniversalCachePartition(InternalAnalysisContext context, int maxCacheSize, |
| 810 CacheRetentionPolicy retentionPolicy) | 824 CacheRetentionPolicy retentionPolicy) |
| 811 : super(context, maxCacheSize, retentionPolicy); | 825 : super(context, maxCacheSize, retentionPolicy); |
| 812 | 826 |
| 813 @override | 827 @override |
| 814 bool contains(AnalysisTarget target) => true; | 828 bool contains(AnalysisTarget target) => true; |
| 815 } | 829 } |
| OLD | NEW |