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.src.task.dart; | 5 library analyzer.src.task.dart; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 * | 340 * |
341 * The list will be empty if there were no errors, but will not be `null`. | 341 * The list will be empty if there were no errors, but will not be `null`. |
342 * | 342 * |
343 * The result is only available for [Source]s representing a compilation unit. | 343 * The result is only available for [Source]s representing a compilation unit. |
344 */ | 344 */ |
345 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = | 345 final ListResultDescriptor<AnalysisError> PARSE_ERRORS = |
346 new ListResultDescriptor<AnalysisError>( | 346 new ListResultDescriptor<AnalysisError>( |
347 'PARSE_ERRORS', AnalysisError.NO_ERRORS); | 347 'PARSE_ERRORS', AnalysisError.NO_ERRORS); |
348 | 348 |
349 /** | 349 /** |
350 * The flag specifying that [RESOLVED_UNIT] is ready for a library. | 350 * The flag specifying that [LIBRARY_ELEMENT2] is ready for a library and its |
| 351 * import/export closure. |
351 * | 352 * |
352 * The result is only available for [Source]s representing a library. | 353 * The result is only available for [Source]s representing a library. |
353 */ | 354 */ |
| 355 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT2 = |
| 356 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT2', false); |
| 357 |
| 358 /** |
| 359 * The flag specifying that [LIBRARY_ELEMENT5] is ready for a library and its |
| 360 * import/export closure. |
| 361 * |
| 362 * The result is only available for [Source]s representing a library. |
| 363 */ |
| 364 final ResultDescriptor<bool> READY_LIBRARY_ELEMENT5 = |
| 365 new ResultDescriptor<bool>('READY_LIBRARY_ELEMENT5', false); |
| 366 |
| 367 /** |
| 368 * The flag specifying that [RESOLVED_UNIT] is ready for all of the units of a |
| 369 * library and its import/export closure. |
| 370 * |
| 371 * The result is only available for [Source]s representing a library. |
| 372 */ |
354 final ResultDescriptor<bool> READY_RESOLVED_UNIT = | 373 final ResultDescriptor<bool> READY_RESOLVED_UNIT = |
355 new ResultDescriptor<bool>('READY_RESOLVED_UNIT', false); | 374 new ResultDescriptor<bool>('READY_RESOLVED_UNIT', false); |
356 | 375 |
357 /** | 376 /** |
358 * The flag specifying that [RESOLVED_UNIT10] is ready for a library. | 377 * The flag specifying that [RESOLVED_UNIT10] is ready for all of the units of a |
| 378 * library and its import/export closure. |
359 * | 379 * |
360 * The result is only available for [Source]s representing a library. | 380 * The result is only available for [Source]s representing a library. |
361 */ | 381 */ |
362 final ResultDescriptor<bool> READY_RESOLVED_UNIT10 = | 382 final ResultDescriptor<bool> READY_RESOLVED_UNIT10 = |
363 new ResultDescriptor<bool>('READY_RESOLVED_UNIT10', false); | 383 new ResultDescriptor<bool>('READY_RESOLVED_UNIT10', false); |
364 | 384 |
365 /** | 385 /** |
366 * The flag specifying that [RESOLVED_UNIT9] is ready for a library. | 386 * The flag specifying that [RESOLVED_UNIT9] is ready for all of the units of a |
| 387 * library and its import/export closure. |
367 * | 388 * |
368 * The result is only available for [Source]s representing a library. | 389 * The result is only available for [Source]s representing a library. |
369 */ | 390 */ |
370 final ResultDescriptor<bool> READY_RESOLVED_UNIT9 = | 391 final ResultDescriptor<bool> READY_RESOLVED_UNIT9 = |
371 new ResultDescriptor<bool>('READY_RESOLVED_UNIT9', false); | 392 new ResultDescriptor<bool>('READY_RESOLVED_UNIT9', false); |
372 | 393 |
373 /** | 394 /** |
374 * The names (resolved and not) referenced by a unit. | 395 * The names (resolved and not) referenced by a unit. |
375 * | 396 * |
376 * The result is only available for [Source]s representing a compilation unit. | 397 * The result is only available for [Source]s representing a compilation unit. |
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 } | 1957 } |
1937 | 1958 |
1938 /** | 1959 /** |
1939 * Return a map from the names of the inputs of this kind of task to the task | 1960 * Return a map from the names of the inputs of this kind of task to the task |
1940 * input descriptors describing those inputs for a task with the | 1961 * input descriptors describing those inputs for a task with the |
1941 * given [target]. | 1962 * given [target]. |
1942 */ | 1963 */ |
1943 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 1964 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
1944 LibrarySpecificUnit unit = target; | 1965 LibrarySpecificUnit unit = target; |
1945 return <String, TaskInput>{ | 1966 return <String, TaskInput>{ |
1946 'resolveReachableLibraries': IMPORT_EXPORT_SOURCE_CLOSURE | 1967 LIBRARY_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(unit.library), |
1947 .of(unit.library) | 1968 'resolveReachableLibraries': READY_LIBRARY_ELEMENT2.of(unit.library), |
1948 .toListOf(LIBRARY_ELEMENT2), | |
1949 LIBRARY_ELEMENT_INPUT: LIBRARY_ELEMENT2.of(unit.library) | |
1950 }; | 1969 }; |
1951 } | 1970 } |
1952 | 1971 |
1953 /** | 1972 /** |
1954 * Create a [ComputeLibraryCycleTask] based on the | 1973 * Create a [ComputeLibraryCycleTask] based on the |
1955 * given [target] in the given [context]. | 1974 * given [target] in the given [context]. |
1956 */ | 1975 */ |
1957 static ComputeLibraryCycleTask createTask( | 1976 static ComputeLibraryCycleTask createTask( |
1958 AnalysisContext context, AnalysisTarget target) { | 1977 AnalysisContext context, AnalysisTarget target) { |
1959 return new ComputeLibraryCycleTask(context, target); | 1978 return new ComputeLibraryCycleTask(context, target); |
(...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3471 } | 3490 } |
3472 | 3491 |
3473 /** | 3492 /** |
3474 * Return a map from the names of the inputs of this kind of task to the task | 3493 * Return a map from the names of the inputs of this kind of task to the task |
3475 * input descriptors describing those inputs for a task with the | 3494 * input descriptors describing those inputs for a task with the |
3476 * given [target]. | 3495 * given [target]. |
3477 */ | 3496 */ |
3478 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 3497 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
3479 LibrarySpecificUnit unit = target; | 3498 LibrarySpecificUnit unit = target; |
3480 return <String, TaskInput>{ | 3499 return <String, TaskInput>{ |
3481 'fullyBuiltLibraryElements': IMPORT_EXPORT_SOURCE_CLOSURE | 3500 'fullyBuiltLibraryElements': READY_LIBRARY_ELEMENT5.of(unit.library), |
3482 .of(unit.library) | |
3483 .toListOf(LIBRARY_ELEMENT5), | |
3484 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library), | 3501 LIBRARY_INPUT: LIBRARY_ELEMENT5.of(unit.library), |
3485 UNIT_INPUT: RESOLVED_UNIT4.of(unit), | 3502 UNIT_INPUT: RESOLVED_UNIT4.of(unit), |
3486 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), | 3503 TYPE_PROVIDER_INPUT: TYPE_PROVIDER.of(AnalysisContextTarget.request), |
3487 // In strong mode, add additional dependencies to enforce inference | 3504 // In strong mode, add additional dependencies to enforce inference |
3488 // ordering. | 3505 // ordering. |
3489 | 3506 |
3490 // Require that full inference be complete for all dependencies of the | 3507 // Require that full inference be complete for all dependencies of the |
3491 // current library cycle. | 3508 // current library cycle. |
3492 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList( | 3509 'orderLibraryCycles': LIBRARY_CYCLE_DEPENDENCIES.of(unit).toList( |
3493 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8 | 3510 (CompilationUnitElementImpl unit) => RESOLVED_UNIT8 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3538 void _addPublicNames(CompilationUnitElement compilationUnit) { | 3555 void _addPublicNames(CompilationUnitElement compilationUnit) { |
3539 compilationUnit.accessors.forEach(_addIfPublic); | 3556 compilationUnit.accessors.forEach(_addIfPublic); |
3540 compilationUnit.enums.forEach(_addIfPublic); | 3557 compilationUnit.enums.forEach(_addIfPublic); |
3541 compilationUnit.functions.forEach(_addIfPublic); | 3558 compilationUnit.functions.forEach(_addIfPublic); |
3542 compilationUnit.functionTypeAliases.forEach(_addIfPublic); | 3559 compilationUnit.functionTypeAliases.forEach(_addIfPublic); |
3543 compilationUnit.types.forEach(_addIfPublic); | 3560 compilationUnit.types.forEach(_addIfPublic); |
3544 } | 3561 } |
3545 } | 3562 } |
3546 | 3563 |
3547 /** | 3564 /** |
| 3565 * A task that ensures that [LIBRARY_ELEMENT2] is ready for the target library |
| 3566 * source and its import/export closure. |
| 3567 */ |
| 3568 class ReadyLibraryElement2Task extends SourceBasedAnalysisTask { |
| 3569 static const String IS_CLIENT_LIST_INPUT1 = 'IS_CLIENT_LIST_INPUT1'; |
| 3570 static const String IS_CLIENT_LIST_INPUT2 = 'IS_CLIENT_LIST_INPUT2'; |
| 3571 |
| 3572 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3573 'ReadyLibraryElement2Task', |
| 3574 createTask, |
| 3575 buildInputs, |
| 3576 <ResultDescriptor>[READY_LIBRARY_ELEMENT2, IS_CLIENT]); |
| 3577 |
| 3578 ReadyLibraryElement2Task( |
| 3579 InternalAnalysisContext context, AnalysisTarget target) |
| 3580 : super(context, target); |
| 3581 |
| 3582 @override |
| 3583 TaskDescriptor get descriptor => DESCRIPTOR; |
| 3584 |
| 3585 @override |
| 3586 bool get handlesDependencyCycles => true; |
| 3587 |
| 3588 @override |
| 3589 void internalPerform() { |
| 3590 bool isClient = _isClient(); |
| 3591 outputs[READY_LIBRARY_ELEMENT2] = true; |
| 3592 outputs[IS_CLIENT] = isClient; |
| 3593 } |
| 3594 |
| 3595 bool _isClient() { |
| 3596 Source htmlSource = context.sourceFactory.forUri(DartSdk.DART_HTML); |
| 3597 Source source = getRequiredSource(); |
| 3598 if (source == htmlSource) { |
| 3599 return true; |
| 3600 } |
| 3601 if (_hasTrueElement(getRequiredInput(IS_CLIENT_LIST_INPUT1))) { |
| 3602 return true; |
| 3603 } |
| 3604 if (_hasTrueElement(getRequiredInput(IS_CLIENT_LIST_INPUT2))) { |
| 3605 return true; |
| 3606 } |
| 3607 return false; |
| 3608 } |
| 3609 |
| 3610 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 3611 Source source = target; |
| 3612 return <String, TaskInput>{ |
| 3613 'thisLibraryElementReady': LIBRARY_ELEMENT2.of(source), |
| 3614 IS_CLIENT_LIST_INPUT1: IMPORTED_LIBRARIES.of(source).toListOf(IS_CLIENT), |
| 3615 IS_CLIENT_LIST_INPUT2: EXPORTED_LIBRARIES.of(source).toListOf(IS_CLIENT), |
| 3616 'directlyImportedLibrariesReady': |
| 3617 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2), |
| 3618 'directlyExportedLibrariesReady': |
| 3619 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2), |
| 3620 }; |
| 3621 } |
| 3622 |
| 3623 static ReadyLibraryElement2Task createTask( |
| 3624 AnalysisContext context, AnalysisTarget target) { |
| 3625 return new ReadyLibraryElement2Task(context, target); |
| 3626 } |
| 3627 |
| 3628 static bool _hasTrueElement(List<bool> elements) { |
| 3629 if (elements != null) { |
| 3630 for (bool isClient in elements) { |
| 3631 if (isClient == true) { |
| 3632 return true; |
| 3633 } |
| 3634 } |
| 3635 } |
| 3636 return false; |
| 3637 } |
| 3638 } |
| 3639 |
| 3640 /** |
| 3641 * A task that ensures that [LIBRARY_ELEMENT5] is ready for the target library |
| 3642 * source and its import/export closure. |
| 3643 */ |
| 3644 class ReadyLibraryElement5Task extends SourceBasedAnalysisTask { |
| 3645 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3646 'ReadyLibraryElement5Task', |
| 3647 createTask, |
| 3648 buildInputs, |
| 3649 <ResultDescriptor>[READY_LIBRARY_ELEMENT5]); |
| 3650 |
| 3651 ReadyLibraryElement5Task( |
| 3652 InternalAnalysisContext context, AnalysisTarget target) |
| 3653 : super(context, target); |
| 3654 |
| 3655 @override |
| 3656 TaskDescriptor get descriptor => DESCRIPTOR; |
| 3657 |
| 3658 @override |
| 3659 bool get handlesDependencyCycles => true; |
| 3660 |
| 3661 @override |
| 3662 void internalPerform() { |
| 3663 outputs[READY_LIBRARY_ELEMENT5] = true; |
| 3664 } |
| 3665 |
| 3666 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 3667 Source source = target; |
| 3668 return <String, TaskInput>{ |
| 3669 'thisLibraryElementReady': LIBRARY_ELEMENT5.of(source), |
| 3670 'directlyImportedLibrariesReady': |
| 3671 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT5), |
| 3672 'directlyExportedLibrariesReady': |
| 3673 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT5), |
| 3674 }; |
| 3675 } |
| 3676 |
| 3677 static ReadyLibraryElement5Task createTask( |
| 3678 AnalysisContext context, AnalysisTarget target) { |
| 3679 return new ReadyLibraryElement5Task(context, target); |
| 3680 } |
| 3681 } |
| 3682 |
| 3683 /** |
3548 * A task that ensures that [RESOLVED_UNIT10] is ready for every unit of the | 3684 * A task that ensures that [RESOLVED_UNIT10] is ready for every unit of the |
3549 * target library source and its import/export closure. | 3685 * target library source and its import/export closure. |
3550 */ | 3686 */ |
3551 class ReadyResolvedUnit10Task extends SourceBasedAnalysisTask { | 3687 class ReadyResolvedUnit10Task extends SourceBasedAnalysisTask { |
3552 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 3688 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
3553 'ReadyResolvedUnit10Task', | 3689 'ReadyResolvedUnit10Task', |
3554 createTask, | 3690 createTask, |
3555 buildInputs, | 3691 buildInputs, |
3556 <ResultDescriptor>[READY_RESOLVED_UNIT10]); | 3692 <ResultDescriptor>[READY_RESOLVED_UNIT10]); |
3557 | 3693 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3956 * Create a [ResolveLibraryReferencesTask] based on the given [target] in | 4092 * Create a [ResolveLibraryReferencesTask] based on the given [target] in |
3957 * the given [context]. | 4093 * the given [context]. |
3958 */ | 4094 */ |
3959 static ResolveLibraryReferencesTask createTask( | 4095 static ResolveLibraryReferencesTask createTask( |
3960 AnalysisContext context, AnalysisTarget target) { | 4096 AnalysisContext context, AnalysisTarget target) { |
3961 return new ResolveLibraryReferencesTask(context, target); | 4097 return new ResolveLibraryReferencesTask(context, target); |
3962 } | 4098 } |
3963 } | 4099 } |
3964 | 4100 |
3965 /** | 4101 /** |
3966 * An artifitial task that does nothing except to force type names resolution | 4102 * An artificial task that does nothing except to force type names resolution |
3967 * for the defining and part units of a library. | 4103 * for the defining and part units of a library. |
3968 */ | 4104 */ |
3969 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask { | 4105 class ResolveLibraryTypeNamesTask extends SourceBasedAnalysisTask { |
3970 /** | 4106 /** |
3971 * The name of the [LIBRARY_ELEMENT4] input. | 4107 * The name of the [LIBRARY_ELEMENT4] input. |
3972 */ | 4108 */ |
3973 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; | 4109 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
3974 | 4110 |
3975 /** | 4111 /** |
3976 * The name of the [TYPE_PROVIDER] input. | 4112 * The name of the [TYPE_PROVIDER] input. |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4737 | 4873 |
4738 @override | 4874 @override |
4739 bool moveNext() { | 4875 bool moveNext() { |
4740 if (_newSources.isEmpty) { | 4876 if (_newSources.isEmpty) { |
4741 return false; | 4877 return false; |
4742 } | 4878 } |
4743 currentTarget = _newSources.removeLast(); | 4879 currentTarget = _newSources.removeLast(); |
4744 return true; | 4880 return true; |
4745 } | 4881 } |
4746 } | 4882 } |
OLD | NEW |