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

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: 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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> UnaryFunction<B, E>(B object);
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 * A description of an input to an [AnalysisTask] that can be used to compute
273 * that input.
274 *
275 * Clients are not expected to subtype this class.
276 */
277 abstract class ListTaskInput<E> extends TaskInput<List<E>> {
278 /**
279 * Return a task input that can be used to compute a list whose elements are
280 * the result of passing the elements of this input to the [mapper] function.
281 */
282 TaskInput<List /*<V>*/ > toList(UnaryFunction<E, Object /*<V>*/ > mapper);
283
284 /**
285 * Return a task input that can be used to compute a list whose elements are
286 * [valueResult]'s associated with those elements.
287 */
288 TaskInput<List /*<V>*/ > toListOf(ResultDescriptor /*<V>*/ valueResult);
289
290 /**
291 * Return a task input that can be used to compute a map whose keys are the
292 * elements of this input and whose values are the result of passing the
293 * corresponding key to the [mapper] function.
294 */
295 TaskInput<Map<E, Object /*V*/ >> toMap(
296 UnaryFunction<E, Object /*<V>*/ > mapper);
297
298 /**
299 * Return a task input that can be used to compute a map whose keys are the
300 * elements of this input and whose values are the [valueResult]'s associated
301 * with those elements.
302 */
303 TaskInput<Map<AnalysisTarget, Object /*V*/ >> toMapOf(
304 ResultDescriptor /*<V>*/ valueResult);
305 }
306
307 /**
247 * A description of an analysis result that can be computed by an [AnalysisTask] . 308 * A description of an analysis result that can be computed by an [AnalysisTask] .
248 * 309 *
249 * Clients are not expected to subtype this class. 310 * Clients are not expected to subtype this class.
250 */ 311 */
251 abstract class ResultDescriptor<V> { 312 abstract class ResultDescriptor<V> {
252 /** 313 /**
253 * Initialize a newly created analysis result to have the given [name]. If a 314 * 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. 315 * composite result is specified, then this result will contribute to it.
255 */ 316 */
256 factory ResultDescriptor(String name, V defaultValue, 317 factory ResultDescriptor(String name, V defaultValue,
257 {CompositeResultDescriptor<V> contributesTo}) = ResultDescriptorImpl; 318 {CompositeResultDescriptor<V> contributesTo}) = ResultDescriptorImpl;
258 319
259 /** 320 /**
260 * Return the default value for results described by this descriptor. 321 * Return the default value for results described by this descriptor.
261 */ 322 */
262 V get defaultValue; 323 V get defaultValue;
263 324
264 /** 325 /**
265 * Return the name of this descriptor. 326 * Return the name of this descriptor.
266 */ 327 */
267 String get name; 328 String get name;
268 329
269 /** 330 /**
270 * Return a task input that can be used to compute this result for the given 331 * Return a task input that can be used to compute this result for the given
271 * [target]. 332 * [target].
272 */ 333 */
273 TaskInput<V> inputFor(AnalysisTarget target); 334 TaskInput<V> of(AnalysisTarget target);
274 } 335 }
275 336
276 /** 337 /**
277 * A description of an [AnalysisTask]. 338 * A description of an [AnalysisTask].
278 */ 339 */
279 abstract class TaskDescriptor { 340 abstract class TaskDescriptor {
280 /** 341 /**
281 * Initialize a newly created task descriptor to have the given [name] and to 342 * 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], 343 * 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 344 * 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. 435 * be computed, or `false` if the inputs have been computed.
375 * 436 *
376 * It is safe to invoke [moveNext] after it has returned `false`. In this case 437 * It is safe to invoke [moveNext] after it has returned `false`. In this case
377 * [moveNext] has no effect and will again return `false`. 438 * [moveNext] has no effect and will again return `false`.
378 * 439 *
379 * Throws a [StateError] if the value of the current result has not been 440 * Throws a [StateError] if the value of the current result has not been
380 * provided using [currentValue]. 441 * provided using [currentValue].
381 */ 442 */
382 bool moveNext(); 443 bool moveNext();
383 } 444 }
OLDNEW
« 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