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

Side by Side Diff: analyzer/lib/src/task/model.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « analyzer/lib/src/task/manager.dart ('k') | analyzer/lib/src/util/asserts.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.model;
6
7 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
8 import 'package:analyzer/src/task/inputs.dart';
9 import 'package:analyzer/task/model.dart';
10
11 /**
12 * The default [ResultCachingPolicy], results are never flushed.
13 */
14 const ResultCachingPolicy DEFAULT_CACHING_POLICY =
15 const SimpleResultCachingPolicy(-1, -1);
16
17 /**
18 * A concrete implementation of a [ListResultDescriptor].
19 */
20 class ListResultDescriptorImpl<E> extends ResultDescriptorImpl<List<E>>
21 implements ListResultDescriptor<E> {
22 /**
23 * Initialize a newly created analysis result to have the given [name] and
24 * [defaultValue]. If a [cachingPolicy] is provided, it will control how long
25 * values associated with this result will remain in the cache.
26 */
27 ListResultDescriptorImpl(String name, List<E> defaultValue,
28 {ResultCachingPolicy<List<E>> cachingPolicy: DEFAULT_CACHING_POLICY})
29 : super(name, defaultValue, cachingPolicy: cachingPolicy);
30
31 @override
32 ListTaskInput<E> of(AnalysisTarget target) =>
33 new ListTaskInputImpl<E>(target, this);
34 }
35
36 /**
37 * A concrete implementation of a [ResultDescriptor].
38 */
39 class ResultDescriptorImpl<V> implements ResultDescriptor<V> {
40 static int _NEXT_HASH = 0;
41
42 @override
43 final hashCode = _NEXT_HASH++;
44
45 /**
46 * The name of the result, used for debugging.
47 */
48 final String name;
49
50 /**
51 * Return the default value for results described by this descriptor.
52 */
53 final V defaultValue;
54
55 /**
56 * The caching policy for results described by this descriptor.
57 */
58 final ResultCachingPolicy<V> cachingPolicy;
59
60 /**
61 * Initialize a newly created analysis result to have the given [name] and
62 * [defaultValue]. If a [cachingPolicy] is provided, it will control how long
63 * values associated with this result will remain in the cache.
64 */
65 ResultDescriptorImpl(this.name, this.defaultValue,
66 {this.cachingPolicy: DEFAULT_CACHING_POLICY});
67
68 @override
69 bool operator ==(Object other) {
70 return other is ResultDescriptorImpl && other.hashCode == hashCode;
71 }
72
73 @override
74 TaskInput<V> of(AnalysisTarget target) =>
75 new SimpleTaskInput<V>(target, this);
76
77 @override
78 String toString() => name;
79 }
80
81 /**
82 * A simple [ResultCachingPolicy] implementation that consider all the objects
83 * to be of the size `1`.
84 */
85 class SimpleResultCachingPolicy<T> implements ResultCachingPolicy<T> {
86 @override
87 final int maxActiveSize;
88
89 @override
90 final int maxIdleSize;
91
92 const SimpleResultCachingPolicy(this.maxActiveSize, this.maxIdleSize);
93
94 @override
95 int measure(T object) => 1;
96 }
97
98 /**
99 * A concrete implementation of a [TaskDescriptor].
100 */
101 class TaskDescriptorImpl implements TaskDescriptor {
102 /**
103 * The name of the described task, used for debugging.
104 */
105 final String name;
106
107 /**
108 * The function used to build the analysis task.
109 */
110 final BuildTask buildTask;
111
112 /**
113 * The function used to build the inputs to the task.
114 */
115 @override
116 final CreateTaskInputs createTaskInputs;
117
118 /**
119 * A list of the analysis results that will be computed by the described task.
120 */
121 @override
122 final List<ResultDescriptor> results;
123
124 /**
125 * Initialize a newly created task descriptor to have the given [name] and to
126 * describe a task that takes the inputs built using the given [createTaskInpu ts],
127 * and produces the given [results]. The [buildTask] will be used to create
128 * the instance of [AnalysisTask] thusly described.
129 */
130 TaskDescriptorImpl(
131 this.name, this.buildTask, this.createTaskInputs, this.results);
132
133 @override
134 AnalysisTask createTask(AnalysisContext context, AnalysisTarget target,
135 Map<String, dynamic> inputs) {
136 AnalysisTask task = buildTask(context, target);
137 task.inputs = inputs;
138 return task;
139 }
140
141 @override
142 String toString() => name;
143 }
OLDNEW
« no previous file with comments | « analyzer/lib/src/task/manager.dart ('k') | analyzer/lib/src/util/asserts.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698