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

Side by Side Diff: pkg/analyzer/lib/src/task/manager.dart

Issue 812733004: Initial task support (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
(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 * Find a task that will compute the given [result] for the given [target].
71 */
72 TaskDescriptor findTask(AnalysisTarget target, ResultDescriptor result) {
73 List<TaskDescriptor> descriptors = taskMap[result];
74 if (descriptors == null) {
75 throw new AnalysisException(
76 'No tasks registered to compute $result for $target');
77 }
78 return _findBestTask(descriptors);
79 }
80
81 /**
82 * Remove the given [result] from the list of results that are to be computed
83 * for all sources within an analysis root.
84 */
85 void removeGeneralResult(ResultDescriptor result) {
86 generalResults.remove(result);
87 }
88
89 /**
90 * Remove the given [result] from the list of results that are to be computed
91 * for priority sources.
92 */
93 void removePriorityResult(ResultDescriptor result) {
94 priorityResults.remove(result);
95 }
96
97 /**
98 * Given a list of task [descriptors] that can be used to compute some
99 * unspecified result, return the descriptor that will compute the result with
100 * the least amount of work.
101 */
102 TaskDescriptor _findBestTask(List<TaskDescriptor> descriptors) {
103 // TODO(brianwilkerson) Improve this implementation.
104 return descriptors[0];
105 }
106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698