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

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: 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
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..2345b5c4fd274ca6884388136decd26920b145a4 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> MapTaskInput<B, E>(B object);
Brian Wilkerson 2015/03/24 15:07:11 The name makes it sound like this function is mapp
scheglov 2015/03/24 17:16:39 MapToTaskInput ? ToTaskInput ? UnaryFunction for
+
+/**
* An [AnalysisTarget] wrapper for an [AnalysisContext].
*/
class AnalysisContextTarget implements AnalysisTarget {
@@ -244,6 +251,57 @@ 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>> {
+ /**
+ * Create and return a builder that can be used to build this task input.
+ */
+ TaskInputBuilder<List<E>> createBuilder();
Brian Wilkerson 2015/03/24 15:07:10 We shouldn't need to override this method, but if
scheglov 2015/03/24 17:16:39 Done.
+
+ /**
+ * Return a task input that can be used to compute a map of elements of
+ * this input into some other objects.
Brian Wilkerson 2015/03/24 15:07:11 Perhaps: Return a task input that can be used to
scheglov 2015/03/24 17:16:39 Done.
+ */
+ TaskInput<Map<E, Object>> toMap(MapTaskInput mapper);
Brian Wilkerson 2015/03/24 15:07:11 Given that MapTaskInput returns a TaskInput, shoul
scheglov 2015/03/24 17:16:39 Not quite. It's final result is Map<E, V>, where
+
+ /**
+ * Return a task input that can be used to compute an object for each element
+ * of this input.
Brian Wilkerson 2015/03/24 15:07:11 Perhaps: Return a task input that can be used to
scheglov 2015/03/24 17:16:39 Done.
+ */
+ TaskInput<List> toList(MapTaskInput mapper);
Brian Wilkerson 2015/03/24 15:07:11 Return ListTaskInput, so that they can be chained?
scheglov 2015/03/24 17:16:39 Later.
+
+ /**
+ * Return a task input that can be used to compute a map of elements of
+ * this input into [valueResult]s.
Brian Wilkerson 2015/03/24 15:07:11 Perhaps: Return a task input that can be used to
scheglov 2015/03/24 17:16:39 Done.
+ */
+ TaskInput<Map<E, Object>> toMapOf(ResultDescriptor valueResult);
+}
Brian Wilkerson 2015/03/24 15:07:11 Seems like a corresponding method would be good:
scheglov 2015/03/24 17:16:39 Done.
+
+
+/**
* A description of an analysis result that can be computed by an [AnalysisTask].
*
* Clients are not expected to subtype this class.
@@ -270,7 +328,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);
}
/**

Powered by Google App Engine
This is Rietveld 408576698