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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
Brian Wilkerson 2015/03/24 15:07:11 This needs to be sorted.
scheglov 2015/03/24 17:16:39 Done.
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.task.model; 5 library analyzer.task.model;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; 9 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
10 import 'package:analyzer/src/generated/java_engine.dart'; 10 import 'package:analyzer/src/generated/java_engine.dart';
11 import 'package:analyzer/src/generated/source.dart'; 11 import 'package:analyzer/src/generated/source.dart';
12 import 'package:analyzer/src/task/model.dart'; 12 import 'package:analyzer/src/task/model.dart';
13 13
14 /** 14 /**
15 * A function that takes an analysis [context] and an analysis [target] and 15 * A function that takes an analysis [context] and an analysis [target] and
16 * returns an analysis task. Such functions are passed to a [TaskDescriptor] to 16 * returns an analysis task. Such functions are passed to a [TaskDescriptor] to
17 * be used to create the described task. 17 * be used to create the described task.
18 */ 18 */
19 typedef AnalysisTask BuildTask(AnalysisContext context, AnalysisTarget target); 19 typedef AnalysisTask BuildTask(AnalysisContext context, AnalysisTarget target);
20 20
21 /** 21 /**
22 * A function that takes the target for which a task will produce results and 22 * A function that takes the target for which a task will produce results and
23 * returns a map from input names to descriptions of the analysis results needed 23 * returns a map from input names to descriptions of the analysis results needed
24 * by the task in order for the task to be performed. Such functions are passed 24 * by the task in order for the task to be performed. Such functions are passed
25 * to a [TaskDescriptor] to be used to determine the inputs needed by the task. 25 * to a [TaskDescriptor] to be used to determine the inputs needed by the task.
26 */ 26 */
27 typedef Map<String, TaskInput> CreateTaskInputs(AnalysisTarget target); 27 typedef Map<String, TaskInput> CreateTaskInputs(AnalysisTarget target);
28 28
29 /** 29 /**
30 * A function that converts an object of the type [B] into a [TaskInput].
31 * This is used, for example, by a [ListTaskInput] to create task inputs
32 * for each value in a list of values.
33 */
34 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
35
36 /**
30 * An [AnalysisTarget] wrapper for an [AnalysisContext]. 37 * An [AnalysisTarget] wrapper for an [AnalysisContext].
31 */ 38 */
32 class AnalysisContextTarget implements AnalysisTarget { 39 class AnalysisContextTarget implements AnalysisTarget {
33 static final AnalysisContextTarget request = new AnalysisContextTarget(null); 40 static final AnalysisContextTarget request = new AnalysisContextTarget(null);
34 41
35 final AnalysisContext context; 42 final AnalysisContext context;
36 43
37 AnalysisContextTarget(this.context); 44 AnalysisContextTarget(this.context);
38 45
39 @override 46 @override
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 /** 244 /**
238 * Return a list containing the descriptors of the results that are unioned 245 * Return a list containing the descriptors of the results that are unioned
239 * together to compose the value of this result. 246 * together to compose the value of this result.
240 * 247 *
241 * Clients must not modify the returned list. 248 * Clients must not modify the returned list.
242 */ 249 */
243 List<ResultDescriptor<V>> get contributors; 250 List<ResultDescriptor<V>> get contributors;
244 } 251 }
245 252
246 /** 253 /**
254 * A description of a [List]-based analysis result that can be computed by an
255 * [AnalysisTask].
256 *
257 * Clients are not expected to subtype this class.
258 */
259 abstract class ListResultDescriptor<E> implements ResultDescriptor<List<E>> {
260 /**
261 * Initialize a newly created analysis result to have the given [name]. If a
262 * composite result is specified, then this result will contribute to it.
263 */
264 factory ListResultDescriptor(String name, List<E> defaultValue,
265 {CompositeResultDescriptor<List<E>> contributesTo}) = ListResultDescriptor Impl<E>;
266
267 @override
268 ListTaskInput<E> of(AnalysisTarget target);
269 }
270
271
272 /**
273 * A description of an input to an [AnalysisTask] that can be used to compute
274 * that input.
275 *
276 * Clients are not expected to subtype this class.
277 */
278 abstract class ListTaskInput<E> extends TaskInput<List<E>> {
279 /**
280 * Create and return a builder that can be used to build this task input.
281 */
282 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.
283
284 /**
285 * Return a task input that can be used to compute a map of elements of
286 * 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.
287 */
288 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
289
290 /**
291 * Return a task input that can be used to compute an object for each element
292 * 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.
293 */
294 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.
295
296 /**
297 * Return a task input that can be used to compute a map of elements of
298 * 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.
299 */
300 TaskInput<Map<E, Object>> toMapOf(ResultDescriptor valueResult);
301 }
Brian Wilkerson 2015/03/24 15:07:11 Seems like a corresponding method would be good:
scheglov 2015/03/24 17:16:39 Done.
302
303
304 /**
247 * A description of an analysis result that can be computed by an [AnalysisTask] . 305 * A description of an analysis result that can be computed by an [AnalysisTask] .
248 * 306 *
249 * Clients are not expected to subtype this class. 307 * Clients are not expected to subtype this class.
250 */ 308 */
251 abstract class ResultDescriptor<V> { 309 abstract class ResultDescriptor<V> {
252 /** 310 /**
253 * Initialize a newly created analysis result to have the given [name]. If a 311 * Initialize a newly created analysis result to have the given [name]. If a
254 * composite result is specified, then this result will contribute to it. 312 * composite result is specified, then this result will contribute to it.
255 */ 313 */
256 factory ResultDescriptor(String name, V defaultValue, 314 factory ResultDescriptor(String name, V defaultValue,
257 {CompositeResultDescriptor<V> contributesTo}) = ResultDescriptorImpl; 315 {CompositeResultDescriptor<V> contributesTo}) = ResultDescriptorImpl;
258 316
259 /** 317 /**
260 * Return the default value for results described by this descriptor. 318 * Return the default value for results described by this descriptor.
261 */ 319 */
262 V get defaultValue; 320 V get defaultValue;
263 321
264 /** 322 /**
265 * Return the name of this descriptor. 323 * Return the name of this descriptor.
266 */ 324 */
267 String get name; 325 String get name;
268 326
269 /** 327 /**
270 * Return a task input that can be used to compute this result for the given 328 * Return a task input that can be used to compute this result for the given
271 * [target]. 329 * [target].
272 */ 330 */
273 TaskInput<V> inputFor(AnalysisTarget target); 331 TaskInput<V> of(AnalysisTarget target);
274 } 332 }
275 333
276 /** 334 /**
277 * A description of an [AnalysisTask]. 335 * A description of an [AnalysisTask].
278 */ 336 */
279 abstract class TaskDescriptor { 337 abstract class TaskDescriptor {
280 /** 338 /**
281 * Initialize a newly created task descriptor to have the given [name] and to 339 * Initialize a newly created task descriptor to have the given [name] and to
282 * describe a task that takes the inputs built using the given [inputBuilder], 340 * describe a task that takes the inputs built using the given [inputBuilder],
283 * and produces the given [results]. The [buildTask] will be used to create 341 * and produces the given [results]. The [buildTask] will be used to create
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 * be computed, or `false` if the inputs have been computed. 432 * be computed, or `false` if the inputs have been computed.
375 * 433 *
376 * It is safe to invoke [moveNext] after it has returned `false`. In this case 434 * It is safe to invoke [moveNext] after it has returned `false`. In this case
377 * [moveNext] has no effect and will again return `false`. 435 * [moveNext] has no effect and will again return `false`.
378 * 436 *
379 * Throws a [StateError] if the value of the current result has not been 437 * Throws a [StateError] if the value of the current result has not been
380 * provided using [currentValue]. 438 * provided using [currentValue].
381 */ 439 */
382 bool moveNext(); 440 bool moveNext();
383 } 441 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698