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.task.inputs; | 5 library analyzer.src.task.inputs; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/task/model.dart'; | 9 import 'package:analyzer/task/model.dart'; |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 @override | 49 @override |
50 AnalysisTarget get currentTarget => null; | 50 AnalysisTarget get currentTarget => null; |
51 | 51 |
52 @override | 52 @override |
53 void set currentValue(Object value) { | 53 void set currentValue(Object value) { |
54 throw new StateError('Only supported after moveNext() returns true'); | 54 throw new StateError('Only supported after moveNext() returns true'); |
55 } | 55 } |
56 | 56 |
57 @override | 57 @override |
| 58 bool get flushOnAccess => false; |
| 59 |
| 60 @override |
58 V get inputValue => input.value; | 61 V get inputValue => input.value; |
59 | 62 |
60 @override | 63 @override |
61 void currentValueNotAvailable() { | 64 void currentValueNotAvailable() { |
62 throw new StateError('Only supported after moveNext() returns true'); | 65 throw new StateError('Only supported after moveNext() returns true'); |
63 } | 66 } |
64 | 67 |
65 @override | 68 @override |
66 bool moveNext() => false; | 69 bool moveNext() => false; |
67 } | 70 } |
68 | 71 |
69 /** | 72 /** |
70 * An input to an [AnalysisTask] that is computed by accessing a single result | 73 * An input to an [AnalysisTask] that is computed by accessing a single result |
71 * defined on a single target. | 74 * defined on a single target. |
72 */ | 75 */ |
73 class ListTaskInputImpl<E> extends SimpleTaskInput<List<E>> | 76 class ListTaskInputImpl<E> extends SimpleTaskInput<List<E>> |
74 with ListTaskInputMixin<E> | 77 with ListTaskInputMixin<E> |
75 implements ListTaskInput<E> { | 78 implements ListTaskInput<E> { |
76 /** | 79 /** |
77 * Initialize a newly created task input that computes the input by accessing | 80 * Initialize a newly created task input that computes the input by accessing |
78 * the given [result] associated with the given [target]. | 81 * the given [result] associated with the given [target]. |
79 */ | 82 */ |
80 ListTaskInputImpl(AnalysisTarget target, ResultDescriptor<List<E>> result) | 83 ListTaskInputImpl(AnalysisTarget target, ResultDescriptor<List<E>> result) |
81 : super(target, result); | 84 : super._unflushable(target, result); |
82 } | 85 } |
83 | 86 |
84 /** | 87 /** |
85 * A mixin-ready implementation of [ListTaskInput]. | 88 * A mixin-ready implementation of [ListTaskInput]. |
86 */ | 89 */ |
87 abstract class ListTaskInputMixin<E> implements ListTaskInput<E> { | 90 abstract class ListTaskInputMixin<E> implements ListTaskInput<E> { |
88 ListTaskInput /*<V>*/ toList(UnaryFunction<E, dynamic /*<V>*/ > mapper) { | 91 ListTaskInput /*<V>*/ toList(UnaryFunction<E, dynamic /*<V>*/ > mapper) { |
89 return new ListToListTaskInput<E, dynamic /*V*/ >(this, mapper); | 92 return new ListToListTaskInput<E, dynamic /*V*/ >(this, mapper); |
90 } | 93 } |
91 | 94 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 @override | 285 @override |
283 void set currentValue(Object value) { | 286 void set currentValue(Object value) { |
284 if (currentBuilder == null) { | 287 if (currentBuilder == null) { |
285 throw new StateError( | 288 throw new StateError( |
286 'Cannot set the result value when there is no current result'); | 289 'Cannot set the result value when there is no current result'); |
287 } | 290 } |
288 currentBuilder.currentValue = value; | 291 currentBuilder.currentValue = value; |
289 } | 292 } |
290 | 293 |
291 @override | 294 @override |
| 295 bool get flushOnAccess => currentBuilder.flushOnAccess; |
| 296 |
| 297 @override |
292 void currentValueNotAvailable() { | 298 void currentValueNotAvailable() { |
293 if (currentBuilder == null) { | 299 if (currentBuilder == null) { |
294 throw new StateError( | 300 throw new StateError( |
295 'Cannot set the result value when there is no current result'); | 301 'Cannot set the result value when there is no current result'); |
296 } | 302 } |
297 currentBuilder.currentValueNotAvailable(); | 303 currentBuilder.currentValueNotAvailable(); |
298 } | 304 } |
299 | 305 |
300 @override | 306 @override |
301 bool moveNext() { | 307 bool moveNext() { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 @override | 439 @override |
434 void set currentValue(Object value) { | 440 void set currentValue(Object value) { |
435 if (builder == null) { | 441 if (builder == null) { |
436 throw new StateError( | 442 throw new StateError( |
437 'Cannot set the result value when there is no current result'); | 443 'Cannot set the result value when there is no current result'); |
438 } | 444 } |
439 builder.currentValue = value; | 445 builder.currentValue = value; |
440 } | 446 } |
441 | 447 |
442 @override | 448 @override |
| 449 bool get flushOnAccess => builder.flushOnAccess; |
| 450 |
| 451 @override |
443 List<E> get inputValue { | 452 List<E> get inputValue { |
444 if (builder != null) { | 453 if (builder != null) { |
445 throw new StateError('Result value has not been created'); | 454 throw new StateError('Result value has not been created'); |
446 } | 455 } |
447 return _inputValue; | 456 return _inputValue; |
448 } | 457 } |
449 | 458 |
450 @override | 459 @override |
451 void currentValueNotAvailable() { | 460 void currentValueNotAvailable() { |
452 if (builder == null) { | 461 if (builder == null) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 * The target on which the result is defined. | 493 * The target on which the result is defined. |
485 */ | 494 */ |
486 final AnalysisTarget target; | 495 final AnalysisTarget target; |
487 | 496 |
488 /** | 497 /** |
489 * The result to be accessed. | 498 * The result to be accessed. |
490 */ | 499 */ |
491 final ResultDescriptor<V> result; | 500 final ResultDescriptor<V> result; |
492 | 501 |
493 /** | 502 /** |
| 503 * Return `true` if the value accessed by this input builder should be flushed |
| 504 * from the cache at the time it is retrieved. |
| 505 */ |
| 506 final bool flushOnAccess; |
| 507 |
| 508 /** |
494 * Initialize a newly created task input that computes the input by accessing | 509 * Initialize a newly created task input that computes the input by accessing |
495 * the given [result] associated with the given [target]. | 510 * the given [result] associated with the given [target]. |
496 */ | 511 */ |
497 SimpleTaskInput(this.target, this.result); | 512 SimpleTaskInput(this.target, this.result, {this.flushOnAccess: false}); |
| 513 |
| 514 /** |
| 515 * Initialize a newly created task input that computes the input by accessing |
| 516 * the given [result] associated with the given [target]. |
| 517 */ |
| 518 SimpleTaskInput._unflushable(this.target, this.result) |
| 519 : flushOnAccess = false; |
498 | 520 |
499 @override | 521 @override |
500 TaskInputBuilder<V> createBuilder() => new SimpleTaskInputBuilder<V>(this); | 522 TaskInputBuilder<V> createBuilder() => new SimpleTaskInputBuilder<V>(this); |
501 } | 523 } |
502 | 524 |
503 /** | 525 /** |
504 * A [TaskInputBuilder] used to build an input based on a [SimpleTaskInput]. | 526 * A [TaskInputBuilder] used to build an input based on a [SimpleTaskInput]. |
505 */ | 527 */ |
506 class SimpleTaskInputBuilder<V> implements TaskInputBuilder<V> { | 528 class SimpleTaskInputBuilder<V> implements TaskInputBuilder<V> { |
507 /** | 529 /** |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 void set currentValue(Object value) { | 581 void set currentValue(Object value) { |
560 if (_state != _AT) { | 582 if (_state != _AT) { |
561 throw new StateError( | 583 throw new StateError( |
562 'Cannot set the result value when there is no current result'); | 584 'Cannot set the result value when there is no current result'); |
563 } | 585 } |
564 _resultValue = value as V; | 586 _resultValue = value as V; |
565 _resultSet = true; | 587 _resultSet = true; |
566 } | 588 } |
567 | 589 |
568 @override | 590 @override |
| 591 bool get flushOnAccess => input.flushOnAccess; |
| 592 |
| 593 @override |
569 V get inputValue { | 594 V get inputValue { |
570 if (_state != _AFTER) { | 595 if (_state != _AFTER) { |
571 throw new StateError('Result value has not been created'); | 596 throw new StateError('Result value has not been created'); |
572 } | 597 } |
573 return _resultValue; | 598 return _resultValue; |
574 } | 599 } |
575 | 600 |
576 @override | 601 @override |
577 void currentValueNotAvailable() { | 602 void currentValueNotAvailable() { |
578 if (_state != _AT) { | 603 if (_state != _AT) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 @override | 692 @override |
668 void set currentValue(Object value) { | 693 void set currentValue(Object value) { |
669 if (currentBuilder == null) { | 694 if (currentBuilder == null) { |
670 throw new StateError( | 695 throw new StateError( |
671 'Cannot set the result value when there is no current result'); | 696 'Cannot set the result value when there is no current result'); |
672 } | 697 } |
673 currentBuilder.currentValue = value; | 698 currentBuilder.currentValue = value; |
674 } | 699 } |
675 | 700 |
676 @override | 701 @override |
| 702 bool get flushOnAccess => currentBuilder.flushOnAccess; |
| 703 |
| 704 @override |
677 Map<String, Object> get inputValue { | 705 Map<String, Object> get inputValue { |
678 if (nameIndex < inputNames.length) { | 706 if (nameIndex < inputNames.length) { |
679 throw new StateError('Result value has not been created'); | 707 throw new StateError('Result value has not been created'); |
680 } | 708 } |
681 return inputs; | 709 return inputs; |
682 } | 710 } |
683 | 711 |
684 /** | 712 /** |
685 * Assuming that there is a current input, return its name. | 713 * Assuming that there is a current input, return its name. |
686 */ | 714 */ |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 @override | 848 @override |
821 void set currentValue(Object value) { | 849 void set currentValue(Object value) { |
822 if (currentBuilder == null) { | 850 if (currentBuilder == null) { |
823 throw new StateError( | 851 throw new StateError( |
824 'Cannot set the result value when there is no current result'); | 852 'Cannot set the result value when there is no current result'); |
825 } | 853 } |
826 currentBuilder.currentValue = value; | 854 currentBuilder.currentValue = value; |
827 } | 855 } |
828 | 856 |
829 @override | 857 @override |
| 858 bool get flushOnAccess => currentBuilder.flushOnAccess; |
| 859 |
| 860 @override |
830 C get inputValue { | 861 C get inputValue { |
831 if (currentBuilder != null || _resultValue == null) { | 862 if (currentBuilder != null || _resultValue == null) { |
832 throw new StateError('Result value has not been created'); | 863 throw new StateError('Result value has not been created'); |
833 } | 864 } |
834 return _resultValue; | 865 return _resultValue; |
835 } | 866 } |
836 | 867 |
837 /** | 868 /** |
838 * The list of values being built. | 869 * The list of values being built. |
839 */ | 870 */ |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 return false; | 918 return false; |
888 } | 919 } |
889 _baseListElement = _baseList[_baseListIndex]; | 920 _baseListElement = _baseList[_baseListIndex]; |
890 currentBuilder = input.generateTaskInputs(_baseListElement).createBuilder(); | 921 currentBuilder = input.generateTaskInputs(_baseListElement).createBuilder(); |
891 return currentBuilder.moveNext(); | 922 return currentBuilder.moveNext(); |
892 } | 923 } |
893 | 924 |
894 void _addResultElement(B baseElement, E resultElement); | 925 void _addResultElement(B baseElement, E resultElement); |
895 void _initResultValue(); | 926 void _initResultValue(); |
896 } | 927 } |
OLD | NEW |