| 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 | 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'; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 * [context] in order to produce results for the given [target]. | 88 * [context] in order to produce results for the given [target]. |
| 89 */ | 89 */ |
| 90 AnalysisTask(this.context, this.target); | 90 AnalysisTask(this.context, this.target); |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * Return a textual description of this task. | 93 * Return a textual description of this task. |
| 94 */ | 94 */ |
| 95 String get description; | 95 String get description; |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * Return the descriptor that describes this task. |
| 99 */ |
| 100 TaskDescriptor get descriptor; |
| 101 |
| 102 /** |
| 103 * Return the value of the input with the given [name]. Throw an exception if |
| 104 * the input value is not defined. |
| 105 */ |
| 106 Object getRequiredInput(String name) { |
| 107 if (inputs == null || !inputs.containsKey(name)) { |
| 108 throw new AnalysisException("Could not $description: missing $name"); |
| 109 } |
| 110 return inputs[name]; |
| 111 } |
| 112 |
| 113 /** |
| 114 * Return the source associated with the target. Throw an exception if |
| 115 * the target is not associated with a source. |
| 116 */ |
| 117 Source getRequiredSource() { |
| 118 Source source = target.source; |
| 119 if (source == null) { |
| 120 throw new AnalysisException("Could not $description: missing source"); |
| 121 } |
| 122 return source; |
| 123 } |
| 124 |
| 125 /** |
| 98 * Perform this analysis task, protected by an exception handler. | 126 * Perform this analysis task, protected by an exception handler. |
| 99 * | 127 * |
| 100 * This method should throw an [AnalysisException] if an exception occurs | 128 * This method should throw an [AnalysisException] if an exception occurs |
| 101 * while performing the task. If other kinds of exceptions are thrown they | 129 * while performing the task. If other kinds of exceptions are thrown they |
| 102 * will be wrapped in an [AnalysisException]. | 130 * will be wrapped in an [AnalysisException]. |
| 103 * | 131 * |
| 104 * If no exception is thrown, this method must fully populate the [outputs] | 132 * If no exception is thrown, this method must fully populate the [outputs] |
| 105 * map (have a key/value pair for each result that this task is expected to | 133 * map (have a key/value pair for each result that this task is expected to |
| 106 * produce). | 134 * produce). |
| 107 */ | 135 */ |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 /** | 188 /** |
| 161 * A [ResultDescriptor] that denotes an analysis result that is a union of | 189 * A [ResultDescriptor] that denotes an analysis result that is a union of |
| 162 * one or more other results. | 190 * one or more other results. |
| 163 * | 191 * |
| 164 * Clients are not expected to subtype this class. | 192 * Clients are not expected to subtype this class. |
| 165 */ | 193 */ |
| 166 abstract class ContributionPoint<V> extends ResultDescriptor<V> { | 194 abstract class ContributionPoint<V> extends ResultDescriptor<V> { |
| 167 /** | 195 /** |
| 168 * Initialize a newly created contribution point to have the given [name]. | 196 * Initialize a newly created contribution point to have the given [name]. |
| 169 */ | 197 */ |
| 170 factory ContributionPoint(String name) = ContributionPointImpl; | 198 factory ContributionPoint(String name, V defaultValue) = |
| 199 ContributionPointImpl; |
| 171 | 200 |
| 172 /** | 201 /** |
| 173 * Return a list containing the descriptors of the results that are unioned | 202 * Return a list containing the descriptors of the results that are unioned |
| 174 * together to comprise the value of this result. | 203 * together to comprise the value of this result. |
| 175 * | 204 * |
| 176 * Clients must not modify the returned list. | 205 * Clients must not modify the returned list. |
| 177 */ | 206 */ |
| 178 List<ResultDescriptor<V>> get contributors; | 207 List<ResultDescriptor<V>> get contributors; |
| 179 } | 208 } |
| 180 | 209 |
| 181 /** | 210 /** |
| 182 * A description of an analysis result that can be computed by an [AnalysisTask]
. | 211 * A description of an analysis result that can be computed by an [AnalysisTask]
. |
| 183 * | 212 * |
| 184 * Clients are not expected to subtype this class. | 213 * Clients are not expected to subtype this class. |
| 185 */ | 214 */ |
| 186 abstract class ResultDescriptor<V> { | 215 abstract class ResultDescriptor<V> { |
| 187 /** | 216 /** |
| 188 * Initialize a newly created analysis result to have the given [name]. If a | 217 * Initialize a newly created analysis result to have the given [name]. If a |
| 189 * contribution point is specified, then this result will contribute to it. | 218 * contribution point is specified, then this result will contribute to it. |
| 190 */ | 219 */ |
| 191 factory ResultDescriptor(String name, {ContributionPoint<V> contributesTo}) = | 220 factory ResultDescriptor(String name, V defaultValue, |
| 192 ResultDescriptorImpl; | 221 {ContributionPoint<V> contributesTo}) = ResultDescriptorImpl; |
| 222 |
| 223 /** |
| 224 * Return the default value for results described by this descriptor. |
| 225 */ |
| 226 V get defaultValue; |
| 193 | 227 |
| 194 /** | 228 /** |
| 195 * Return a task input that can be used to compute this result for the given | 229 * Return a task input that can be used to compute this result for the given |
| 196 * [target]. | 230 * [target]. |
| 197 */ | 231 */ |
| 198 TaskInput<V> inputFor(AnalysisTarget target); | 232 TaskInput<V> inputFor(AnalysisTarget target); |
| 199 } | 233 } |
| 200 | 234 |
| 201 /** | 235 /** |
| 202 * A description of an [AnalysisTask]. | 236 * A description of an [AnalysisTask]. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 * be computed, or `false` if the inputs have been computed. | 328 * be computed, or `false` if the inputs have been computed. |
| 295 * | 329 * |
| 296 * It is safe to invoke [moveNext] after it has returned `false`. In this case | 330 * It is safe to invoke [moveNext] after it has returned `false`. In this case |
| 297 * [moveNext] has no effect and will again return `false`. | 331 * [moveNext] has no effect and will again return `false`. |
| 298 * | 332 * |
| 299 * Throws a [StateError] if the value of the current result has not been | 333 * Throws a [StateError] if the value of the current result has not been |
| 300 * provided using [currentValue]. | 334 * provided using [currentValue]. |
| 301 */ | 335 */ |
| 302 bool moveNext(); | 336 bool moveNext(); |
| 303 } | 337 } |
| OLD | NEW |