| 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/error.dart' show AnalysisError; | 10 import 'package:analyzer/src/generated/error.dart' show AnalysisError; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 * map should be fully populated (have a key/value pair for each result that | 191 * map should be fully populated (have a key/value pair for each result that |
| 192 * this task is expected to produce) or the [caughtException] should be set. | 192 * this task is expected to produce) or the [caughtException] should be set. |
| 193 * | 193 * |
| 194 * Clients should not override this method. | 194 * Clients should not override this method. |
| 195 */ | 195 */ |
| 196 void perform() { | 196 void perform() { |
| 197 try { | 197 try { |
| 198 _safelyPerform(); | 198 _safelyPerform(); |
| 199 } on AnalysisException catch (exception, stackTrace) { | 199 } on AnalysisException catch (exception, stackTrace) { |
| 200 caughtException = new CaughtException(exception, stackTrace); | 200 caughtException = new CaughtException(exception, stackTrace); |
| 201 AnalysisEngine.instance.logger.logInformation( | 201 AnalysisEngine.instance.logger |
| 202 "Task failed: ${description}", caughtException); | 202 .logInformation("Task failed: ${description}", caughtException); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 @override | 206 @override |
| 207 String toString() => description; | 207 String toString() => description; |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * Perform this analysis task, ensuring that all exceptions are wrapped in an | 210 * Perform this analysis task, ensuring that all exceptions are wrapped in an |
| 211 * [AnalysisException]. | 211 * [AnalysisException]. |
| 212 * | 212 * |
| 213 * Clients should not override this method. | 213 * Clients should not override this method. |
| 214 */ | 214 */ |
| 215 void _safelyPerform() { | 215 void _safelyPerform() { |
| 216 try { | 216 try { |
| 217 // | 217 // |
| 218 // Report that this task is being performed. | 218 // Report that this task is being performed. |
| 219 // | 219 // |
| 220 String contextName = context.name; | 220 String contextName = context.name; |
| 221 if (contextName == null) { | 221 if (contextName == null) { |
| 222 contextName = 'unnamed'; | 222 contextName = 'unnamed'; |
| 223 } | 223 } |
| 224 AnalysisEngine.instance.instrumentationService.logAnalysisTask( | 224 AnalysisEngine.instance.instrumentationService |
| 225 contextName, this); | 225 .logAnalysisTask(contextName, this); |
| 226 // | 226 // |
| 227 // Gather statistics on the performance of the task. | 227 // Gather statistics on the performance of the task. |
| 228 // | 228 // |
| 229 int count = countMap[runtimeType]; | 229 int count = countMap[runtimeType]; |
| 230 countMap[runtimeType] = count == null ? 1 : count + 1; | 230 countMap[runtimeType] = count == null ? 1 : count + 1; |
| 231 Stopwatch stopwatch = stopwatchMap[runtimeType]; | 231 Stopwatch stopwatch = stopwatchMap[runtimeType]; |
| 232 if (stopwatch == null) { | 232 if (stopwatch == null) { |
| 233 stopwatch = new Stopwatch(); | 233 stopwatch = new Stopwatch(); |
| 234 stopwatchMap[runtimeType] = stopwatch; | 234 stopwatchMap[runtimeType] = stopwatch; |
| 235 } | 235 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 261 * | 261 * |
| 262 * Clients are not expected to subtype this class. | 262 * Clients are not expected to subtype this class. |
| 263 */ | 263 */ |
| 264 abstract class ListResultDescriptor<E> implements ResultDescriptor<List<E>> { | 264 abstract class ListResultDescriptor<E> implements ResultDescriptor<List<E>> { |
| 265 /** | 265 /** |
| 266 * Initialize a newly created analysis result to have the given [name] and | 266 * Initialize a newly created analysis result to have the given [name] and |
| 267 * [defaultValue]. If a [cachingPolicy] is provided, it will control how long | 267 * [defaultValue]. If a [cachingPolicy] is provided, it will control how long |
| 268 * values associated with this result will remain in the cache. | 268 * values associated with this result will remain in the cache. |
| 269 */ | 269 */ |
| 270 factory ListResultDescriptor(String name, List<E> defaultValue, | 270 factory ListResultDescriptor(String name, List<E> defaultValue, |
| 271 {ResultCachingPolicy<List<E>> cachingPolicy}) = ListResultDescriptorImpl<E
>; | 271 {ResultCachingPolicy<List<E>> cachingPolicy}) = ListResultDescriptorImpl< |
| 272 E>; |
| 272 | 273 |
| 273 @override | 274 @override |
| 274 ListTaskInput<E> of(AnalysisTarget target); | 275 ListTaskInput<E> of(AnalysisTarget target); |
| 275 } | 276 } |
| 276 | 277 |
| 277 /** | 278 /** |
| 278 * A description of an input to an [AnalysisTask] that can be used to compute | 279 * A description of an input to an [AnalysisTask] that can be used to compute |
| 279 * that input. | 280 * that input. |
| 280 * | 281 * |
| 281 * Clients are not expected to subtype this class. | 282 * Clients are not expected to subtype this class. |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 /** | 437 /** |
| 437 * A description of an [AnalysisTask]. | 438 * A description of an [AnalysisTask]. |
| 438 */ | 439 */ |
| 439 abstract class TaskDescriptor { | 440 abstract class TaskDescriptor { |
| 440 /** | 441 /** |
| 441 * Initialize a newly created task descriptor to have the given [name] and to | 442 * Initialize a newly created task descriptor to have the given [name] and to |
| 442 * describe a task that takes the inputs built using the given [inputBuilder], | 443 * describe a task that takes the inputs built using the given [inputBuilder], |
| 443 * and produces the given [results]. The [buildTask] will be used to create | 444 * and produces the given [results]. The [buildTask] will be used to create |
| 444 * the instance of [AnalysisTask] thusly described. | 445 * the instance of [AnalysisTask] thusly described. |
| 445 */ | 446 */ |
| 446 factory TaskDescriptor(String name, BuildTask buildTask, | 447 factory TaskDescriptor( |
| 448 String name, |
| 449 BuildTask buildTask, |
| 447 CreateTaskInputs inputBuilder, | 450 CreateTaskInputs inputBuilder, |
| 448 List<ResultDescriptor> results) = TaskDescriptorImpl; | 451 List<ResultDescriptor> results) = TaskDescriptorImpl; |
| 449 | 452 |
| 450 /** | 453 /** |
| 451 * Return the builder used to build the inputs to the task. | 454 * Return the builder used to build the inputs to the task. |
| 452 */ | 455 */ |
| 453 CreateTaskInputs get createTaskInputs; | 456 CreateTaskInputs get createTaskInputs; |
| 454 | 457 |
| 455 /** | 458 /** |
| 456 * Return the name of the task being described. | 459 * Return the name of the task being described. |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 /** | 641 /** |
| 639 * A work should be done, but without any special urgency. | 642 * A work should be done, but without any special urgency. |
| 640 */ | 643 */ |
| 641 NORMAL, | 644 NORMAL, |
| 642 | 645 |
| 643 /** | 646 /** |
| 644 * Nothing to do. | 647 * Nothing to do. |
| 645 */ | 648 */ |
| 646 NONE | 649 NONE |
| 647 } | 650 } |
| OLD | NEW |