Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Unified Diff: pkg/analyzer/lib/task/model.dart

Issue 1005693007: Add toMap / toMapOf / toList (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/task/dart.dart ('k') | pkg/analyzer/test/src/task/driver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/task/model.dart
diff --git a/pkg/analyzer/lib/task/model.dart b/pkg/analyzer/lib/task/model.dart
index c9f475149acd237f40fd1845e0f1f24b4469f356..d7423ee783d51589f23aa17751c6f4b20679995c 100644
--- a/pkg/analyzer/lib/task/model.dart
+++ b/pkg/analyzer/lib/task/model.dart
@@ -27,6 +27,13 @@ typedef AnalysisTask BuildTask(AnalysisContext context, AnalysisTarget target);
typedef Map<String, TaskInput> CreateTaskInputs(AnalysisTarget target);
/**
+ * A function that converts an object of the type [B] into a [TaskInput].
+ * This is used, for example, by a [ListTaskInput] to create task inputs
+ * for each value in a list of values.
+ */
+typedef TaskInput<E> UnaryFunction<B, E>(B object);
+
+/**
* An [AnalysisTarget] wrapper for an [AnalysisContext].
*/
class AnalysisContextTarget implements AnalysisTarget {
@@ -244,6 +251,60 @@ abstract class CompositeResultDescriptor<V> extends ResultDescriptor<V> {
}
/**
+ * A description of a [List]-based analysis result that can be computed by an
+ * [AnalysisTask].
+ *
+ * Clients are not expected to subtype this class.
+ */
+abstract class ListResultDescriptor<E> implements ResultDescriptor<List<E>> {
+ /**
+ * Initialize a newly created analysis result to have the given [name]. If a
+ * composite result is specified, then this result will contribute to it.
+ */
+ factory ListResultDescriptor(String name, List<E> defaultValue,
+ {CompositeResultDescriptor<List<E>> contributesTo}) = ListResultDescriptorImpl<E>;
+
+ @override
+ ListTaskInput<E> of(AnalysisTarget target);
+}
+
+/**
+ * A description of an input to an [AnalysisTask] that can be used to compute
+ * that input.
+ *
+ * Clients are not expected to subtype this class.
+ */
+abstract class ListTaskInput<E> extends TaskInput<List<E>> {
+ /**
+ * Return a task input that can be used to compute a list whose elements are
+ * the result of passing the elements of this input to the [mapper] function.
+ */
+ TaskInput<List /*<V>*/ > toList(UnaryFunction<E, Object /*<V>*/ > mapper);
+
+ /**
+ * Return a task input that can be used to compute a list whose elements are
+ * [valueResult]'s associated with those elements.
+ */
+ TaskInput<List /*<V>*/ > toListOf(ResultDescriptor /*<V>*/ valueResult);
+
+ /**
+ * Return a task input that can be used to compute a map whose keys are the
+ * elements of this input and whose values are the result of passing the
+ * corresponding key to the [mapper] function.
+ */
+ TaskInput<Map<E, Object /*V*/ >> toMap(
+ UnaryFunction<E, Object /*<V>*/ > mapper);
+
+ /**
+ * Return a task input that can be used to compute a map whose keys are the
+ * elements of this input and whose values are the [valueResult]'s associated
+ * with those elements.
+ */
+ TaskInput<Map<AnalysisTarget, Object /*V*/ >> toMapOf(
+ ResultDescriptor /*<V>*/ valueResult);
+}
+
+/**
* A description of an analysis result that can be computed by an [AnalysisTask].
*
* Clients are not expected to subtype this class.
@@ -270,7 +331,7 @@ abstract class ResultDescriptor<V> {
* Return a task input that can be used to compute this result for the given
* [target].
*/
- TaskInput<V> inputFor(AnalysisTarget target);
+ TaskInput<V> of(AnalysisTarget target);
}
/**
« no previous file with comments | « pkg/analyzer/lib/task/dart.dart ('k') | pkg/analyzer/test/src/task/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698