| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 * the given [result] associated with the given [target]. | 81 * the given [result] associated with the given [target]. |
| 82 */ | 82 */ |
| 83 ListTaskInputImpl(AnalysisTarget target, ResultDescriptor<List<E>> result) | 83 ListTaskInputImpl(AnalysisTarget target, ResultDescriptor<List<E>> result) |
| 84 : super._unflushable(target, result); | 84 : super._unflushable(target, result); |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * A mixin-ready implementation of [ListTaskInput]. | 88 * A mixin-ready implementation of [ListTaskInput]. |
| 89 */ | 89 */ |
| 90 abstract class ListTaskInputMixin<E> implements ListTaskInput<E> { | 90 abstract class ListTaskInputMixin<E> implements ListTaskInput<E> { |
| 91 @override |
| 92 ListTaskInput /*<V>*/ toFlattenListOf( |
| 93 ListResultDescriptor /*<V>*/ subListResult) { |
| 94 return new ListToFlattenListTaskInput<E, dynamic /*V*/ >( |
| 95 this, subListResult.of as dynamic); |
| 96 } |
| 97 |
| 91 ListTaskInput /*<V>*/ toList(UnaryFunction<E, dynamic /*<V>*/ > mapper) { | 98 ListTaskInput /*<V>*/ toList(UnaryFunction<E, dynamic /*<V>*/ > mapper) { |
| 92 return new ListToListTaskInput<E, dynamic /*V*/ >(this, mapper); | 99 return new ListToListTaskInput<E, dynamic /*V*/ >(this, mapper); |
| 93 } | 100 } |
| 94 | 101 |
| 95 ListTaskInput /*<V>*/ toListOf(ResultDescriptor /*<V>*/ valueResult) { | 102 ListTaskInput /*<V>*/ toListOf(ResultDescriptor /*<V>*/ valueResult) { |
| 96 return (this as ListTaskInputImpl<AnalysisTarget>).toList(valueResult.of); | 103 return (this as ListTaskInput<AnalysisTarget>).toList(valueResult.of); |
| 97 } | 104 } |
| 98 | 105 |
| 99 MapTaskInput<E, dynamic /*V*/ > toMap( | 106 MapTaskInput<E, dynamic /*V*/ > toMap( |
| 100 UnaryFunction<E, dynamic /*<V>*/ > mapper) { | 107 UnaryFunction<E, dynamic /*<V>*/ > mapper) { |
| 101 return new ListToMapTaskInput<E, dynamic /*V*/ >(this, mapper); | 108 return new ListToMapTaskInput<E, dynamic /*V*/ >(this, mapper); |
| 102 } | 109 } |
| 103 | 110 |
| 104 MapTaskInput<AnalysisTarget, dynamic /*V*/ > toMapOf( | 111 MapTaskInput<AnalysisTarget, dynamic /*V*/ > toMapOf( |
| 105 ResultDescriptor /*<V>*/ valueResult) { | 112 ResultDescriptor /*<V>*/ valueResult) { |
| 106 return (this as ListTaskInputImpl<AnalysisTarget>).toMap(valueResult.of); | 113 return (this as ListTaskInputImpl<AnalysisTarget>).toMap(valueResult.of); |
| 107 } | 114 } |
| 108 } | 115 } |
| 109 | 116 |
| 110 /** | 117 /** |
| 111 * An input to an [AnalysisTask] that is computed by the following steps. First | 118 * An input to an [AnalysisTask] that is computed by the following steps. First |
| 112 * another (base) task input is used to compute a [List]-valued result. An input | 119 * another (base) task input is used to compute a [List]-valued result. An input |
| 113 * generator function is then used to map each element of that list to a task | 120 * generator function is then used to map each element of that list to a task |
| 114 * input. Finally, each of the task inputs are used to access analysis results, | 121 * input. Finally, each of the task inputs are used to access analysis results, |
| 115 * and the list of the analysis results is used as the input to the task. | 122 * and the list of the analysis results is used as the input to the task. |
| 116 */ | 123 */ |
| 124 class ListToFlattenListTaskInput<B, E> |
| 125 extends _ListToCollectionTaskInput<B, E, List<E>> |
| 126 with ListTaskInputMixin<E> |
| 127 implements ListTaskInput<E> { |
| 128 /** |
| 129 * Initialize a result accessor to use the given [baseAccessor] to access a |
| 130 * list of values that can be passed to the given [generateTaskInputs] to |
| 131 * generate a list of task inputs that can be used to access the elements of |
| 132 * the input being accessed. |
| 133 */ |
| 134 ListToFlattenListTaskInput(TaskInput<List<B>> baseAccessor, |
| 135 GenerateTaskInputs<B, E> generateTaskInputs) |
| 136 : super(baseAccessor, generateTaskInputs); |
| 137 |
| 138 @override |
| 139 TaskInputBuilder<List<E>> createBuilder() => |
| 140 new ListToFlattenListTaskInputBuilder<B, E>(this); |
| 141 } |
| 142 |
| 143 /** |
| 144 * A [TaskInputBuilder] used to build an input based on a [ListToFlattenListTask
Input]. |
| 145 */ |
| 146 class ListToFlattenListTaskInputBuilder<B, E> |
| 147 extends _ListToCollectionTaskInputBuilder<B, E, List<E>> { |
| 148 /** |
| 149 * The list of values being built. |
| 150 */ |
| 151 List<E> _resultValue; |
| 152 |
| 153 /** |
| 154 * Initialize a newly created task input builder that computes the result |
| 155 * specified by the given [input]. |
| 156 */ |
| 157 ListToFlattenListTaskInputBuilder(ListToFlattenListTaskInput<B, E> input) |
| 158 : super(input); |
| 159 |
| 160 @override |
| 161 void _addResultElement(B baseElement, E resultElement) { |
| 162 _resultValue.addAll(resultElement as Iterable); |
| 163 } |
| 164 |
| 165 @override |
| 166 void _initResultValue() { |
| 167 _resultValue = <E>[]; |
| 168 } |
| 169 } |
| 170 |
| 171 /** |
| 172 * An input to an [AnalysisTask] that is computed by the following steps. First |
| 173 * another (base) task input is used to compute a [List]-valued result. An input |
| 174 * generator function is then used to map each element of that list to a task |
| 175 * input. Finally, each of the task inputs are used to access analysis results, |
| 176 * and the list of the analysis results is used as the input to the task. |
| 177 */ |
| 117 class ListToListTaskInput<B, E> | 178 class ListToListTaskInput<B, E> |
| 118 extends _ListToCollectionTaskInput<B, E, List<E>> | 179 extends _ListToCollectionTaskInput<B, E, List<E>> |
| 119 with ListTaskInputMixin<E> { | 180 with ListTaskInputMixin<E> { |
| 120 /** | 181 /** |
| 121 * Initialize a result accessor to use the given [baseAccessor] to access a | 182 * Initialize a result accessor to use the given [baseAccessor] to access a |
| 122 * list of values that can be passed to the given [generateTaskInputs] to | 183 * list of values that can be passed to the given [generateTaskInputs] to |
| 123 * generate a list of task inputs that can be used to access the elements of | 184 * generate a list of task inputs that can be used to access the elements of |
| 124 * the input being accessed. | 185 * the input being accessed. |
| 125 */ | 186 */ |
| 126 ListToListTaskInput(TaskInput<List<B>> baseAccessor, | 187 ListToListTaskInput(TaskInput<List<B>> baseAccessor, |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 * Initialize a newly created task input that computes the input by accessing | 433 * Initialize a newly created task input that computes the input by accessing |
| 373 * the given [result] associated with the given [target]. | 434 * the given [result] associated with the given [target]. |
| 374 */ | 435 */ |
| 375 ObjectToListTaskInput(this.baseInput, this.mapper); | 436 ObjectToListTaskInput(this.baseInput, this.mapper); |
| 376 | 437 |
| 377 @override | 438 @override |
| 378 TaskInputBuilder<List<E>> createBuilder() => | 439 TaskInputBuilder<List<E>> createBuilder() => |
| 379 new ObjectToListTaskInputBuilder<E>(this); | 440 new ObjectToListTaskInputBuilder<E>(this); |
| 380 | 441 |
| 381 @override | 442 @override |
| 443 ListTaskInput /*<V>*/ toFlattenListOf( |
| 444 ListResultDescriptor /*<V>*/ subListResult) { |
| 445 return new ListToFlattenListTaskInput<E, dynamic /*V*/ >( |
| 446 this, subListResult.of as dynamic); |
| 447 } |
| 448 |
| 449 @override |
| 382 ListTaskInput /*<V>*/ toListOf(ResultDescriptor /*<V>*/ valueResult) { | 450 ListTaskInput /*<V>*/ toListOf(ResultDescriptor /*<V>*/ valueResult) { |
| 383 return new ListToListTaskInput<E, dynamic /*V*/ >( | 451 return new ListToListTaskInput<E, dynamic /*V*/ >( |
| 384 this, valueResult.of as dynamic); | 452 this, valueResult.of as dynamic); |
| 385 } | 453 } |
| 386 | 454 |
| 387 @override | 455 @override |
| 388 MapTaskInput<AnalysisTarget, dynamic /*V*/ > toMapOf( | 456 MapTaskInput<AnalysisTarget, dynamic /*V*/ > toMapOf( |
| 389 ResultDescriptor /*<V>*/ valueResult) { | 457 ResultDescriptor /*<V>*/ valueResult) { |
| 390 return new ListToMapTaskInput<AnalysisTarget, dynamic /*V*/ >( | 458 return new ListToMapTaskInput<AnalysisTarget, dynamic /*V*/ >( |
| 391 this as dynamic, valueResult.of); | 459 this as dynamic, valueResult.of); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 return false; | 986 return false; |
| 919 } | 987 } |
| 920 _baseListElement = _baseList[_baseListIndex]; | 988 _baseListElement = _baseList[_baseListIndex]; |
| 921 currentBuilder = input.generateTaskInputs(_baseListElement).createBuilder(); | 989 currentBuilder = input.generateTaskInputs(_baseListElement).createBuilder(); |
| 922 return currentBuilder.moveNext(); | 990 return currentBuilder.moveNext(); |
| 923 } | 991 } |
| 924 | 992 |
| 925 void _addResultElement(B baseElement, E resultElement); | 993 void _addResultElement(B baseElement, E resultElement); |
| 926 void _initResultValue(); | 994 void _initResultValue(); |
| 927 } | 995 } |
| OLD | NEW |