OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library analyzer.src.task.manager; |
| 6 |
| 7 import 'dart:collection'; |
| 8 |
| 9 import 'package:analyzer/src/generated/java_engine.dart'; |
| 10 import 'package:analyzer/task/model.dart'; |
| 11 |
| 12 /** |
| 13 * An object that manages the information about the tasks that have been |
| 14 * defined. |
| 15 */ |
| 16 class TaskManager { |
| 17 /** |
| 18 * A table mapping [ResultDescriptor]s to a list of [TaskDescriptor]s |
| 19 * for the tasks that can be used to compute the result. |
| 20 */ |
| 21 Map<ResultDescriptor, List<TaskDescriptor>> taskMap = |
| 22 new HashMap<ResultDescriptor, List<TaskDescriptor>>(); |
| 23 |
| 24 /** |
| 25 * A list of the results that are to be computed for all sources within an |
| 26 * analysis root. |
| 27 */ |
| 28 Set<ResultDescriptor> generalResults = new Set<ResultDescriptor>(); |
| 29 |
| 30 /** |
| 31 * A list of the results that are to be computed for priority sources. |
| 32 */ |
| 33 Set<ResultDescriptor> priorityResults = new Set<ResultDescriptor>(); |
| 34 |
| 35 /** |
| 36 * Add the given [result] to the list of results that are to be computed for |
| 37 * all sources within an analysis root. |
| 38 */ |
| 39 void addGeneralResult(ResultDescriptor result) { |
| 40 generalResults.add(result); |
| 41 } |
| 42 |
| 43 /** |
| 44 * Add the given [result] to the list of results that are to be computed for |
| 45 * priority sources. |
| 46 */ |
| 47 void addPriorityResult(ResultDescriptor result) { |
| 48 priorityResults.add(result); |
| 49 } |
| 50 |
| 51 /** |
| 52 * Add the given [descriptor] to the list of analysis task descriptors that |
| 53 * can be used to compute analysis results. |
| 54 */ |
| 55 void addTaskDescriptor(TaskDescriptor descriptor) { |
| 56 descriptor.results.forEach((ResultDescriptor result) { |
| 57 // |
| 58 // Add the result to the task map. |
| 59 // |
| 60 List<TaskDescriptor> descriptors = taskMap[result]; |
| 61 if (descriptors == null) { |
| 62 descriptors = <TaskDescriptor>[]; |
| 63 taskMap[result] = descriptors; |
| 64 } |
| 65 descriptors.add(descriptor); |
| 66 }); |
| 67 } |
| 68 |
| 69 /** |
| 70 * Add the task descriptors in the given list of [descriptors] to the list of |
| 71 * analysis task descriptors that can be used to compute analysis results. |
| 72 */ |
| 73 void addTaskDescriptors(List<TaskDescriptor> descriptors) { |
| 74 descriptors.forEach(addTaskDescriptor); |
| 75 } |
| 76 |
| 77 /** |
| 78 * Find a task that will compute the given [result] for the given [target]. |
| 79 */ |
| 80 TaskDescriptor findTask(AnalysisTarget target, ResultDescriptor result) { |
| 81 List<TaskDescriptor> descriptors = taskMap[result]; |
| 82 if (descriptors == null) { |
| 83 throw new AnalysisException( |
| 84 'No tasks registered to compute $result for $target'); |
| 85 } |
| 86 return _findBestTask(descriptors); |
| 87 } |
| 88 |
| 89 /** |
| 90 * Remove the given [result] from the list of results that are to be computed |
| 91 * for all sources within an analysis root. |
| 92 */ |
| 93 void removeGeneralResult(ResultDescriptor result) { |
| 94 generalResults.remove(result); |
| 95 } |
| 96 |
| 97 /** |
| 98 * Remove the given [result] from the list of results that are to be computed |
| 99 * for priority sources. |
| 100 */ |
| 101 void removePriorityResult(ResultDescriptor result) { |
| 102 priorityResults.remove(result); |
| 103 } |
| 104 |
| 105 /** |
| 106 * Given a list of task [descriptors] that can be used to compute some |
| 107 * unspecified result, return the descriptor that will compute the result with |
| 108 * the least amount of work. |
| 109 */ |
| 110 TaskDescriptor _findBestTask(List<TaskDescriptor> descriptors) { |
| 111 // TODO(brianwilkerson) Improve this implementation. |
| 112 return descriptors[0]; |
| 113 } |
| 114 } |
OLD | NEW |