Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 import 'dart:developer'; | 8 import 'dart:developer'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; | 10 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * A function that takes the target for which a task will produce results and | 31 * A function that takes the target for which a task will produce results and |
| 32 * returns a map from input names to descriptions of the analysis results needed | 32 * returns a map from input names to descriptions of the analysis results needed |
| 33 * by the task in order for the task to be performed. Such functions are passed | 33 * by the task in order for the task to be performed. Such functions are passed |
| 34 * to a [TaskDescriptor] to be used to determine the inputs needed by the task. | 34 * to a [TaskDescriptor] to be used to determine the inputs needed by the task. |
| 35 */ | 35 */ |
| 36 typedef Map<String, TaskInput> CreateTaskInputs(AnalysisTarget target); | 36 typedef Map<String, TaskInput> CreateTaskInputs(AnalysisTarget target); |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * A function that takes the target for which a task will produce results and | |
| 40 * returns `true` if the task is appropriate for thetarget. Such functions are | |
|
Paul Berry
2016/01/25 20:12:40
s/thetarget/the target/
Brian Wilkerson
2016/01/25 20:27:36
Done
| |
| 41 * passed to a [TaskDescriptor] to be used to determine the inputs needed by the | |
| 42 * task. | |
| 43 */ | |
| 44 typedef bool IsAppropriateFor(AnalysisTarget target); | |
| 45 | |
| 46 /** | |
| 39 * A function that converts an object of the type [B] into a [TaskInput]. | 47 * A function that converts an object of the type [B] into a [TaskInput]. |
| 40 * This is used, for example, by a [ListTaskInput] to create task inputs | 48 * This is used, for example, by a [ListTaskInput] to create task inputs |
| 41 * for each value in a list of values. | 49 * for each value in a list of values. |
| 42 */ | 50 */ |
| 43 typedef TaskInput<E> UnaryFunction<B, E>(B object); | 51 typedef TaskInput<E> UnaryFunction<B, E>(B object); |
| 44 | 52 |
| 45 /** | 53 /** |
| 46 * An [AnalysisTarget] wrapper for an [AnalysisContext]. | 54 * An [AnalysisTarget] wrapper for an [AnalysisContext]. |
| 47 */ | 55 */ |
| 48 class AnalysisContextTarget implements AnalysisTarget { | 56 class AnalysisContextTarget implements AnalysisTarget { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 * A description of an input to an [AnalysisTask] that can be used to compute | 356 * A description of an input to an [AnalysisTask] that can be used to compute |
| 349 * that input. | 357 * that input. |
| 350 * | 358 * |
| 351 * Clients may not extend, implement or mix-in this class. | 359 * Clients may not extend, implement or mix-in this class. |
| 352 */ | 360 */ |
| 353 abstract class ListTaskInput<E> implements TaskInput<List<E>> { | 361 abstract class ListTaskInput<E> implements TaskInput<List<E>> { |
| 354 /** | 362 /** |
| 355 * Return a task input that can be used to compute a flatten list whose | 363 * Return a task input that can be used to compute a flatten list whose |
| 356 * elements are combined [subListResult]'s associated with those elements. | 364 * elements are combined [subListResult]'s associated with those elements. |
| 357 */ | 365 */ |
| 358 ListTaskInput /*<V>*/ toFlattenListOf /*<V>*/ ( | 366 ListTaskInput/*<V>*/ toFlattenListOf/*<V>*/( |
| 359 ListResultDescriptor /*<V>*/ subListResult); | 367 ListResultDescriptor/*<V>*/ subListResult); |
| 360 | 368 |
| 361 /** | 369 /** |
| 362 * Return a task input that can be used to compute a list whose elements are | 370 * Return a task input that can be used to compute a list whose elements are |
| 363 * the result of passing the elements of this input to the [mapper] function. | 371 * the result of passing the elements of this input to the [mapper] function. |
| 364 */ | 372 */ |
| 365 ListTaskInput /*<V>*/ toList /*<V>*/ ( | 373 ListTaskInput/*<V>*/ toList/*<V>*/(UnaryFunction<E, dynamic/*<=V>*/ > mapper); |
| 366 UnaryFunction<E, dynamic /*<=V>*/ > mapper); | |
| 367 | 374 |
| 368 /** | 375 /** |
| 369 * Return a task input that can be used to compute a list whose elements are | 376 * Return a task input that can be used to compute a list whose elements are |
| 370 * [valueResult]'s associated with those elements. | 377 * [valueResult]'s associated with those elements. |
| 371 */ | 378 */ |
| 372 ListTaskInput /*<V>*/ toListOf /*<V>*/ (ResultDescriptor /*<V>*/ valueResult); | 379 ListTaskInput/*<V>*/ toListOf/*<V>*/(ResultDescriptor/*<V>*/ valueResult); |
| 373 | 380 |
| 374 /** | 381 /** |
| 375 * Return a task input that can be used to compute a map whose keys are the | 382 * Return a task input that can be used to compute a map whose keys are the |
| 376 * elements of this input and whose values are the result of passing the | 383 * elements of this input and whose values are the result of passing the |
| 377 * corresponding key to the [mapper] function. | 384 * corresponding key to the [mapper] function. |
| 378 */ | 385 */ |
| 379 MapTaskInput<E, dynamic /*=V*/ > toMap /*<V>*/ ( | 386 MapTaskInput<E, dynamic/*=V*/ > toMap/*<V>*/( |
| 380 UnaryFunction<E, dynamic /*=V*/ > mapper); | 387 UnaryFunction<E, dynamic/*=V*/ > mapper); |
| 381 | 388 |
| 382 /** | 389 /** |
| 383 * Return a task input that can be used to compute a map whose keys are the | 390 * Return a task input that can be used to compute a map whose keys are the |
| 384 * elements of this input and whose values are the [valueResult]'s associated | 391 * elements of this input and whose values are the [valueResult]'s associated |
| 385 * with those elements. | 392 * with those elements. |
| 386 */ | 393 */ |
| 387 MapTaskInput<AnalysisTarget, dynamic /*=V*/ > toMapOf /*<V>*/ ( | 394 MapTaskInput<AnalysisTarget, dynamic/*=V*/ > toMapOf/*<V>*/( |
| 388 ResultDescriptor /*<V>*/ valueResult); | 395 ResultDescriptor/*<V>*/ valueResult); |
| 389 } | 396 } |
| 390 | 397 |
| 391 /** | 398 /** |
| 392 * A description of an input with a [Map] based values. | 399 * A description of an input with a [Map] based values. |
| 393 * | 400 * |
| 394 * Clients may not extend, implement or mix-in this class. | 401 * Clients may not extend, implement or mix-in this class. |
| 395 */ | 402 */ |
| 396 abstract class MapTaskInput<K, V> implements TaskInput<Map<K, V>> { | 403 abstract class MapTaskInput<K, V> implements TaskInput<Map<K, V>> { |
| 397 /** | 404 /** |
| 398 * [V] must be a [List]. | 405 * [V] must be a [List]. |
| 399 * Return a task input that can be used to compute a list whose elements are | 406 * Return a task input that can be used to compute a list whose elements are |
| 400 * the result of passing keys [K] and the corresponding elements of [V] to | 407 * the result of passing keys [K] and the corresponding elements of [V] to |
| 401 * the [mapper] function. | 408 * the [mapper] function. |
| 402 */ | 409 */ |
| 403 TaskInput<List /*<E>*/ > toFlattenList /*<E>*/ ( | 410 TaskInput<List/*<E>*/ > toFlattenList/*<E>*/( |
| 404 BinaryFunction<K, dynamic /*element of V*/, dynamic /*=E*/ > mapper); | 411 BinaryFunction<K, dynamic /*element of V*/, dynamic/*=E*/ > mapper); |
| 405 } | 412 } |
| 406 | 413 |
| 407 /** | 414 /** |
| 408 * A policy object that can compute sizes of results and provide the maximum | 415 * A policy object that can compute sizes of results and provide the maximum |
| 409 * active and idle sizes that can be kept in the cache. | 416 * active and idle sizes that can be kept in the cache. |
| 410 * | 417 * |
| 411 * All the [ResultDescriptor]s with the same [ResultCachingPolicy] instance | 418 * All the [ResultDescriptor]s with the same [ResultCachingPolicy] instance |
| 412 * share the same total size in a cache. | 419 * share the same total size in a cache. |
| 413 * | 420 * |
| 414 * Clients may implement this class when implementing plugins. | 421 * Clients may implement this class when implementing plugins. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 * | 526 * |
| 520 * Clients may not extend, implement or mix-in this class. | 527 * Clients may not extend, implement or mix-in this class. |
| 521 */ | 528 */ |
| 522 abstract class TaskDescriptor { | 529 abstract class TaskDescriptor { |
| 523 /** | 530 /** |
| 524 * Initialize a newly created task descriptor to have the given [name] and to | 531 * Initialize a newly created task descriptor to have the given [name] and to |
| 525 * describe a task that takes the inputs built using the given [inputBuilder], | 532 * describe a task that takes the inputs built using the given [inputBuilder], |
| 526 * and produces the given [results]. The [buildTask] will be used to create | 533 * and produces the given [results]. The [buildTask] will be used to create |
| 527 * the instance of [AnalysisTask] thusly described. | 534 * the instance of [AnalysisTask] thusly described. |
| 528 */ | 535 */ |
| 529 factory TaskDescriptor( | 536 factory TaskDescriptor(String name, BuildTask buildTask, |
| 530 String name, | 537 CreateTaskInputs inputBuilder, List<ResultDescriptor> results, |
| 531 BuildTask buildTask, | 538 {IsAppropriateFor isAppropriateFor}) = TaskDescriptorImpl; |
| 532 CreateTaskInputs inputBuilder, | |
| 533 List<ResultDescriptor> results) = TaskDescriptorImpl; | |
| 534 | 539 |
| 535 /** | 540 /** |
| 536 * Return the builder used to build the inputs to the task. | 541 * Return the builder used to build the inputs to the task. |
| 537 */ | 542 */ |
| 538 CreateTaskInputs get createTaskInputs; | 543 CreateTaskInputs get createTaskInputs; |
| 539 | 544 |
| 540 /** | 545 /** |
| 541 * Return the name of the task being described. | 546 * Return the name of the task being described. |
| 542 */ | 547 */ |
| 543 String get name; | 548 String get name; |
| 544 | 549 |
| 545 /** | 550 /** |
| 546 * Return a list of the analysis results that will be computed by this task. | 551 * Return a list of the analysis results that will be computed by this task. |
| 547 */ | 552 */ |
| 548 List<ResultDescriptor> get results; | 553 List<ResultDescriptor> get results; |
| 549 | 554 |
| 550 /** | 555 /** |
| 551 * Create and return a task that is described by this descriptor that can be | 556 * Create and return a task that is described by this descriptor that can be |
| 552 * used to compute results based on the given [inputs]. | 557 * used to compute results based on the given [inputs]. |
| 553 */ | 558 */ |
| 554 AnalysisTask createTask(AnalysisContext context, AnalysisTarget target, | 559 AnalysisTask createTask(AnalysisContext context, AnalysisTarget target, |
| 555 Map<String, dynamic> inputs); | 560 Map<String, dynamic> inputs); |
| 561 | |
| 562 /** | |
| 563 * Return `true` if this task is appropriate for the given [target]. | |
| 564 */ | |
| 565 bool isAppropriateFor(AnalysisTarget target); | |
| 556 } | 566 } |
| 557 | 567 |
| 558 /** | 568 /** |
| 559 * A description of an input to an [AnalysisTask] that can be used to compute | 569 * A description of an input to an [AnalysisTask] that can be used to compute |
| 560 * that input. | 570 * that input. |
| 561 * | 571 * |
| 562 * Clients may not extend, implement or mix-in this class. | 572 * Clients may not extend, implement or mix-in this class. |
| 563 */ | 573 */ |
| 564 abstract class TaskInput<V> { | 574 abstract class TaskInput<V> { |
| 565 /** | 575 /** |
| 566 * Create and return a builder that can be used to build this task input. | 576 * Create and return a builder that can be used to build this task input. |
| 567 */ | 577 */ |
| 568 TaskInputBuilder<V> createBuilder(); | 578 TaskInputBuilder<V> createBuilder(); |
| 569 | 579 |
| 570 /** | 580 /** |
| 571 * Return a task input that can be used to compute a list whose elements are | 581 * Return a task input that can be used to compute a list whose elements are |
| 572 * the result of passing the result of this input to the [mapper] function. | 582 * the result of passing the result of this input to the [mapper] function. |
| 573 */ | 583 */ |
| 574 ListTaskInput /*<E>*/ mappedToList /*<E>*/ (List /*<E>*/ mapper(V value)); | 584 ListTaskInput/*<E>*/ mappedToList/*<E>*/(List/*<E>*/ mapper(V value)); |
| 575 } | 585 } |
| 576 | 586 |
| 577 /** | 587 /** |
| 578 * An object used to build the value associated with a single [TaskInput]. | 588 * An object used to build the value associated with a single [TaskInput]. |
| 579 * | 589 * |
| 580 * All builders work by requesting one or more results (each result being | 590 * All builders work by requesting one or more results (each result being |
| 581 * associated with a target). The interaction pattern is modeled after the class | 591 * associated with a target). The interaction pattern is modeled after the class |
| 582 * [Iterator], in which the method [moveNext] is invoked to move from one result | 592 * [Iterator], in which the method [moveNext] is invoked to move from one result |
| 583 * request to the next. The getters [currentResult] and [currentTarget] are used | 593 * request to the next. The getters [currentResult] and [currentTarget] are used |
| 584 * to get the result and target of the current request. The value of the result | 594 * to get the result and target of the current request. The value of the result |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 /** | 746 /** |
| 737 * A work should be done, but without any special urgency. | 747 * A work should be done, but without any special urgency. |
| 738 */ | 748 */ |
| 739 NORMAL, | 749 NORMAL, |
| 740 | 750 |
| 741 /** | 751 /** |
| 742 * Nothing to do. | 752 * Nothing to do. |
| 743 */ | 753 */ |
| 744 NONE | 754 NONE |
| 745 } | 755 } |
| OLD | NEW |