| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 * | 146 * |
| 147 * The list will be empty if there were no errors, but will not be `null`. | 147 * The list will be empty if there were no errors, but will not be `null`. |
| 148 * | 148 * |
| 149 * The result is only available for [LibrarySpecificUnit]s. | 149 * The result is only available for [LibrarySpecificUnit]s. |
| 150 */ | 150 */ |
| 151 final ListResultDescriptor<AnalysisError> HINTS = | 151 final ListResultDescriptor<AnalysisError> HINTS = |
| 152 new ListResultDescriptor<AnalysisError>( | 152 new ListResultDescriptor<AnalysisError>( |
| 153 'HINT_ERRORS', AnalysisError.NO_ERRORS); | 153 'HINT_ERRORS', AnalysisError.NO_ERRORS); |
| 154 | 154 |
| 155 /** | 155 /** |
| 156 * The sources representing the combined import/export closure of a library. | |
| 157 * The [Source]s include only library sources, not their units. | |
| 158 * | |
| 159 * The result is only available for [Source]s representing a library. | |
| 160 */ | |
| 161 final ListResultDescriptor<Source> IMPORT_EXPORT_SOURCE_CLOSURE = | |
| 162 new ListResultDescriptor<Source>('IMPORT_EXPORT_SOURCE_CLOSURE', null); | |
| 163 | |
| 164 /** | |
| 165 * A list of the [VariableElement]s whose type should be inferred that another | 156 * A list of the [VariableElement]s whose type should be inferred that another |
| 166 * inferable static variable (the target) depends on. | 157 * inferable static variable (the target) depends on. |
| 167 * | 158 * |
| 168 * The result is only available for [VariableElement]s, and only when strong | 159 * The result is only available for [VariableElement]s, and only when strong |
| 169 * mode is enabled. | 160 * mode is enabled. |
| 170 */ | 161 */ |
| 171 final ListResultDescriptor< | 162 final ListResultDescriptor< |
| 172 VariableElement> INFERABLE_STATIC_VARIABLE_DEPENDENCIES = | 163 VariableElement> INFERABLE_STATIC_VARIABLE_DEPENDENCIES = |
| 173 new ListResultDescriptor<VariableElement>( | 164 new ListResultDescriptor<VariableElement>( |
| 174 'INFERABLE_STATIC_VARIABLE_DEPENDENCIES', null); | 165 'INFERABLE_STATIC_VARIABLE_DEPENDENCIES', null); |
| (...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 * Create a [BuildSourceExportClosureTask] based on the given [target] in | 1468 * Create a [BuildSourceExportClosureTask] based on the given [target] in |
| 1478 * the given [context]. | 1469 * the given [context]. |
| 1479 */ | 1470 */ |
| 1480 static BuildSourceExportClosureTask createTask( | 1471 static BuildSourceExportClosureTask createTask( |
| 1481 AnalysisContext context, AnalysisTarget target) { | 1472 AnalysisContext context, AnalysisTarget target) { |
| 1482 return new BuildSourceExportClosureTask(context, target); | 1473 return new BuildSourceExportClosureTask(context, target); |
| 1483 } | 1474 } |
| 1484 } | 1475 } |
| 1485 | 1476 |
| 1486 /** | 1477 /** |
| 1487 * A task that builds [IMPORT_EXPORT_SOURCE_CLOSURE] of a library, and also | |
| 1488 * sets [IS_CLIENT]. | |
| 1489 */ | |
| 1490 class BuildSourceImportExportClosureTask extends SourceBasedAnalysisTask { | |
| 1491 /** | |
| 1492 * The name of the import/export closure. | |
| 1493 */ | |
| 1494 static const String IMPORT_EXPORT_INPUT = 'IMPORT_EXPORT_INPUT'; | |
| 1495 | |
| 1496 /** | |
| 1497 * The task descriptor describing this kind of task. | |
| 1498 */ | |
| 1499 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | |
| 1500 'BuildSourceImportExportClosureTask', | |
| 1501 createTask, | |
| 1502 buildInputs, | |
| 1503 <ResultDescriptor>[IMPORT_EXPORT_SOURCE_CLOSURE, IS_CLIENT]); | |
| 1504 | |
| 1505 BuildSourceImportExportClosureTask( | |
| 1506 InternalAnalysisContext context, AnalysisTarget target) | |
| 1507 : super(context, target); | |
| 1508 | |
| 1509 @override | |
| 1510 TaskDescriptor get descriptor => DESCRIPTOR; | |
| 1511 | |
| 1512 @override | |
| 1513 void internalPerform() { | |
| 1514 List<Source> importExportClosure = getRequiredInput(IMPORT_EXPORT_INPUT); | |
| 1515 Source htmlSource = context.sourceFactory.forUri(DartSdk.DART_HTML); | |
| 1516 // | |
| 1517 // Record outputs. | |
| 1518 // | |
| 1519 outputs[IMPORT_EXPORT_SOURCE_CLOSURE] = importExportClosure; | |
| 1520 outputs[IS_CLIENT] = importExportClosure.contains(htmlSource); | |
| 1521 } | |
| 1522 | |
| 1523 /** | |
| 1524 * Return a map from the names of the inputs of this kind of task to the task | |
| 1525 * input descriptors describing those inputs for a task with the | |
| 1526 * given library [target]. | |
| 1527 */ | |
| 1528 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | |
| 1529 Source source = target; | |
| 1530 return <String, TaskInput>{ | |
| 1531 IMPORT_EXPORT_INPUT: | |
| 1532 new _ImportExportSourceClosureTaskInput(source, LIBRARY_ELEMENT2) | |
| 1533 }; | |
| 1534 } | |
| 1535 | |
| 1536 /** | |
| 1537 * Create a [BuildSourceImportExportClosureTask] based on the given [target] | |
| 1538 * in the given [context]. | |
| 1539 */ | |
| 1540 static BuildSourceImportExportClosureTask createTask( | |
| 1541 AnalysisContext context, AnalysisTarget target) { | |
| 1542 return new BuildSourceImportExportClosureTask(context, target); | |
| 1543 } | |
| 1544 } | |
| 1545 | |
| 1546 /** | |
| 1547 * A task that builds [TYPE_PROVIDER] for a context. | 1478 * A task that builds [TYPE_PROVIDER] for a context. |
| 1548 */ | 1479 */ |
| 1549 class BuildTypeProviderTask extends SourceBasedAnalysisTask { | 1480 class BuildTypeProviderTask extends SourceBasedAnalysisTask { |
| 1550 /** | 1481 /** |
| 1551 * The [PUBLIC_NAMESPACE] input of the `dart:core` library. | 1482 * The [PUBLIC_NAMESPACE] input of the `dart:core` library. |
| 1552 */ | 1483 */ |
| 1553 static const String CORE_INPUT = 'CORE_INPUT'; | 1484 static const String CORE_INPUT = 'CORE_INPUT'; |
| 1554 | 1485 |
| 1555 /** | 1486 /** |
| 1556 * The [PUBLIC_NAMESPACE] input of the `dart:async` library. | 1487 * The [PUBLIC_NAMESPACE] input of the `dart:async` library. |
| (...skipping 2002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3559 compilationUnit.functionTypeAliases.forEach(_addIfPublic); | 3490 compilationUnit.functionTypeAliases.forEach(_addIfPublic); |
| 3560 compilationUnit.types.forEach(_addIfPublic); | 3491 compilationUnit.types.forEach(_addIfPublic); |
| 3561 } | 3492 } |
| 3562 } | 3493 } |
| 3563 | 3494 |
| 3564 /** | 3495 /** |
| 3565 * A task that ensures that [LIBRARY_ELEMENT2] is ready for the target library | 3496 * A task that ensures that [LIBRARY_ELEMENT2] is ready for the target library |
| 3566 * source and its import/export closure. | 3497 * source and its import/export closure. |
| 3567 */ | 3498 */ |
| 3568 class ReadyLibraryElement2Task extends SourceBasedAnalysisTask { | 3499 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( | 3500 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3573 'ReadyLibraryElement2Task', | 3501 'ReadyLibraryElement2Task', |
| 3574 createTask, | 3502 createTask, |
| 3575 buildInputs, | 3503 buildInputs, |
| 3576 <ResultDescriptor>[READY_LIBRARY_ELEMENT2, IS_CLIENT]); | 3504 <ResultDescriptor>[READY_LIBRARY_ELEMENT2]); |
| 3577 | 3505 |
| 3578 ReadyLibraryElement2Task( | 3506 ReadyLibraryElement2Task( |
| 3579 InternalAnalysisContext context, AnalysisTarget target) | 3507 InternalAnalysisContext context, AnalysisTarget target) |
| 3580 : super(context, target); | 3508 : super(context, target); |
| 3581 | 3509 |
| 3582 @override | 3510 @override |
| 3583 TaskDescriptor get descriptor => DESCRIPTOR; | 3511 TaskDescriptor get descriptor => DESCRIPTOR; |
| 3584 | 3512 |
| 3585 @override | 3513 @override |
| 3586 bool get handlesDependencyCycles => true; | 3514 bool get handlesDependencyCycles => true; |
| 3587 | 3515 |
| 3588 @override | 3516 @override |
| 3589 void internalPerform() { | 3517 void internalPerform() { |
| 3590 bool isClient = _isClient(); | |
| 3591 outputs[READY_LIBRARY_ELEMENT2] = true; | 3518 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 } | 3519 } |
| 3609 | 3520 |
| 3610 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 3521 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 3611 Source source = target; | 3522 Source source = target; |
| 3612 return <String, TaskInput>{ | 3523 return <String, TaskInput>{ |
| 3613 'thisLibraryElementReady': LIBRARY_ELEMENT2.of(source), | 3524 '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': | 3525 'directlyImportedLibrariesReady': |
| 3617 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2), | 3526 IMPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2), |
| 3618 'directlyExportedLibrariesReady': | 3527 'directlyExportedLibrariesReady': |
| 3619 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2), | 3528 EXPORTED_LIBRARIES.of(source).toListOf(READY_LIBRARY_ELEMENT2), |
| 3620 }; | 3529 }; |
| 3621 } | 3530 } |
| 3622 | 3531 |
| 3623 static ReadyLibraryElement2Task createTask( | 3532 static ReadyLibraryElement2Task createTask( |
| 3624 AnalysisContext context, AnalysisTarget target) { | 3533 AnalysisContext context, AnalysisTarget target) { |
| 3625 return new ReadyLibraryElement2Task(context, target); | 3534 return new ReadyLibraryElement2Task(context, target); |
| 3626 } | 3535 } |
| 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 } | 3536 } |
| 3639 | 3537 |
| 3640 /** | 3538 /** |
| 3641 * A task that ensures that [LIBRARY_ELEMENT5] is ready for the target library | 3539 * A task that ensures that [LIBRARY_ELEMENT5] is ready for the target library |
| 3642 * source and its import/export closure. | 3540 * source and its import/export closure. |
| 3643 */ | 3541 */ |
| 3644 class ReadyLibraryElement5Task extends SourceBasedAnalysisTask { | 3542 class ReadyLibraryElement5Task extends SourceBasedAnalysisTask { |
| 3645 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 3543 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 3646 'ReadyLibraryElement5Task', | 3544 'ReadyLibraryElement5Task', |
| 3647 createTask, | 3545 createTask, |
| (...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4873 | 4771 |
| 4874 @override | 4772 @override |
| 4875 bool moveNext() { | 4773 bool moveNext() { |
| 4876 if (_newSources.isEmpty) { | 4774 if (_newSources.isEmpty) { |
| 4877 return false; | 4775 return false; |
| 4878 } | 4776 } |
| 4879 currentTarget = _newSources.removeLast(); | 4777 currentTarget = _newSources.removeLast(); |
| 4880 return true; | 4778 return true; |
| 4881 } | 4779 } |
| 4882 } | 4780 } |
| OLD | NEW |