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

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

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years 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 | « packages/analyzer/lib/src/task/strong/rules.dart ('k') | packages/analyzer/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'dart:developer'; 8 import 'dart:developer';
9 9
10 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask; 10 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 AnalysisContextTarget(this.context); 53 AnalysisContextTarget(this.context);
54 54
55 @override 55 @override
56 Source get source => null; 56 Source get source => null;
57 } 57 }
58 58
59 /** 59 /**
60 * An object with which an analysis result can be associated. 60 * An object with which an analysis result can be associated.
61 * 61 *
62 * Clients are allowed to subtype this class when creating new kinds of targets. 62 * Clients may implement this class when creating new kinds of targets.
63 * Instances of this type are used in hashed data structures, so subtypes are 63 * Instances of this type are used in hashed data structures, so subtypes are
64 * required to correctly implement [==] and [hashCode]. 64 * required to correctly implement [==] and [hashCode].
65 */ 65 */
66 abstract class AnalysisTarget { 66 abstract class AnalysisTarget {
67 /** 67 /**
68 * Return the source associated with this target, or `null` if this target is 68 * Return the source associated with this target, or `null` if this target is
69 * not associated with a source. 69 * not associated with a source.
70 */ 70 */
71 Source get source; 71 Source get source;
72 } 72 }
73 73
74 /** 74 /**
75 * An object used to compute one or more analysis results associated with a 75 * An object used to compute one or more analysis results associated with a
76 * single target. 76 * single target.
77 * 77 *
78 * Clients are expected to extend this class when creating new tasks. 78 * Clients must extend this class when creating new tasks.
79 */ 79 */
80 abstract class AnalysisTask { 80 abstract class AnalysisTask {
81 /** 81 /**
82 * A table mapping the types of analysis tasks to the number of times each 82 * A table mapping the types of analysis tasks to the number of times each
83 * kind of task has been performed. 83 * kind of task has been performed.
84 */ 84 */
85 static final Map<Type, int> countMap = new HashMap<Type, int>(); 85 static final Map<Type, int> countMap = new HashMap<Type, int>();
86 86
87 /** 87 /**
88 * A table mapping the types of analysis tasks to user tags used to collect 88 * A table mapping the types of analysis tasks to user tags used to collect
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 * map (have a key/value pair for each result that this task is expected to 191 * map (have a key/value pair for each result that this task is expected to
192 * produce). 192 * produce).
193 */ 193 */
194 void internalPerform(); 194 void internalPerform();
195 195
196 /** 196 /**
197 * Perform this analysis task. When this method returns, either the [outputs] 197 * Perform this analysis task. When this method returns, either the [outputs]
198 * map should be fully populated (have a key/value pair for each result that 198 * map should be fully populated (have a key/value pair for each result that
199 * this task is expected to produce) or the [caughtException] should be set. 199 * this task is expected to produce) or the [caughtException] should be set.
200 * 200 *
201 * Clients should not override this method. 201 * Clients may not override this method.
202 */ 202 */
203 void perform() { 203 void perform() {
204 try { 204 try {
205 _safelyPerform(); 205 _safelyPerform();
206 } on AnalysisException catch (exception, stackTrace) { 206 } on AnalysisException catch (exception, stackTrace) {
207 caughtException = new CaughtException(exception, stackTrace); 207 caughtException = new CaughtException(exception, stackTrace);
208 AnalysisEngine.instance.logger 208 AnalysisEngine.instance.logger
209 .logInformation("Task failed: ${description}", caughtException); 209 .logInformation("Task failed: ${description}", caughtException);
210 } 210 }
211 } 211 }
212 212
213 @override 213 @override
214 String toString() => description; 214 String toString() => description;
215 215
216 /** 216 /**
217 * Perform this analysis task, ensuring that all exceptions are wrapped in an 217 * Perform this analysis task, ensuring that all exceptions are wrapped in an
218 * [AnalysisException]. 218 * [AnalysisException].
219 * 219 *
220 * Clients should not override this method. 220 * Clients may not override this method.
221 */ 221 */
222 void _safelyPerform() { 222 void _safelyPerform() {
223 try { 223 try {
224 // 224 //
225 // Report that this task is being performed. 225 // Report that this task is being performed.
226 // 226 //
227 String contextName = context.name; 227 String contextName = context.name;
228 if (contextName == null) { 228 if (contextName == null) {
229 contextName = 'unnamed'; 229 contextName = 'unnamed';
230 } 230 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 'Unexpected exception while performing $description', 266 'Unexpected exception while performing $description',
267 new CaughtException(exception, stackTrace)); 267 new CaughtException(exception, stackTrace));
268 } 268 }
269 } 269 }
270 } 270 }
271 271
272 /** 272 /**
273 * A description of a [List]-based analysis result that can be computed by an 273 * A description of a [List]-based analysis result that can be computed by an
274 * [AnalysisTask]. 274 * [AnalysisTask].
275 * 275 *
276 * Clients are not expected to subtype this class. 276 * Clients may not extend, implement or mix-in this class.
277 */ 277 */
278 abstract class ListResultDescriptor<E> implements ResultDescriptor<List<E>> { 278 abstract class ListResultDescriptor<E> implements ResultDescriptor<List<E>> {
279 /** 279 /**
280 * Initialize a newly created analysis result to have the given [name] and 280 * Initialize a newly created analysis result to have the given [name] and
281 * [defaultValue]. If a [cachingPolicy] is provided, it will control how long 281 * [defaultValue]. If a [cachingPolicy] is provided, it will control how long
282 * values associated with this result will remain in the cache. 282 * values associated with this result will remain in the cache.
283 */ 283 */
284 factory ListResultDescriptor(String name, List<E> defaultValue, 284 factory ListResultDescriptor(String name, List<E> defaultValue,
285 {ResultCachingPolicy<List<E>> cachingPolicy}) = ListResultDescriptorImpl< 285 {ResultCachingPolicy<List<E>> cachingPolicy}) = ListResultDescriptorImpl<
286 E>; 286 E>;
287 287
288 @override 288 @override
289 ListTaskInput<E> of(AnalysisTarget target, {bool flushOnAccess: false}); 289 ListTaskInput<E> of(AnalysisTarget target, {bool flushOnAccess: false});
290 } 290 }
291 291
292 /** 292 /**
293 * A description of an input to an [AnalysisTask] that can be used to compute 293 * A description of an input to an [AnalysisTask] that can be used to compute
294 * that input. 294 * that input.
295 * 295 *
296 * Clients are not expected to subtype this class. 296 * Clients may not extend, implement or mix-in this class.
297 */ 297 */
298 abstract class ListTaskInput<E> extends TaskInput<List<E>> { 298 abstract class ListTaskInput<E> extends TaskInput<List<E>> {
299 /** 299 /**
300 * Return a task input that can be used to compute a list whose elements are 300 * Return a task input that can be used to compute a list whose elements are
301 * the result of passing the elements of this input to the [mapper] function. 301 * the result of passing the elements of this input to the [mapper] function.
302 */ 302 */
303 ListTaskInput /*<V>*/ toList(UnaryFunction<E, dynamic /*<V>*/ > mapper); 303 ListTaskInput /*<V>*/ toList(UnaryFunction<E, dynamic /*<V>*/ > mapper);
304 304
305 /** 305 /**
306 * Return a task input that can be used to compute a list whose elements are 306 * Return a task input that can be used to compute a list whose elements are
(...skipping 14 matching lines...) Expand all
321 * elements of this input and whose values are the [valueResult]'s associated 321 * elements of this input and whose values are the [valueResult]'s associated
322 * with those elements. 322 * with those elements.
323 */ 323 */
324 MapTaskInput<AnalysisTarget, dynamic /*V*/ > toMapOf( 324 MapTaskInput<AnalysisTarget, dynamic /*V*/ > toMapOf(
325 ResultDescriptor /*<V>*/ valueResult); 325 ResultDescriptor /*<V>*/ valueResult);
326 } 326 }
327 327
328 /** 328 /**
329 * A description of an input with a [Map] based values. 329 * A description of an input with a [Map] based values.
330 * 330 *
331 * Clients are not expected to subtype this class. 331 * Clients may not extend, implement or mix-in this class.
332 */ 332 */
333 abstract class MapTaskInput<K, V> extends TaskInput<Map<K, V>> { 333 abstract class MapTaskInput<K, V> extends TaskInput<Map<K, V>> {
334 /** 334 /**
335 * [V] must be a [List]. 335 * [V] must be a [List].
336 * Return a task input that can be used to compute a list whose elements are 336 * Return a task input that can be used to compute a list whose elements are
337 * the result of passing keys [K] and the corresponding elements of [V] to 337 * the result of passing keys [K] and the corresponding elements of [V] to
338 * the [mapper] function. 338 * the [mapper] function.
339 */ 339 */
340 TaskInput<List /*<E>*/ > toFlattenList( 340 TaskInput<List /*<E>*/ > toFlattenList(
341 BinaryFunction<K, dynamic /*element of V*/, dynamic /*<E>*/ > mapper); 341 BinaryFunction<K, dynamic /*element of V*/, dynamic /*<E>*/ > mapper);
342 } 342 }
343 343
344 /** 344 /**
345 * A policy object that can compute sizes of results and provide the maximum 345 * A policy object that can compute sizes of results and provide the maximum
346 * active and idle sizes that can be kept in the cache. 346 * active and idle sizes that can be kept in the cache.
347 * 347 *
348 * All the [ResultDescriptor]s with the same [ResultCachingPolicy] instance 348 * All the [ResultDescriptor]s with the same [ResultCachingPolicy] instance
349 * share the same total size in a cache. 349 * share the same total size in a cache.
350 *
351 * Clients may implement this class when implementing plugins.
350 */ 352 */
351 abstract class ResultCachingPolicy<T> { 353 abstract class ResultCachingPolicy<T> {
352 /** 354 /**
353 * Return the maximum total size of results that can be kept in the cache 355 * Return the maximum total size of results that can be kept in the cache
354 * while analysis is in progress. 356 * while analysis is in progress.
355 */ 357 */
356 int get maxActiveSize; 358 int get maxActiveSize;
357 359
358 /** 360 /**
359 * Return the maximum total size of results that can be kept in the cache 361 * Return the maximum total size of results that can be kept in the cache
360 * while analysis is idle. 362 * while analysis is idle.
361 */ 363 */
362 int get maxIdleSize; 364 int get maxIdleSize;
363 365
364 /** 366 /**
365 * Return the size of the given [object]. 367 * Return the size of the given [object].
366 */ 368 */
367 int measure(T object); 369 int measure(T object);
368 } 370 }
369 371
370 /** 372 /**
371 * A description of an analysis result that can be computed by an [AnalysisTask] . 373 * A description of an analysis result that can be computed by an [AnalysisTask] .
372 * 374 *
373 * Clients are not expected to subtype this class. 375 * Clients may not extend, implement or mix-in this class.
374 */ 376 */
375 abstract class ResultDescriptor<V> { 377 abstract class ResultDescriptor<V> {
376 /** 378 /**
377 * Initialize a newly created analysis result to have the given [name] and 379 * Initialize a newly created analysis result to have the given [name] and
378 * [defaultValue]. 380 * [defaultValue].
379 * 381 *
380 * The given [cachingPolicy] is used to limit the total size of results 382 * The given [cachingPolicy] is used to limit the total size of results
381 * described by this descriptor. If no policy is specified, the results are 383 * described by this descriptor. If no policy is specified, the results are
382 * never evicted from the cache, and removed only when they are invalidated. 384 * never evicted from the cache, and removed only when they are invalidated.
383 */ 385 */
(...skipping 19 matching lines...) Expand all
403 * Return a task input that can be used to compute this result for the given 405 * Return a task input that can be used to compute this result for the given
404 * [target]. If [flushOnAccess] is `true` then the value of this result that 406 * [target]. If [flushOnAccess] is `true` then the value of this result that
405 * is associated with the [target] will be flushed when it is accessed. 407 * is associated with the [target] will be flushed when it is accessed.
406 */ 408 */
407 TaskInput<V> of(AnalysisTarget target, {bool flushOnAccess: false}); 409 TaskInput<V> of(AnalysisTarget target, {bool flushOnAccess: false});
408 } 410 }
409 411
410 /** 412 /**
411 * A specification of the given [result] for the given [target]. 413 * A specification of the given [result] for the given [target].
412 * 414 *
413 * Clients are not expected to subtype this class. 415 * Clients may not extend, implement or mix-in this class.
414 */ 416 */
415 class TargetedResult { 417 class TargetedResult {
416 /** 418 /**
417 * An empty list of results. 419 * An empty list of results.
418 */ 420 */
419 static final List<TargetedResult> EMPTY_LIST = const <TargetedResult>[]; 421 static final List<TargetedResult> EMPTY_LIST = const <TargetedResult>[];
420 422
421 /** 423 /**
422 * The target with which the result is associated. 424 * The target with which the result is associated.
423 */ 425 */
(...skipping 20 matching lines...) Expand all
444 other.target == target && 446 other.target == target &&
445 other.result == result; 447 other.result == result;
446 } 448 }
447 449
448 @override 450 @override
449 String toString() => '$result for $target'; 451 String toString() => '$result for $target';
450 } 452 }
451 453
452 /** 454 /**
453 * A description of an [AnalysisTask]. 455 * A description of an [AnalysisTask].
456 *
457 * Clients may not extend, implement or mix-in this class.
454 */ 458 */
455 abstract class TaskDescriptor { 459 abstract class TaskDescriptor {
456 /** 460 /**
457 * Initialize a newly created task descriptor to have the given [name] and to 461 * Initialize a newly created task descriptor to have the given [name] and to
458 * describe a task that takes the inputs built using the given [inputBuilder], 462 * describe a task that takes the inputs built using the given [inputBuilder],
459 * and produces the given [results]. The [buildTask] will be used to create 463 * and produces the given [results]. The [buildTask] will be used to create
460 * the instance of [AnalysisTask] thusly described. 464 * the instance of [AnalysisTask] thusly described.
461 */ 465 */
462 factory TaskDescriptor( 466 factory TaskDescriptor(
463 String name, 467 String name,
(...skipping 21 matching lines...) Expand all
485 * used to compute results based on the given [inputs]. 489 * used to compute results based on the given [inputs].
486 */ 490 */
487 AnalysisTask createTask(AnalysisContext context, AnalysisTarget target, 491 AnalysisTask createTask(AnalysisContext context, AnalysisTarget target,
488 Map<String, dynamic> inputs); 492 Map<String, dynamic> inputs);
489 } 493 }
490 494
491 /** 495 /**
492 * A description of an input to an [AnalysisTask] that can be used to compute 496 * A description of an input to an [AnalysisTask] that can be used to compute
493 * that input. 497 * that input.
494 * 498 *
495 * Clients are not expected to subtype this class. 499 * Clients may not extend, implement or mix-in this class.
496 */ 500 */
497 abstract class TaskInput<V> { 501 abstract class TaskInput<V> {
498 /** 502 /**
499 * Create and return a builder that can be used to build this task input. 503 * Create and return a builder that can be used to build this task input.
500 */ 504 */
501 TaskInputBuilder<V> createBuilder(); 505 TaskInputBuilder<V> createBuilder();
502 506
503 /** 507 /**
504 * Return a task input that can be used to compute a list whose elements are 508 * Return a task input that can be used to compute a list whose elements are
505 * the result of passing the result of this input to the [mapper] function. 509 * the result of passing the result of this input to the [mapper] function.
506 */ 510 */
507 ListTaskInput /*<E>*/ mappedToList(List /*<E>*/ mapper(V value)); 511 ListTaskInput /*<E>*/ mappedToList(List /*<E>*/ mapper(V value));
508 } 512 }
509 513
510 /** 514 /**
511 * An object used to build the value associated with a single [TaskInput]. 515 * An object used to build the value associated with a single [TaskInput].
512 * 516 *
513 * All builders work by requesting one or more results (each result being 517 * All builders work by requesting one or more results (each result being
514 * associated with a target). The interaction pattern is modeled after the class 518 * associated with a target). The interaction pattern is modeled after the class
515 * [Iterator], in which the method [moveNext] is invoked to move from one result 519 * [Iterator], in which the method [moveNext] is invoked to move from one result
516 * request to the next. The getters [currentResult] and [currentTarget] are used 520 * request to the next. The getters [currentResult] and [currentTarget] are used
517 * to get the result and target of the current request. The value of the result 521 * to get the result and target of the current request. The value of the result
518 * must be supplied using the [currentValue] setter before [moveNext] can be 522 * must be supplied using the [currentValue] setter before [moveNext] can be
519 * invoked to move to the next request. When [moveNext] returns `false`, 523 * invoked to move to the next request. When [moveNext] returns `false`,
520 * indicating that there are no more requests, the method [inputValue] can be 524 * indicating that there are no more requests, the method [inputValue] can be
521 * used to access the value of the input that was built. 525 * used to access the value of the input that was built.
522 * 526 *
523 * Clients are not expected to subtype this class. 527 * Clients may not extend, implement or mix-in this class.
524 */ 528 */
525 abstract class TaskInputBuilder<V> { 529 abstract class TaskInputBuilder<V> {
526 /** 530 /**
527 * Return the result that needs to be computed, or `null` if [moveNext] has 531 * Return the result that needs to be computed, or `null` if [moveNext] has
528 * not been invoked or if the last invocation of [moveNext] returned `false`. 532 * not been invoked or if the last invocation of [moveNext] returned `false`.
529 */ 533 */
530 ResultDescriptor get currentResult; 534 ResultDescriptor get currentResult;
531 535
532 /** 536 /**
533 * Return the target for which the result needs to be computed, or `null` if 537 * Return the target for which the result needs to be computed, or `null` if
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 * provided using [currentValue]. 585 * provided using [currentValue].
582 */ 586 */
583 bool moveNext(); 587 bool moveNext();
584 } 588 }
585 589
586 /** 590 /**
587 * [WorkManager]s are used to drive analysis. 591 * [WorkManager]s are used to drive analysis.
588 * 592 *
589 * They know specific of the targets and results they care about, 593 * They know specific of the targets and results they care about,
590 * so they can request analysis results in optimal order. 594 * so they can request analysis results in optimal order.
595 *
596 * Clients may implement this class when implementing plugins.
591 */ 597 */
592 abstract class WorkManager { 598 abstract class WorkManager {
593 /** 599 /**
594 * Notifies the manager about changes in the explicit source list. 600 * Notifies the manager about changes in the explicit source list.
595 */ 601 */
596 void applyChange(List<Source> addedSources, List<Source> changedSources, 602 void applyChange(List<Source> addedSources, List<Source> changedSources,
597 List<Source> removedSources); 603 List<Source> removedSources);
598 604
599 /** 605 /**
600 * Notifies the managers that the given set of priority [targets] was set. 606 * Notifies the managers that the given set of priority [targets] was set.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 /** 673 /**
668 * A work should be done, but without any special urgency. 674 * A work should be done, but without any special urgency.
669 */ 675 */
670 NORMAL, 676 NORMAL,
671 677
672 /** 678 /**
673 * Nothing to do. 679 * Nothing to do.
674 */ 680 */
675 NONE 681 NONE
676 } 682 }
OLDNEW
« no previous file with comments | « packages/analyzer/lib/src/task/strong/rules.dart ('k') | packages/analyzer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698