| 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: ANALYSIS_ERRORS); | 49 contributesTo: ANALYSIS_ERRORS); |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * The sources representing the export closure of a library. |
| 53 * |
| 54 * The result is only available for targets representing a Dart library. |
| 55 */ |
| 56 final ResultDescriptor<List<Source>> EXPORT_SOURCE_CLOSURE = |
| 57 new ResultDescriptor<List<Source>>('EXPORT_SOURCE_CLOSURE', null); |
| 58 |
| 59 /** |
| 52 * The partial [LibraryElement] associated with a library. | 60 * The partial [LibraryElement] associated with a library. |
| 53 * | 61 * |
| 54 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each | 62 * The [LibraryElement] and its [CompilationUnitElement]s are attached to each |
| 55 * other. Directives 'library', 'part' and 'part of' are resolved. | 63 * other. Directives 'library', 'part' and 'part of' are resolved. |
| 56 * | 64 * |
| 57 * The result is only available for targets representing a Dart library. | 65 * The result is only available for targets representing a Dart library. |
| 58 */ | 66 */ |
| 59 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = | 67 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT1 = |
| 60 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null); | 68 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT1', null); |
| 61 | 69 |
| 62 /** | 70 /** |
| 71 * The partial [LibraryElement] associated with a library. |
| 72 * |
| 73 * In addition to [LIBRARY_ELEMENT1] `imports` and `exports` of the |
| 74 * [LibraryElement] are set. |
| 75 * |
| 76 * The result is only available for targets representing a Dart library. |
| 77 */ |
| 78 final ResultDescriptor<LibraryElement> LIBRARY_ELEMENT2 = |
| 79 new ResultDescriptor<LibraryElement>('LIBRARY_ELEMENT2', null); |
| 80 |
| 81 /** |
| 63 * The partially resolved [CompilationUnit] associated with a unit. | 82 * The partially resolved [CompilationUnit] associated with a unit. |
| 64 * | 83 * |
| 65 * All declarations bound to the element defined by the declaration. | 84 * All declarations bound to the element defined by the declaration. |
| 66 * | 85 * |
| 67 * The result is only available for targets representing a unit. | 86 * The result is only available for targets representing a unit. |
| 68 */ | 87 */ |
| 69 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT1 = | 88 final ResultDescriptor<CompilationUnit> RESOLVED_UNIT1 = |
| 70 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT1', null); | 89 new ResultDescriptor<CompilationUnit>('RESOLVED_UNIT1', null); |
| 71 | 90 |
| 72 /** | 91 /** |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 * Create a [BuildCompilationUnitElementTask] based on the given [target] in | 192 * Create a [BuildCompilationUnitElementTask] based on the given [target] in |
| 174 * the given [context]. | 193 * the given [context]. |
| 175 */ | 194 */ |
| 176 static BuildCompilationUnitElementTask createTask( | 195 static BuildCompilationUnitElementTask createTask( |
| 177 AnalysisContext context, AnalysisTarget target) { | 196 AnalysisContext context, AnalysisTarget target) { |
| 178 return new BuildCompilationUnitElementTask(context, target); | 197 return new BuildCompilationUnitElementTask(context, target); |
| 179 } | 198 } |
| 180 } | 199 } |
| 181 | 200 |
| 182 /** | 201 /** |
| 183 * A task that builds [RESOLVED_UNIT3] for a library. | 202 * A task that builds imports and export directive elements for a library. |
| 184 */ | 203 */ |
| 185 class BuildDirectiveElementsTask extends SourceBasedAnalysisTask { | 204 class BuildDirectiveElementsTask extends SourceBasedAnalysisTask { |
| 186 /** | 205 /** |
| 187 * The name of the input for [RESOLVED_UNIT2] of a library unit. | 206 * The name of the input for [RESOLVED_UNIT2] of a library unit. |
| 188 */ | 207 */ |
| 189 static const String RESOLVED_UNIT2_INPUT_NAME = 'RESOLVED_UNIT2_INPUT_NAME'; | 208 static const String RESOLVED_UNIT2_INPUT_NAME = 'RESOLVED_UNIT2_INPUT_NAME'; |
| 190 | 209 |
| 191 /** | 210 /** |
| 192 * The input with a list of [LIBRARY_ELEMENT1]s of imported libraries. | 211 * The input with a list of [LIBRARY_ELEMENT1]s of imported libraries. |
| 193 */ | 212 */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 210 * The input with a list of [SOURCE_KIND]s of exported libraries. | 229 * The input with a list of [SOURCE_KIND]s of exported libraries. |
| 211 */ | 230 */ |
| 212 static const String EXPORTS_SOURCE_KIND_INPUT_NAME = | 231 static const String EXPORTS_SOURCE_KIND_INPUT_NAME = |
| 213 'EXPORTS_SOURCE_KIND_INPUT_NAME'; | 232 'EXPORTS_SOURCE_KIND_INPUT_NAME'; |
| 214 | 233 |
| 215 /** | 234 /** |
| 216 * The task descriptor describing this kind of task. | 235 * The task descriptor describing this kind of task. |
| 217 */ | 236 */ |
| 218 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 237 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 219 'BUILD_RESOLVED_UNIT3', createTask, buildInputs, <ResultDescriptor>[ | 238 'BUILD_RESOLVED_UNIT3', createTask, buildInputs, <ResultDescriptor>[ |
| 239 LIBRARY_ELEMENT2, |
| 220 RESOLVED_UNIT3, | 240 RESOLVED_UNIT3, |
| 221 BUILD_DIRECTIVES_ERRORS | 241 BUILD_DIRECTIVES_ERRORS |
| 222 ]); | 242 ]); |
| 223 | 243 |
| 224 BuildDirectiveElementsTask( | 244 BuildDirectiveElementsTask( |
| 225 InternalAnalysisContext context, AnalysisTarget target) | 245 InternalAnalysisContext context, AnalysisTarget target) |
| 226 : super(context, target); | 246 : super(context, target); |
| 227 | 247 |
| 228 @override | 248 @override |
| 229 TaskDescriptor get descriptor => DESCRIPTOR; | 249 TaskDescriptor get descriptor => DESCRIPTOR; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // Namespace namespace = new NamespaceBuilder() | 374 // Namespace namespace = new NamespaceBuilder() |
| 355 // .createExportNamespaceForLibrary(libraryElement); | 375 // .createExportNamespaceForLibrary(libraryElement); |
| 356 // Element element = namespace.get(FunctionElement.MAIN_FUNCTION_NAME); | 376 // Element element = namespace.get(FunctionElement.MAIN_FUNCTION_NAME); |
| 357 // if (element is FunctionElement) { | 377 // if (element is FunctionElement) { |
| 358 // libraryElement.entryPoint = element; | 378 // libraryElement.entryPoint = element; |
| 359 // } | 379 // } |
| 360 // } | 380 // } |
| 361 // | 381 // |
| 362 // Record outputs. | 382 // Record outputs. |
| 363 // | 383 // |
| 384 outputs[LIBRARY_ELEMENT2] = libraryElement; |
| 364 outputs[RESOLVED_UNIT3] = libraryUnit; | 385 outputs[RESOLVED_UNIT3] = libraryUnit; |
| 365 outputs[BUILD_DIRECTIVES_ERRORS] = errors; | 386 outputs[BUILD_DIRECTIVES_ERRORS] = errors; |
| 366 } | 387 } |
| 367 | 388 |
| 368 /** | 389 /** |
| 369 * Return a map from the names of the inputs of this kind of task to the task | 390 * Return a map from the names of the inputs of this kind of task to the task |
| 370 * input descriptors describing those inputs for a task with the | 391 * input descriptors describing those inputs for a task with the |
| 371 * given library [source]. | 392 * given library [source]. |
| 372 */ | 393 */ |
| 373 static Map<String, TaskInput> buildInputs(Source source) { | 394 static Map<String, TaskInput> buildInputs(Source source) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 * Create a [BuildEnumMemberElementsTask] based on the given [target] in | 514 * Create a [BuildEnumMemberElementsTask] based on the given [target] in |
| 494 * the given [context]. | 515 * the given [context]. |
| 495 */ | 516 */ |
| 496 static BuildEnumMemberElementsTask createTask( | 517 static BuildEnumMemberElementsTask createTask( |
| 497 AnalysisContext context, AnalysisTarget target) { | 518 AnalysisContext context, AnalysisTarget target) { |
| 498 return new BuildEnumMemberElementsTask(context, target); | 519 return new BuildEnumMemberElementsTask(context, target); |
| 499 } | 520 } |
| 500 } | 521 } |
| 501 | 522 |
| 502 /** | 523 /** |
| 524 * A task that builds [EXPORT_SOURCE_CLOSURE] of a library. |
| 525 */ |
| 526 class BuildExportSourceClosureTask extends SourceBasedAnalysisTask { |
| 527 /** |
| 528 * The name of the input for [LIBRARY_ELEMENT2] of a library. |
| 529 */ |
| 530 static const String LIBRARY2_ELEMENT_INPUT = 'LIBRARY2_ELEMENT_INPUT'; |
| 531 |
| 532 /** |
| 533 * The task descriptor describing this kind of task. |
| 534 */ |
| 535 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 536 'BuildExportSourceClosureTask', createTask, buildInputs, |
| 537 <ResultDescriptor>[EXPORT_SOURCE_CLOSURE]); |
| 538 |
| 539 BuildExportSourceClosureTask( |
| 540 InternalAnalysisContext context, AnalysisTarget target) |
| 541 : super(context, target); |
| 542 |
| 543 @override |
| 544 TaskDescriptor get descriptor => DESCRIPTOR; |
| 545 |
| 546 @override |
| 547 void internalPerform() { |
| 548 LibraryElement library = getRequiredInput(LIBRARY2_ELEMENT_INPUT); |
| 549 // |
| 550 // Compute export closure. |
| 551 // |
| 552 Set<LibraryElement> libraries = new Set<LibraryElement>(); |
| 553 _buildExportClosure(libraries, library); |
| 554 List<Source> sources = libraries.map((lib) => lib.source).toList(); |
| 555 // |
| 556 // Record outputs. |
| 557 // |
| 558 outputs[EXPORT_SOURCE_CLOSURE] = sources; |
| 559 } |
| 560 |
| 561 /** |
| 562 * Return a map from the names of the inputs of this kind of task to the task |
| 563 * input descriptors describing those inputs for a task with the |
| 564 * given library [source]. |
| 565 */ |
| 566 static Map<String, TaskInput> buildInputs(Source source) { |
| 567 return <String, TaskInput>{ |
| 568 LIBRARY2_ELEMENT_INPUT: LIBRARY_ELEMENT2.inputFor(source) |
| 569 }; |
| 570 } |
| 571 |
| 572 /** |
| 573 * Create a [BuildExportSourceClosureTask] based on the given [target] in |
| 574 * the given [context]. |
| 575 */ |
| 576 static BuildExportSourceClosureTask createTask( |
| 577 AnalysisContext context, AnalysisTarget target) { |
| 578 return new BuildExportSourceClosureTask(context, target); |
| 579 } |
| 580 |
| 581 /** |
| 582 * Create a set representing the export closure of the given [library]. |
| 583 */ |
| 584 static void _buildExportClosure( |
| 585 Set<LibraryElement> libraries, LibraryElement library) { |
| 586 if (library != null && libraries.add(library)) { |
| 587 for (ExportElement exportElement in library.exports) { |
| 588 _buildExportClosure(libraries, exportElement.exportedLibrary); |
| 589 } |
| 590 } |
| 591 } |
| 592 } |
| 593 |
| 594 /** |
| 503 * A task that builds a library element for a Dart library. | 595 * A task that builds a library element for a Dart library. |
| 504 */ | 596 */ |
| 505 class BuildLibraryElementTask extends SourceBasedAnalysisTask { | 597 class BuildLibraryElementTask extends SourceBasedAnalysisTask { |
| 506 /** | 598 /** |
| 507 * The name of the input whose value is the defining [RESOLVED_UNIT1]. | 599 * The name of the input whose value is the defining [RESOLVED_UNIT1]. |
| 508 */ | 600 */ |
| 509 static const String DEFINING_RESOLVER_UNIT1_INPUT_NAME = | 601 static const String DEFINING_RESOLVER_UNIT1_INPUT_NAME = |
| 510 'DEFINING_RESOLVER_UNIT1_INPUT_NAME'; | 602 'DEFINING_RESOLVER_UNIT1_INPUT_NAME'; |
| 511 | 603 |
| 512 /** | 604 /** |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 } | 1222 } |
| 1131 | 1223 |
| 1132 /** | 1224 /** |
| 1133 * Create a [ScanDartTask] based on the given [target] in the given [context]. | 1225 * Create a [ScanDartTask] based on the given [target] in the given [context]. |
| 1134 */ | 1226 */ |
| 1135 static ScanDartTask createTask( | 1227 static ScanDartTask createTask( |
| 1136 AnalysisContext context, AnalysisTarget target) { | 1228 AnalysisContext context, AnalysisTarget target) { |
| 1137 return new ScanDartTask(context, target); | 1229 return new ScanDartTask(context, target); |
| 1138 } | 1230 } |
| 1139 } | 1231 } |
| OLD | NEW |