| 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 |
| 11 /** | 11 /** |
| 12 * A function that converts an arbitrary object into a [TaskInput]. This is | 12 * A function that converts an object of the type [B] into a [TaskInput]. |
| 13 * used, for example, by a [ListBasedTaskInput] to create task inputs for each | 13 * This is used, for example, by a [ListToListTaskInput] to create task inputs |
| 14 * value in a list of values. | 14 * for each value in a list of values. |
| 15 */ | 15 */ |
| 16 typedef TaskInput<E> GenerateTaskInputs<E>(Object object); | 16 typedef TaskInput<E> GenerateTaskInputs<B, E>(B object); |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * An input to an [AnalysisTask] that is computed by the following steps. First | 19 * An input to an [AnalysisTask] that is computed by the following steps. First |
| 20 * another (base) task input is used to compute a [List]-valued result. An input | 20 * another (base) task input is used to compute a [List]-valued result. An input |
| 21 * generator function is then used to map each element of that list to a task | 21 * generator function is then used to map each element of that list to a task |
| 22 * input. Finally, each of the task inputs are used to access analysis results, | 22 * input. Finally, each of the task inputs are used to access analysis results, |
| 23 * and the list of the analysis results is used as the input to the task. | 23 * and the list of the analysis results is used as the input to the task. |
| 24 */ | 24 */ |
| 25 class ListBasedTaskInput<B, E> | 25 class ListToListTaskInput<B, E> |
| 26 extends _CollectionBasedTaskInput<B, E, List<E>> { | 26 extends _ListToCollectionTaskInput<B, E, List<E>> { |
| 27 /** | 27 /** |
| 28 * Initialize a result accessor to use the given [baseAccessor] to access a | 28 * Initialize a result accessor to use the given [baseAccessor] to access a |
| 29 * list of values that can be passed to the given [generateTaskInputs] to | 29 * list of values that can be passed to the given [generateTaskInputs] to |
| 30 * generate a list of task inputs that can be used to access the elements of | 30 * generate a list of task inputs that can be used to access the elements of |
| 31 * the input being accessed. | 31 * the input being accessed. |
| 32 */ | 32 */ |
| 33 ListBasedTaskInput( | 33 ListToListTaskInput(TaskInput<List<B>> baseAccessor, |
| 34 TaskInput<List<B>> baseAccessor, GenerateTaskInputs<E> generateTaskInputs) | 34 GenerateTaskInputs<B, E> generateTaskInputs) |
| 35 : super(baseAccessor, generateTaskInputs); | 35 : super(baseAccessor, generateTaskInputs); |
| 36 | 36 |
| 37 @override | 37 @override |
| 38 TaskInputBuilder<List<E>> createBuilder() => | 38 TaskInputBuilder<List<E>> createBuilder() => |
| 39 new ListBasedTaskInputBuilder<B, E>(this); | 39 new ListToListTaskInputBuilder<B, E>(this); |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * A [TaskInputBuilder] used to build an input based on a [ListBasedTaskInput]. | 43 * A [TaskInputBuilder] used to build an input based on a [ListToListTaskInput]. |
| 44 */ | 44 */ |
| 45 class ListBasedTaskInputBuilder<B, E> | 45 class ListToListTaskInputBuilder<B, E> |
| 46 extends _CollectionBasedTaskInputBuilder<B, E, List<E>> { | 46 extends _ListToCollectionTaskInputBuilder<B, E, List<E>> { |
| 47 /** | 47 /** |
| 48 * The list of values being built. | 48 * The list of values being built. |
| 49 */ | 49 */ |
| 50 List<E> _resultValue; | 50 List<E> _resultValue; |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Initialize a newly created task input builder that computes the result | 53 * Initialize a newly created task input builder that computes the result |
| 54 * specified by the given [input]. | 54 * specified by the given [input]. |
| 55 */ | 55 */ |
| 56 ListBasedTaskInputBuilder(ListBasedTaskInput<B, E> input) : super(input); | 56 ListToListTaskInputBuilder(ListToListTaskInput<B, E> input) : super(input); |
| 57 | 57 |
| 58 @override | 58 @override |
| 59 void _addResultElement(B baseElement, E resultElement) { | 59 void _addResultElement(B baseElement, E resultElement) { |
| 60 _resultValue.add(resultElement); | 60 _resultValue.add(resultElement); |
| 61 } | 61 } |
| 62 | 62 |
| 63 @override | 63 @override |
| 64 void _initResultValue() { | 64 void _initResultValue() { |
| 65 _resultValue = <E>[]; | 65 _resultValue = <E>[]; |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * An input to an [AnalysisTask] that is computed by the following steps. First | 70 * An input to an [AnalysisTask] that is computed by the following steps. First |
| 71 * another (base) task input is used to compute a [List]-valued result. An input | 71 * another (base) task input is used to compute a [List]-valued result. An input |
| 72 * generator function is then used to map each element of that list to a task | 72 * generator function is then used to map each element of that list to a task |
| 73 * input. Finally, each of the task inputs are used to access analysis results, | 73 * input. Finally, each of the task inputs are used to access analysis results, |
| 74 * and the map of the base elements to the analysis results is used as the | 74 * and the map of the base elements to the analysis results is used as the |
| 75 * input to the task. | 75 * input to the task. |
| 76 */ | 76 */ |
| 77 class MapBasedTaskInput<B, E> | 77 class ListToMapTaskInput<B, E> |
| 78 extends _CollectionBasedTaskInput<B, E, Map<B, E>> { | 78 extends _ListToCollectionTaskInput<B, E, Map<B, E>> { |
| 79 /** | 79 /** |
| 80 * Initialize a result accessor to use the given [baseAccessor] to access a | 80 * Initialize a result accessor to use the given [baseAccessor] to access a |
| 81 * list of values that can be passed to the given [generateTaskInputs] to | 81 * list of values that can be passed to the given [generateTaskInputs] to |
| 82 * generate a list of task inputs that can be used to access the elements of | 82 * generate a list of task inputs that can be used to access the elements of |
| 83 * the input being accessed. | 83 * the input being accessed. |
| 84 */ | 84 */ |
| 85 MapBasedTaskInput( | 85 ListToMapTaskInput(TaskInput<List<B>> baseAccessor, |
| 86 TaskInput<List<B>> baseAccessor, GenerateTaskInputs<E> generateTaskInputs) | 86 GenerateTaskInputs<B, E> generateTaskInputs) |
| 87 : super(baseAccessor, generateTaskInputs); | 87 : super(baseAccessor, generateTaskInputs); |
| 88 | 88 |
| 89 @override | 89 @override |
| 90 TaskInputBuilder<Map<B, E>> createBuilder() => | 90 TaskInputBuilder<Map<B, E>> createBuilder() => |
| 91 new MapBasedTaskInputBuilder<B, E>(this); | 91 new ListToMapTaskInputBuilder<B, E>(this); |
| 92 } | 92 } |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * A [TaskInputBuilder] used to build an input based on a [MapBasedTaskInput]. | 95 * A [TaskInputBuilder] used to build an input based on a [ListToMapTaskInput]. |
| 96 */ | 96 */ |
| 97 class MapBasedTaskInputBuilder<B, E> | 97 class ListToMapTaskInputBuilder<B, E> |
| 98 extends _CollectionBasedTaskInputBuilder<B, E, Map<B, E>> { | 98 extends _ListToCollectionTaskInputBuilder<B, E, Map<B, E>> { |
| 99 /** | 99 /** |
| 100 * The map being built. | 100 * The map being built. |
| 101 */ | 101 */ |
| 102 Map<B, E> _resultValue; | 102 Map<B, E> _resultValue; |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * Initialize a newly created task input builder that computes the result | 105 * Initialize a newly created task input builder that computes the result |
| 106 * specified by the given [input]. | 106 * specified by the given [input]. |
| 107 */ | 107 */ |
| 108 MapBasedTaskInputBuilder(MapBasedTaskInput<B, E> input) : super(input); | 108 ListToMapTaskInputBuilder(ListToMapTaskInput<B, E> input) : super(input); |
| 109 | 109 |
| 110 @override | 110 @override |
| 111 void _addResultElement(B baseElement, E resultElement) { | 111 void _addResultElement(B baseElement, E resultElement) { |
| 112 _resultValue[baseElement] = resultElement; | 112 _resultValue[baseElement] = resultElement; |
| 113 } | 113 } |
| 114 | 114 |
| 115 @override | 115 @override |
| 116 void _initResultValue() { | 116 void _initResultValue() { |
| 117 _resultValue = new HashMap<B, E>(); | 117 _resultValue = new HashMap<B, E>(); |
| 118 } | 118 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 /** | 346 /** |
| 347 * An input to an [AnalysisTask] that is computed by the following steps. First | 347 * An input to an [AnalysisTask] that is computed by the following steps. First |
| 348 * another (base) task input is used to compute a [List]-valued result. An input | 348 * another (base) task input is used to compute a [List]-valued result. An input |
| 349 * generator function is then used to map each element of that list to a task | 349 * generator function is then used to map each element of that list to a task |
| 350 * input. Finally, each of the task inputs are used to access analysis results, | 350 * input. Finally, each of the task inputs are used to access analysis results, |
| 351 * and a collection of the analysis results is used as the input to the task. | 351 * and a collection of the analysis results is used as the input to the task. |
| 352 */ | 352 */ |
| 353 abstract class _CollectionBasedTaskInput<B, E, C> implements TaskInput<C> { | 353 abstract class _ListToCollectionTaskInput<B, E, C> implements TaskInput<C> { |
| 354 /** | 354 /** |
| 355 * The accessor used to access the list of elements being mapped. | 355 * The accessor used to access the list of elements being mapped. |
| 356 */ | 356 */ |
| 357 final TaskInput<List<B>> baseAccessor; | 357 final TaskInput<List<B>> baseAccessor; |
| 358 | 358 |
| 359 /** | 359 /** |
| 360 * The function used to convert an element in the list returned by the | 360 * The function used to convert an element in the list returned by the |
| 361 * [baseAccessor] to a task input. | 361 * [baseAccessor] to a task input. |
| 362 */ | 362 */ |
| 363 final GenerateTaskInputs<E> generateTaskInputs; | 363 final GenerateTaskInputs<B, E> generateTaskInputs; |
| 364 | 364 |
| 365 /** | 365 /** |
| 366 * Initialize a result accessor to use the given [baseAccessor] to access a | 366 * Initialize a result accessor to use the given [baseAccessor] to access a |
| 367 * list of values that can be passed to the given [generateTaskInputs] to | 367 * list of values that can be passed to the given [generateTaskInputs] to |
| 368 * generate a list of task inputs that can be used to access the elements of | 368 * generate a list of task inputs that can be used to access the elements of |
| 369 * the input being accessed. | 369 * the input being accessed. |
| 370 */ | 370 */ |
| 371 _CollectionBasedTaskInput(this.baseAccessor, this.generateTaskInputs); | 371 _ListToCollectionTaskInput(this.baseAccessor, this.generateTaskInputs); |
| 372 } | 372 } |
| 373 | 373 |
| 374 /** | 374 /** |
| 375 * A [TaskInputBuilder] used to build an [_CollectionBasedTaskInput]. | 375 * A [TaskInputBuilder] used to build an [_ListToCollectionTaskInput]. |
| 376 */ | 376 */ |
| 377 abstract class _CollectionBasedTaskInputBuilder<B, E, C> | 377 abstract class _ListToCollectionTaskInputBuilder<B, E, C> |
| 378 implements TaskInputBuilder<C> { | 378 implements TaskInputBuilder<C> { |
| 379 /** | 379 /** |
| 380 * The input being built. | 380 * The input being built. |
| 381 */ | 381 */ |
| 382 final _CollectionBasedTaskInput<B, E, C> input; | 382 final _ListToCollectionTaskInput<B, E, C> input; |
| 383 | 383 |
| 384 /** | 384 /** |
| 385 * The builder used to build the current result. | 385 * The builder used to build the current result. |
| 386 */ | 386 */ |
| 387 TaskInputBuilder currentBuilder; | 387 TaskInputBuilder currentBuilder; |
| 388 | 388 |
| 389 /** | 389 /** |
| 390 * The list of values computed by the [input]'s base accessor. | 390 * The list of values computed by the [input]'s base accessor. |
| 391 */ | 391 */ |
| 392 List<B> _baseList = null; | 392 List<B> _baseList = null; |
| 393 | 393 |
| 394 /** | 394 /** |
| 395 * The index in the [_baseList] of the value for which a value is currently | 395 * The index in the [_baseList] of the value for which a value is currently |
| 396 * being built. | 396 * being built. |
| 397 */ | 397 */ |
| 398 int _baseListIndex = -1; | 398 int _baseListIndex = -1; |
| 399 | 399 |
| 400 /** | 400 /** |
| 401 * The element of the [_baseList] for which a value is currently being built. | 401 * The element of the [_baseList] for which a value is currently being built. |
| 402 */ | 402 */ |
| 403 B _baseListElement; | 403 B _baseListElement; |
| 404 | 404 |
| 405 /** | 405 /** |
| 406 * Initialize a newly created task input builder that computes the result | 406 * Initialize a newly created task input builder that computes the result |
| 407 * specified by the given [input]. | 407 * specified by the given [input]. |
| 408 */ | 408 */ |
| 409 _CollectionBasedTaskInputBuilder(this.input); | 409 _ListToCollectionTaskInputBuilder(this.input); |
| 410 | 410 |
| 411 @override | 411 @override |
| 412 ResultDescriptor get currentResult { | 412 ResultDescriptor get currentResult { |
| 413 if (currentBuilder == null) { | 413 if (currentBuilder == null) { |
| 414 return null; | 414 return null; |
| 415 } | 415 } |
| 416 return currentBuilder.currentResult; | 416 return currentBuilder.currentResult; |
| 417 } | 417 } |
| 418 | 418 |
| 419 @override | 419 @override |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 return false; | 478 return false; |
| 479 } | 479 } |
| 480 _baseListElement = _baseList[_baseListIndex]; | 480 _baseListElement = _baseList[_baseListIndex]; |
| 481 currentBuilder = input.generateTaskInputs(_baseListElement).createBuilder(); | 481 currentBuilder = input.generateTaskInputs(_baseListElement).createBuilder(); |
| 482 return currentBuilder.moveNext(); | 482 return currentBuilder.moveNext(); |
| 483 } | 483 } |
| 484 | 484 |
| 485 void _addResultElement(B baseElement, E resultElement); | 485 void _addResultElement(B baseElement, E resultElement); |
| 486 void _initResultValue(); | 486 void _initResultValue(); |
| 487 } | 487 } |
| OLD | NEW |