| Index: pkg/analyzer/lib/src/task/inputs.dart
|
| diff --git a/pkg/analyzer/lib/src/task/inputs.dart b/pkg/analyzer/lib/src/task/inputs.dart
|
| index 5efac2c03a34c3dfe415ffb7e07622b6223e9f43..8f8c56c5e3cd78c35bd441bba7c77d8edabce95e 100644
|
| --- a/pkg/analyzer/lib/src/task/inputs.dart
|
| +++ b/pkg/analyzer/lib/src/task/inputs.dart
|
| @@ -16,6 +16,11 @@ import 'package:analyzer/task/model.dart';
|
| typedef TaskInput<E> GenerateTaskInputs<B, E>(B object);
|
|
|
| /**
|
| + * A function that maps one [value] to another value.
|
| + */
|
| +typedef R Mapper<P, R>(P value);
|
| +
|
| +/**
|
| * An input to an [AnalysisTask] that is computed by accessing a single result
|
| * defined on a single target.
|
| */
|
| @@ -180,7 +185,7 @@ abstract class MapTaskInputMixin<K, V> implements MapTaskInput<K, V> {
|
| * Finally, each of the task inputs are used to access analysis results,
|
| * and the list of the results is used as the input.
|
| */
|
| -class MapToFlattenListTaskInput<K, V, E> implements TaskInput<List<E>> {
|
| +class MapToFlattenListTaskInput<K, V, E> extends TaskInputImpl<List<E>> {
|
| final MapTaskInput<K, List<V>> base;
|
| final BinaryFunction<K, V, E> mapper;
|
|
|
| @@ -293,10 +298,139 @@ class MapToFlattenListTaskInputBuilder<K, V, E>
|
| }
|
|
|
| /**
|
| + * An input to an [AnalysisTask] that is computed by mapping the value of
|
| + * another task input to a list of values.
|
| + */
|
| +class ObjectToListTaskInput<E> extends TaskInputImpl with ListTaskInputMixin<E>
|
| + implements ListTaskInput<E> {
|
| + /**
|
| + * The input used to compute the value to be mapped.
|
| + */
|
| + final TaskInput baseInput;
|
| +
|
| + /**
|
| + * The function used to map the value of the base input to the list of values.
|
| + */
|
| + final Mapper<Object, List<E>> mapper;
|
| +
|
| + /**
|
| + * Initialize a newly created task input that computes the input by accessing
|
| + * the given [result] associated with the given [target].
|
| + */
|
| + ObjectToListTaskInput(this.baseInput, this.mapper);
|
| +
|
| + @override
|
| + TaskInputBuilder<List<E>> createBuilder() =>
|
| + new ObjectToListTaskInputBuilder<E>(this);
|
| +
|
| + @override
|
| + ListTaskInput /*<V>*/ toListOf(ResultDescriptor /*<V>*/ valueResult) {
|
| + return new ListToListTaskInput<E, dynamic /*V*/ >(
|
| + this, valueResult.of as dynamic);
|
| + }
|
| +
|
| + @override
|
| + MapTaskInput<AnalysisTarget, dynamic /*V*/ > toMapOf(
|
| + ResultDescriptor /*<V>*/ valueResult) {
|
| + return new ListToMapTaskInput<AnalysisTarget, dynamic /*V*/ >(
|
| + this, valueResult.of);
|
| + }
|
| +}
|
| +
|
| +/**
|
| + * A [TaskInputBuilder] used to build an input based on a [SimpleTaskInput].
|
| + */
|
| +class ObjectToListTaskInputBuilder<E> implements TaskInputBuilder<List<E>> {
|
| + /**
|
| + * The input being built.
|
| + */
|
| + final ObjectToListTaskInput<E> input;
|
| +
|
| + /**
|
| + * The builder created by the input.
|
| + */
|
| + TaskInputBuilder builder;
|
| +
|
| + /**
|
| + * The value of the input being built, or `null` if the value hasn't been set
|
| + * yet or if no result is available ([currentValueNotAvailable] was called).
|
| + */
|
| + List<E> _inputValue = null;
|
| +
|
| + /**
|
| + * Initialize a newly created task input builder that computes the result
|
| + * specified by the given [input].
|
| + */
|
| + ObjectToListTaskInputBuilder(this.input) {
|
| + builder = input.baseInput.createBuilder();
|
| + }
|
| +
|
| + @override
|
| + ResultDescriptor get currentResult {
|
| + if (builder == null) {
|
| + return null;
|
| + }
|
| + return builder.currentResult;
|
| + }
|
| +
|
| + @override
|
| + AnalysisTarget get currentTarget {
|
| + if (builder == null) {
|
| + return null;
|
| + }
|
| + return builder.currentTarget;
|
| + }
|
| +
|
| + @override
|
| + void set currentValue(Object value) {
|
| + if (builder == null) {
|
| + throw new StateError(
|
| + 'Cannot set the result value when there is no current result');
|
| + }
|
| + builder.currentValue = value;
|
| + }
|
| +
|
| + @override
|
| + List<E> get inputValue {
|
| + if (builder != null) {
|
| + throw new StateError('Result value has not been created');
|
| + }
|
| + return _inputValue;
|
| + }
|
| +
|
| + @override
|
| + void currentValueNotAvailable() {
|
| + if (builder == null) {
|
| + throw new StateError(
|
| + 'Cannot set the result value when there is no current result');
|
| + }
|
| + builder.currentValueNotAvailable();
|
| + }
|
| +
|
| + @override
|
| + bool moveNext() {
|
| + if (builder == null) {
|
| + return false;
|
| + } else if (builder.moveNext()) {
|
| + return true;
|
| + } else {
|
| + // This might not be the right semantics. If the value could not be
|
| + // computed then we pass the resulting `null` in to the mapper function.
|
| + // Unfortunately, we cannot tell the difference between a `null` that's
|
| + // there because no value could be computed and a `null` that's there
|
| + // because that's what *was* computed.
|
| + _inputValue = input.mapper(builder.inputValue);
|
| + builder = null;
|
| + return false;
|
| + }
|
| + }
|
| +}
|
| +
|
| +/**
|
| * An input to an [AnalysisTask] that is computed by accessing a single result
|
| * defined on a single target.
|
| */
|
| -class SimpleTaskInput<V> implements TaskInput<V> {
|
| +class SimpleTaskInput<V> extends TaskInputImpl<V> {
|
| /**
|
| * The target on which the result is defined.
|
| */
|
| @@ -416,6 +550,13 @@ class SimpleTaskInputBuilder<V> implements TaskInputBuilder<V> {
|
| }
|
| }
|
|
|
| +abstract class TaskInputImpl<V> implements TaskInput<V> {
|
| + @override
|
| + ListTaskInput /*<E>*/ mappedToList(List /*<E>*/ mapper(V value)) {
|
| + return new ObjectToListTaskInput(this, mapper);
|
| + }
|
| +}
|
| +
|
| /**
|
| * A [TaskInputBuilder] used to build an input based on one or more other task
|
| * inputs. The task inputs to be built are specified by a table mapping the name
|
| @@ -546,7 +687,7 @@ class TopLevelTaskInputBuilder
|
| * input. Finally, each of the task inputs are used to access analysis results,
|
| * and a collection of the analysis results is used as the input to the task.
|
| */
|
| -abstract class _ListToCollectionTaskInput<B, E, C> implements TaskInput<C> {
|
| +abstract class _ListToCollectionTaskInput<B, E, C> extends TaskInputImpl<C> {
|
| /**
|
| * The accessor used to access the list of elements being mapped.
|
| */
|
|
|