Chromium Code Reviews| 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/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 * The list will be empty if there were no errors, but will not be `null`. | 42 * The list will be empty if there were no errors, but will not be `null`. |
| 43 * | 43 * |
| 44 * The result is only available for targets representing a Dart library. | 44 * The result is only available for targets representing a Dart library. |
| 45 */ | 45 */ |
| 46 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS = | 46 final ResultDescriptor<List<AnalysisError>> BUILD_LIBRARY_ERRORS = |
| 47 new ResultDescriptor<List<AnalysisError>>( | 47 new ResultDescriptor<List<AnalysisError>>( |
| 48 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS, | 48 'BUILD_LIBRARY_ERRORS', AnalysisError.NO_ERRORS, |
| 49 contributesTo: DART_ERRORS); | 49 contributesTo: DART_ERRORS); |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * The export [Namespace] of a library. | |
| 53 * | |
| 54 * The result is only available for targets representing a Dart library. | |
| 55 */ | |
| 56 final ResultDescriptor<Namespace> EXPORT_NAMESPACE = | |
| 57 new ResultDescriptor<Namespace>('EXPORT_NAMESPACE', null); | |
| 58 | |
| 59 /** | |
| 60 * The sources representing the export closure of a library. | 52 * The sources representing the export closure of a library. |
| 61 * | 53 * |
| 62 * The result is only available for targets representing a Dart library. | 54 * The result is only available for targets representing a Dart library. |
| 63 */ | 55 */ |
| 64 final ResultDescriptor<List<Source>> EXPORT_SOURCE_CLOSURE = | 56 final ResultDescriptor<List<Source>> EXPORT_SOURCE_CLOSURE = |
| 65 new ResultDescriptor<List<Source>>('EXPORT_SOURCE_CLOSURE', null); | 57 new ResultDescriptor<List<Source>>('EXPORT_SOURCE_CLOSURE', null); |
| 66 | 58 |
| 67 /** | 59 /** |
| 68 * The partial [LibraryElement] associated with a library. | 60 * The partial [LibraryElement] associated with a library. |
| 69 * | 61 * |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 82 * [LibraryElement] are set. | 74 * [LibraryElement] are set. |
| 83 * | 75 * |
| 84 * The result is only available for targets representing a Dart library. | 76 * The result is only available for targets representing a Dart library. |
| 85 */ | 77 */ |
| 86 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT2 = | 78 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT2 = |
| 87 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT2', null); | 79 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT2', null); |
| 88 | 80 |
| 89 /** | 81 /** |
| 90 * The partial [LibraryElement] associated with a library. | 82 * The partial [LibraryElement] associated with a library. |
| 91 * | 83 * |
| 92 * In addition to [LIBRARY_ELEMENT2] `entryPoint` is set, if the library does | 84 * In addition to [LIBRARY_ELEMENT2] `publicNamespace` is set. |
|
Brian Wilkerson
2015/03/18 19:20:56
"`publicNamespace`" --> "[LibraryElement.publicNam
| |
| 93 * not declare one already and one of the exported libraries exports one. | |
| 94 * | 85 * |
| 95 * The result is only available for targets representing a Dart library. | 86 * The result is only available for targets representing a Dart library. |
| 96 */ | 87 */ |
| 97 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT3 = | 88 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT3 = |
| 98 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT3', null); | 89 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT3', null); |
| 99 | 90 |
| 100 /** | 91 /** |
| 92 * The partial [LibraryElement] associated with a library. | |
| 93 * | |
| 94 * In addition to [LIBRARY_ELEMENT3] `entryPoint` is set, if the library does | |
| 95 * not declare one already and one of the exported libraries exports one. | |
| 96 * | |
| 97 * Also `exportNamespace` is set. | |
| 98 * | |
| 99 * The result is only available for targets representing a Dart library. | |
| 100 */ | |
| 101 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT4 = | |
| 102 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT4', null); | |
| 103 | |
| 104 /** | |
| 101 * The partially resolved [CompilationUnit] associated with a unit. | 105 * The partially resolved [CompilationUnit] associated with a unit. |
| 102 * | 106 * |
| 103 * All declarations bound to the element defined by the declaration. | 107 * All declarations bound to the element defined by the declaration. |
| 104 * | 108 * |
| 105 * The result is only available for targets representing a unit. | 109 * The result is only available for targets representing a unit. |
| 106 */ | 110 */ |
| 107 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT1 = | 111 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT1 = |
| 108 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT1', null); | 112 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT1', null); |
| 109 | 113 |
| 110 /** | 114 /** |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 /** | 224 /** |
| 221 * A task that builds imports and export directive elements for a library. | 225 * A task that builds imports and export directive elements for a library. |
| 222 */ | 226 */ |
| 223 class BuildDirectiveElementsTask extends SourceBasedAnalysisTask { | 227 class BuildDirectiveElementsTask extends SourceBasedAnalysisTask { |
| 224 /** | 228 /** |
| 225 * The name of the input for [RESOLVED_UNIT2] of a library unit. | 229 * The name of the input for [RESOLVED_UNIT2] of a library unit. |
| 226 */ | 230 */ |
| 227 static const String RESOLVED_UNIT2_INPUT_NAME = 'RESOLVED_UNIT2_INPUT_NAME'; | 231 static const String RESOLVED_UNIT2_INPUT_NAME = 'RESOLVED_UNIT2_INPUT_NAME'; |
| 228 | 232 |
| 229 /** | 233 /** |
| 230 * The input with a list of [LIBRARY_ELEMENT1]s of imported libraries. | 234 * The input with a list of [LIBRARY_ELEMENT3]s of imported libraries. |
| 231 */ | 235 */ |
| 232 static const String IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME = | 236 static const String IMPORTS_LIBRARY_ELEMENT_INPUT_NAME = |
| 233 'IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME'; | 237 'IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME'; |
| 234 | 238 |
| 235 /** | 239 /** |
| 236 * The input with a list of [LIBRARY_ELEMENT1]s of exported libraries. | 240 * The input with a list of [LIBRARY_ELEMENT3]s of exported libraries. |
| 237 */ | 241 */ |
| 238 static const String EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME = | 242 static const String EXPORTS_LIBRARY_ELEMENT_INPUT_NAME = |
| 239 'EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME'; | 243 'EXPORTS_LIBRARY_ELEMENT_INPUT_NAME'; |
| 240 | 244 |
| 241 /** | 245 /** |
| 242 * The input with a list of [SOURCE_KIND]s of imported libraries. | 246 * The input with a list of [SOURCE_KIND]s of imported libraries. |
| 243 */ | 247 */ |
| 244 static const String IMPORTS_SOURCE_KIND_INPUT_NAME = | 248 static const String IMPORTS_SOURCE_KIND_INPUT_NAME = |
| 245 'IMPORTS_SOURCE_KIND_INPUT_NAME'; | 249 'IMPORTS_SOURCE_KIND_INPUT_NAME'; |
| 246 | 250 |
| 247 /** | 251 /** |
| 248 * The input with a list of [SOURCE_KIND]s of exported libraries. | 252 * The input with a list of [SOURCE_KIND]s of exported libraries. |
| 249 */ | 253 */ |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 268 TaskDescriptor get descriptor => DESCRIPTOR; | 272 TaskDescriptor get descriptor => DESCRIPTOR; |
| 269 | 273 |
| 270 @override | 274 @override |
| 271 void internalPerform() { | 275 void internalPerform() { |
| 272 List<AnalysisError> errors = <AnalysisError>[]; | 276 List<AnalysisError> errors = <AnalysisError>[]; |
| 273 // | 277 // |
| 274 // Prepare inputs. | 278 // Prepare inputs. |
| 275 // | 279 // |
| 276 CompilationUnit libraryUnit = getRequiredInput(RESOLVED_UNIT2_INPUT_NAME); | 280 CompilationUnit libraryUnit = getRequiredInput(RESOLVED_UNIT2_INPUT_NAME); |
| 277 Map<Source, LibraryElement> importLibraryMap = | 281 Map<Source, LibraryElement> importLibraryMap = |
| 278 getRequiredInput(IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME); | 282 getRequiredInput(IMPORTS_LIBRARY_ELEMENT_INPUT_NAME); |
| 279 Map<Source, LibraryElement> exportLibraryMap = | 283 Map<Source, LibraryElement> exportLibraryMap = |
| 280 getRequiredInput(EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME); | 284 getRequiredInput(EXPORTS_LIBRARY_ELEMENT_INPUT_NAME); |
| 281 Map<Source, SourceKind> importSourceKindMap = | 285 Map<Source, SourceKind> importSourceKindMap = |
| 282 getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME); | 286 getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME); |
| 283 Map<Source, SourceKind> exportSourceKindMap = | 287 Map<Source, SourceKind> exportSourceKindMap = |
| 284 getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME); | 288 getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME); |
| 285 // | 289 // |
| 286 // Process inputs. | 290 // Process inputs. |
| 287 // | 291 // |
| 288 LibraryElementImpl libraryElement = libraryUnit.element.library; | 292 LibraryElementImpl libraryElement = libraryUnit.element.library; |
| 289 Source librarySource = libraryElement.source; | 293 Source librarySource = libraryElement.source; |
| 290 // | 294 // |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 } | 401 } |
| 398 | 402 |
| 399 /** | 403 /** |
| 400 * Return a map from the names of the inputs of this kind of task to the task | 404 * Return a map from the names of the inputs of this kind of task to the task |
| 401 * input descriptors describing those inputs for a task with the | 405 * input descriptors describing those inputs for a task with the |
| 402 * given library [source]. | 406 * given library [source]. |
| 403 */ | 407 */ |
| 404 static Map<String, TaskInput> buildInputs(Source source) { | 408 static Map<String, TaskInput> buildInputs(Source source) { |
| 405 return <String, TaskInput>{ | 409 return <String, TaskInput>{ |
| 406 RESOLVED_UNIT2_INPUT_NAME: RESOLVED_UNIT2.inputFor(source), | 410 RESOLVED_UNIT2_INPUT_NAME: RESOLVED_UNIT2.inputFor(source), |
| 407 IMPORTS_LIBRARY_ELEMENT1_INPUT_NAME: | 411 IMPORTS_LIBRARY_ELEMENT_INPUT_NAME: |
| 408 new ListToMapTaskInput<Source, LibraryElement>( | 412 new ListToMapTaskInput<Source, LibraryElement>( |
| 409 IMPORTED_LIBRARIES.inputFor(source), | 413 IMPORTED_LIBRARIES.inputFor(source), |
| 410 (Source source) => LIBRARY_ELEMENT1.inputFor(source)), | 414 (Source source) => LIBRARY_ELEMENT1.inputFor(source)), |
| 411 EXPORTS_LIBRARY_ELEMENT1_INPUT_NAME: | 415 EXPORTS_LIBRARY_ELEMENT_INPUT_NAME: |
| 412 new ListToMapTaskInput<Source, LibraryElement>( | 416 new ListToMapTaskInput<Source, LibraryElement>( |
| 413 EXPORTED_LIBRARIES.inputFor(source), | 417 EXPORTED_LIBRARIES.inputFor(source), |
| 414 (Source source) => LIBRARY_ELEMENT1.inputFor(source)), | 418 (Source source) => LIBRARY_ELEMENT1.inputFor(source)), |
| 415 IMPORTS_SOURCE_KIND_INPUT_NAME: | 419 IMPORTS_SOURCE_KIND_INPUT_NAME: |
| 416 new ListToMapTaskInput<Source, SourceKind>( | 420 new ListToMapTaskInput<Source, SourceKind>( |
| 417 IMPORTED_LIBRARIES.inputFor(source), | 421 IMPORTED_LIBRARIES.inputFor(source), |
| 418 (Source source) => SOURCE_KIND.inputFor(source)), | 422 (Source source) => SOURCE_KIND.inputFor(source)), |
| 419 EXPORTS_SOURCE_KIND_INPUT_NAME: | 423 EXPORTS_SOURCE_KIND_INPUT_NAME: |
| 420 new ListToMapTaskInput<Source, SourceKind>( | 424 new ListToMapTaskInput<Source, SourceKind>( |
| 421 EXPORTED_LIBRARIES.inputFor(source), | 425 EXPORTED_LIBRARIES.inputFor(source), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 * Create a [BuildEnumMemberElementsTask] based on the given [target] in | 528 * Create a [BuildEnumMemberElementsTask] based on the given [target] in |
| 525 * the given [context]. | 529 * the given [context]. |
| 526 */ | 530 */ |
| 527 static BuildEnumMemberElementsTask createTask( | 531 static BuildEnumMemberElementsTask createTask( |
| 528 AnalysisContext context, AnalysisTarget target) { | 532 AnalysisContext context, AnalysisTarget target) { |
| 529 return new BuildEnumMemberElementsTask(context, target); | 533 return new BuildEnumMemberElementsTask(context, target); |
| 530 } | 534 } |
| 531 } | 535 } |
| 532 | 536 |
| 533 /** | 537 /** |
| 534 * A task that builds [EXPORT_NAMESPACE] and [LIBRARY_ELEMENT3] for a library. | 538 * A task that builds [EXPORT_NAMESPACE] and [LIBRARY_ELEMENT4] for a library. |
| 535 */ | 539 */ |
| 536 class BuildExportNamespaceTask extends SourceBasedAnalysisTask { | 540 class BuildExportNamespaceTask extends SourceBasedAnalysisTask { |
| 537 /** | 541 /** |
| 538 * The name of the input for [LIBRARY_ELEMENT2] of a library. | 542 * The name of the input for [LIBRARY_ELEMENT3] of a library. |
| 539 */ | 543 */ |
| 540 static const String LIBRARY2_ELEMENT_INPUT = 'LIBRARY2_ELEMENT_INPUT'; | 544 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
| 541 | |
| 542 /** | |
| 543 * The a [Source] to [PUBLIC_NAMESPACE] map input. | |
| 544 */ | |
| 545 static const String PUBLIC_NAMESPACES_INPUT = 'PUBLIC_NAMESPACES_INPUT'; | |
| 546 | 545 |
| 547 /** | 546 /** |
| 548 * The task descriptor describing this kind of task. | 547 * The task descriptor describing this kind of task. |
| 549 */ | 548 */ |
| 550 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 549 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 551 'BuildExportNamespaceTask', createTask, buildInputs, <ResultDescriptor>[ | 550 'BuildExportNamespaceTask', createTask, buildInputs, |
| 552 EXPORT_NAMESPACE, | 551 <ResultDescriptor>[LIBRARY_ELEMENT4]); |
| 553 LIBRARY_ELEMENT3 | |
| 554 ]); | |
| 555 | 552 |
| 556 BuildExportNamespaceTask( | 553 BuildExportNamespaceTask( |
| 557 InternalAnalysisContext context, AnalysisTarget target) | 554 InternalAnalysisContext context, AnalysisTarget target) |
| 558 : super(context, target); | 555 : super(context, target); |
| 559 | 556 |
| 560 @override | 557 @override |
| 561 TaskDescriptor get descriptor => DESCRIPTOR; | 558 TaskDescriptor get descriptor => DESCRIPTOR; |
| 562 | 559 |
| 563 @override | 560 @override |
| 564 void internalPerform() { | 561 void internalPerform() { |
| 565 LibraryElementImpl library = getRequiredInput(LIBRARY2_ELEMENT_INPUT); | 562 LibraryElementImpl library = getRequiredInput(LIBRARY_INPUT); |
| 566 Map<Source, Namespace> publicNamespaces = | |
| 567 getRequiredInput(PUBLIC_NAMESPACES_INPUT); | |
| 568 // | 563 // |
| 569 // Compute export namespace. | 564 // Compute export namespace. |
| 570 // | 565 // |
| 571 ExportNamespaceBuilder builder = | 566 ExportNamespaceBuilder builder = new ExportNamespaceBuilder(); |
| 572 new ExportNamespaceBuilder(publicNamespaces); | |
| 573 Namespace namespace = builder.build(library); | 567 Namespace namespace = builder.build(library); |
| 568 library.exportNamespace = namespace; | |
| 574 // | 569 // |
| 575 // Update entry point. | 570 // Update entry point. |
| 576 // | 571 // |
| 577 if (library.entryPoint == null) { | 572 if (library.entryPoint == null) { |
| 578 Iterable<Element> exportedElements = namespace.definedNames.values; | 573 Iterable<Element> exportedElements = namespace.definedNames.values; |
| 579 library.entryPoint = exportedElements.firstWhere( | 574 library.entryPoint = exportedElements.firstWhere( |
| 580 (element) => element is FunctionElement && element.isEntryPoint, | 575 (element) => element is FunctionElement && element.isEntryPoint, |
| 581 orElse: () => null); | 576 orElse: () => null); |
| 582 } | 577 } |
| 583 // | 578 // |
| 584 // Record outputs. | 579 // Record outputs. |
| 585 // | 580 // |
| 586 outputs[EXPORT_NAMESPACE] = namespace; | 581 outputs[LIBRARY_ELEMENT4] = library; |
| 587 outputs[LIBRARY_ELEMENT3] = library; | |
| 588 } | 582 } |
| 589 | 583 |
| 590 /** | 584 /** |
| 591 * Return a map from the names of the inputs of this kind of task to the task | 585 * Return a map from the names of the inputs of this kind of task to the task |
| 592 * input descriptors describing those inputs for a task with the | 586 * input descriptors describing those inputs for a task with the |
| 593 * given library [source]. | 587 * given library [source]. |
| 594 */ | 588 */ |
| 595 static Map<String, TaskInput> buildInputs(Source source) { | 589 static Map<String, TaskInput> buildInputs(Source source) { |
| 596 return <String, TaskInput>{ | 590 return <String, TaskInput>{ |
| 597 LIBRARY2_ELEMENT_INPUT: LIBRARY_ELEMENT2.inputFor(source), | 591 LIBRARY_INPUT: LIBRARY_ELEMENT3.inputFor(source), |
| 598 PUBLIC_NAMESPACES_INPUT: new ListToMapTaskInput<Source, Namespace>( | 592 'exportsLibraryPublicNamespace': |
| 599 EXPORT_SOURCE_CLOSURE.inputFor(source), | 593 new ListToMapTaskInput<Source, LibraryElement>( |
| 600 (Source source) => PUBLIC_NAMESPACE.inputFor(source)) | 594 EXPORT_SOURCE_CLOSURE.inputFor(source), |
| 595 (Source source) => LIBRARY_ELEMENT3.inputFor(source)) | |
| 601 }; | 596 }; |
| 602 } | 597 } |
| 603 | 598 |
| 604 /** | 599 /** |
| 605 * Create a [BuildExportNamespaceTask] based on the given [target] in | 600 * Create a [BuildExportNamespaceTask] based on the given [target] in |
| 606 * the given [context]. | 601 * the given [context]. |
| 607 */ | 602 */ |
| 608 static BuildExportNamespaceTask createTask( | 603 static BuildExportNamespaceTask createTask( |
| 609 AnalysisContext context, AnalysisTarget target) { | 604 AnalysisContext context, AnalysisTarget target) { |
| 610 return new BuildExportNamespaceTask(context, target); | 605 return new BuildExportNamespaceTask(context, target); |
| 611 } | 606 } |
| 612 } | 607 } |
| 613 | 608 |
| 614 /** | 609 /** |
| 615 * A task that builds [EXPORT_SOURCE_CLOSURE] of a library. | 610 * A task that builds [EXPORT_SOURCE_CLOSURE] of a library. |
| 616 */ | 611 */ |
| 617 class BuildExportSourceClosureTask extends SourceBasedAnalysisTask { | 612 class BuildExportSourceClosureTask extends SourceBasedAnalysisTask { |
| 618 /** | 613 /** |
| 619 * The name of the input for [LIBRARY_ELEMENT2] of a library. | 614 * The name of the input for [LIBRARY_ELEMENT3] of a library. |
| 620 */ | 615 */ |
| 621 static const String LIBRARY2_ELEMENT_INPUT = 'LIBRARY2_ELEMENT_INPUT'; | 616 static const String LIBRARY2_ELEMENT_INPUT = 'LIBRARY2_ELEMENT_INPUT'; |
| 622 | 617 |
| 623 /** | 618 /** |
| 624 * The task descriptor describing this kind of task. | 619 * The task descriptor describing this kind of task. |
| 625 */ | 620 */ |
| 626 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 621 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 627 'BuildExportSourceClosureTask', createTask, buildInputs, | 622 'BuildExportSourceClosureTask', createTask, buildInputs, |
| 628 <ResultDescriptor>[EXPORT_SOURCE_CLOSURE]); | 623 <ResultDescriptor>[EXPORT_SOURCE_CLOSURE]); |
| 629 | 624 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 AnalysisContext context, AnalysisTarget target) { | 946 AnalysisContext context, AnalysisTarget target) { |
| 952 return new BuildLibraryElementTask(context, target); | 947 return new BuildLibraryElementTask(context, target); |
| 953 } | 948 } |
| 954 } | 949 } |
| 955 | 950 |
| 956 /** | 951 /** |
| 957 * A task that builds [PUBLIC_NAMESPACE] for a library. | 952 * A task that builds [PUBLIC_NAMESPACE] for a library. |
| 958 */ | 953 */ |
| 959 class BuildPublicNamespaceTask extends SourceBasedAnalysisTask { | 954 class BuildPublicNamespaceTask extends SourceBasedAnalysisTask { |
| 960 /** | 955 /** |
| 961 * The name of the input for [LIBRARY_ELEMENT1] of a library. | 956 * The name of the input for [LIBRARY_ELEMENT2] of a library. |
| 962 */ | 957 */ |
| 963 static const String BUILT_LIBRARY_ELEMENT_INPUT_NAME = | 958 static const String LIBRARY_INPUT = 'LIBRARY_INPUT'; |
| 964 'BUILT_LIBRARY_ELEMENT_INPUT_NAME'; | |
| 965 | 959 |
| 966 /** | 960 /** |
| 967 * The task descriptor describing this kind of task. | 961 * The task descriptor describing this kind of task. |
| 968 */ | 962 */ |
| 969 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 963 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 970 'BUILD_PUBLIC_NAMESPACE', createTask, buildInputs, | 964 'BuildPublicNamespaceTask', createTask, buildInputs, |
| 971 <ResultDescriptor>[PUBLIC_NAMESPACE]); | 965 <ResultDescriptor>[LIBRARY_ELEMENT3]); |
| 972 | 966 |
| 973 BuildPublicNamespaceTask( | 967 BuildPublicNamespaceTask( |
| 974 InternalAnalysisContext context, AnalysisTarget target) | 968 InternalAnalysisContext context, AnalysisTarget target) |
| 975 : super(context, target); | 969 : super(context, target); |
| 976 | 970 |
| 977 @override | 971 @override |
| 978 TaskDescriptor get descriptor => DESCRIPTOR; | 972 TaskDescriptor get descriptor => DESCRIPTOR; |
| 979 | 973 |
| 980 @override | 974 @override |
| 981 void internalPerform() { | 975 void internalPerform() { |
| 982 LibraryElement library = getRequiredInput(BUILT_LIBRARY_ELEMENT_INPUT_NAME); | 976 LibraryElementImpl library = getRequiredInput(LIBRARY_INPUT); |
| 983 Namespace namespace = new PublicNamespaceBuilder().build(library); | 977 library.publicNamespace = new PublicNamespaceBuilder().build(library); |
| 984 outputs[PUBLIC_NAMESPACE] = namespace; | 978 outputs[LIBRARY_ELEMENT3] = library; |
| 985 } | 979 } |
| 986 | 980 |
| 987 /** | 981 /** |
| 988 * Return a map from the names of the inputs of this kind of task to the task | 982 * Return a map from the names of the inputs of this kind of task to the task |
| 989 * input descriptors describing those inputs for a task with the | 983 * input descriptors describing those inputs for a task with the |
| 990 * given library [source]. | 984 * given library [source]. |
| 991 */ | 985 */ |
| 992 static Map<String, TaskInput> buildInputs(Source source) { | 986 static Map<String, TaskInput> buildInputs(Source source) { |
| 993 return <String, TaskInput>{ | 987 return <String, TaskInput>{ |
| 994 BUILT_LIBRARY_ELEMENT_INPUT_NAME: LIBRARY_ELEMENT1.inputFor(source) | 988 LIBRARY_INPUT: LIBRARY_ELEMENT2.inputFor(source) |
| 995 }; | 989 }; |
| 996 } | 990 } |
| 997 | 991 |
| 998 /** | 992 /** |
| 999 * Create a [BuildPublicNamespaceTask] based on the given [target] in | 993 * Create a [BuildPublicNamespaceTask] based on the given [target] in |
| 1000 * the given [context]. | 994 * the given [context]. |
| 1001 */ | 995 */ |
| 1002 static BuildPublicNamespaceTask createTask( | 996 static BuildPublicNamespaceTask createTask( |
| 1003 AnalysisContext context, AnalysisTarget target) { | 997 AnalysisContext context, AnalysisTarget target) { |
| 1004 return new BuildPublicNamespaceTask(context, target); | 998 return new BuildPublicNamespaceTask(context, target); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1028 | 1022 |
| 1029 BuildTypeProviderTask( | 1023 BuildTypeProviderTask( |
| 1030 InternalAnalysisContext context, AnalysisContextTarget target) | 1024 InternalAnalysisContext context, AnalysisContextTarget target) |
| 1031 : super(context, target); | 1025 : super(context, target); |
| 1032 | 1026 |
| 1033 @override | 1027 @override |
| 1034 TaskDescriptor get descriptor => DESCRIPTOR; | 1028 TaskDescriptor get descriptor => DESCRIPTOR; |
| 1035 | 1029 |
| 1036 @override | 1030 @override |
| 1037 void internalPerform() { | 1031 void internalPerform() { |
| 1038 Namespace coreNamespace = getRequiredInput(CORE_INPUT); | 1032 LibraryElement coreLibrary = getRequiredInput(CORE_INPUT); |
| 1039 Namespace asyncNamespace = getRequiredInput(ASYNC_INPUT); | 1033 LibraryElement asyncLibrary = getRequiredInput(ASYNC_INPUT); |
| 1034 Namespace coreNamespace = coreLibrary.publicNamespace; | |
| 1035 Namespace asyncNamespace = asyncLibrary.publicNamespace; | |
| 1040 // | 1036 // |
| 1041 // Record outputs. | 1037 // Record outputs. |
| 1042 // | 1038 // |
| 1043 TypeProvider typeProvider = | 1039 TypeProvider typeProvider = |
| 1044 new TypeProviderImpl.forNamespaces(coreNamespace, asyncNamespace); | 1040 new TypeProviderImpl.forNamespaces(coreNamespace, asyncNamespace); |
| 1045 (context as ExtendedAnalysisContext).typeProvider = typeProvider; | 1041 (context as ExtendedAnalysisContext).typeProvider = typeProvider; |
| 1046 outputs[TYPE_PROVIDER] = typeProvider; | 1042 outputs[TYPE_PROVIDER] = typeProvider; |
| 1047 } | 1043 } |
| 1048 | 1044 |
| 1049 static Map<String, TaskInput> buildInputs(AnalysisContextTarget target) { | 1045 static Map<String, TaskInput> buildInputs(AnalysisContextTarget target) { |
| 1050 SourceFactory sourceFactory = target.context.sourceFactory; | 1046 SourceFactory sourceFactory = target.context.sourceFactory; |
| 1051 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); | 1047 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); |
| 1052 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); | 1048 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); |
| 1053 return <String, TaskInput>{ | 1049 return <String, TaskInput>{ |
| 1054 CORE_INPUT: PUBLIC_NAMESPACE.inputFor(coreSource), | 1050 CORE_INPUT: LIBRARY_ELEMENT3.inputFor(coreSource), |
| 1055 ASYNC_INPUT: PUBLIC_NAMESPACE.inputFor(asyncSource) | 1051 ASYNC_INPUT: LIBRARY_ELEMENT3.inputFor(asyncSource) |
| 1056 }; | 1052 }; |
| 1057 } | 1053 } |
| 1058 | 1054 |
| 1059 /** | 1055 /** |
| 1060 * Create a [BuildTypeProviderTask] based on the given [context]. | 1056 * Create a [BuildTypeProviderTask] based on the given [context]. |
| 1061 */ | 1057 */ |
| 1062 static BuildTypeProviderTask createTask( | 1058 static BuildTypeProviderTask createTask( |
| 1063 AnalysisContext context, AnalysisContextTarget target) { | 1059 AnalysisContext context, AnalysisContextTarget target) { |
| 1064 return new BuildTypeProviderTask(context, target); | 1060 return new BuildTypeProviderTask(context, target); |
| 1065 } | 1061 } |
| 1066 } | 1062 } |
| 1067 | 1063 |
| 1068 /** | 1064 /** |
| 1069 * The helper for building the export [Namespace] of a [LibraryElement]. | 1065 * The helper for building the export [Namespace] of a [LibraryElement]. |
| 1070 */ | 1066 */ |
| 1071 class ExportNamespaceBuilder { | 1067 class ExportNamespaceBuilder { |
| 1072 final Map<Source, Namespace> _publicNamespaces; | |
| 1073 | |
| 1074 ExportNamespaceBuilder(this._publicNamespaces); | |
| 1075 | |
| 1076 /** | 1068 /** |
| 1077 * Build the export [Namespace] of the given [LibraryElement]. | 1069 * Build the export [Namespace] of the given [LibraryElement]. |
| 1078 */ | 1070 */ |
| 1079 Namespace build(LibraryElement library) { | 1071 Namespace build(LibraryElement library) { |
| 1080 return new Namespace( | 1072 return new Namespace( |
| 1081 _createExportMapping(library, new HashSet<LibraryElement>())); | 1073 _createExportMapping(library, new HashSet<LibraryElement>())); |
| 1082 } | 1074 } |
| 1083 | 1075 |
| 1084 /** | 1076 /** |
| 1085 * Create a mapping table representing the export namespace of the given | 1077 * Create a mapping table representing the export namespace of the given |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1104 // valid library. | 1096 // valid library. |
| 1105 // | 1097 // |
| 1106 HashMap<String, Element> exportedNames = | 1098 HashMap<String, Element> exportedNames = |
| 1107 _createExportMapping(exportedLibrary, visitedElements); | 1099 _createExportMapping(exportedLibrary, visitedElements); |
| 1108 exportedNames = _applyCombinators(exportedNames, element.combinators); | 1100 exportedNames = _applyCombinators(exportedNames, element.combinators); |
| 1109 definedNames.addAll(exportedNames); | 1101 definedNames.addAll(exportedNames); |
| 1110 } | 1102 } |
| 1111 } | 1103 } |
| 1112 // Add names of the public namespace. | 1104 // Add names of the public namespace. |
| 1113 { | 1105 { |
| 1114 Namespace publicNamespace = _publicNamespaces[library.source]; | 1106 Namespace publicNamespace = library.publicNamespace; |
| 1115 if (publicNamespace != null) { | 1107 if (publicNamespace != null) { |
| 1116 definedNames.addAll(publicNamespace.definedNames); | 1108 definedNames.addAll(publicNamespace.definedNames); |
| 1117 } | 1109 } |
| 1118 } | 1110 } |
| 1119 return definedNames; | 1111 return definedNames; |
| 1120 } finally { | 1112 } finally { |
| 1121 visitedElements.remove(library); | 1113 visitedElements.remove(library); |
| 1122 } | 1114 } |
| 1123 } | 1115 } |
| 1124 | 1116 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1455 } | 1447 } |
| 1456 | 1448 |
| 1457 /** | 1449 /** |
| 1458 * Create a [ScanDartTask] based on the given [target] in the given [context]. | 1450 * Create a [ScanDartTask] based on the given [target] in the given [context]. |
| 1459 */ | 1451 */ |
| 1460 static ScanDartTask createTask( | 1452 static ScanDartTask createTask( |
| 1461 AnalysisContext context, AnalysisTarget target) { | 1453 AnalysisContext context, AnalysisTarget target) { |
| 1462 return new ScanDartTask(context, target); | 1454 return new ScanDartTask(context, target); |
| 1463 } | 1455 } |
| 1464 } | 1456 } |
| OLD | NEW |