| 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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( | 512 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
| 513 'BUILD_LIBRARY_ELEMENT', createTask, buildInputs, <ResultDescriptor>[ | 513 'BUILD_LIBRARY_ELEMENT', createTask, buildInputs, <ResultDescriptor>[ |
| 514 BUILD_LIBRARY_ERRORS, | 514 BUILD_LIBRARY_ERRORS, |
| 515 RESOLVED_UNIT2, | 515 RESOLVED_UNIT2, |
| 516 LIBRARY_ELEMENT1, | 516 LIBRARY_ELEMENT1, |
| 517 IS_LAUNCHABLE, | 517 IS_LAUNCHABLE, |
| 518 HAS_HTML_IMPORT | 518 HAS_HTML_IMPORT |
| 519 ]); | 519 ]); |
| 520 | 520 |
| 521 /** | 521 /** |
| 522 * The constant used as an unknown common library name in parts. |
| 523 */ |
| 524 static const String _UNKNOWN_LIBRARY_NAME = 'unknown-library-name'; |
| 525 |
| 526 /** |
| 522 * Initialize a newly created task to build a library element for the given | 527 * Initialize a newly created task to build a library element for the given |
| 523 * [target] in the given [context]. | 528 * [target] in the given [context]. |
| 524 */ | 529 */ |
| 525 BuildLibraryElementTask( | 530 BuildLibraryElementTask( |
| 526 InternalAnalysisContext context, AnalysisTarget target) | 531 InternalAnalysisContext context, AnalysisTarget target) |
| 527 : super(context, target); | 532 : super(context, target); |
| 528 | 533 |
| 529 @override | 534 @override |
| 530 TaskDescriptor get descriptor => DESCRIPTOR; | 535 TaskDescriptor get descriptor => DESCRIPTOR; |
| 531 | 536 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 549 new HashMap<Source, CompilationUnit>(); | 554 new HashMap<Source, CompilationUnit>(); |
| 550 for (CompilationUnit partUnit in partUnits) { | 555 for (CompilationUnit partUnit in partUnits) { |
| 551 Source partSource = partUnit.element.source; | 556 Source partSource = partUnit.element.source; |
| 552 partUnitMap[partSource] = partUnit; | 557 partUnitMap[partSource] = partUnit; |
| 553 } | 558 } |
| 554 Source htmlSource = context.sourceFactory.forUri(DartSdk.DART_HTML); | 559 Source htmlSource = context.sourceFactory.forUri(DartSdk.DART_HTML); |
| 555 // | 560 // |
| 556 // Update "part" directives. | 561 // Update "part" directives. |
| 557 // | 562 // |
| 558 LibraryIdentifier libraryNameNode = null; | 563 LibraryIdentifier libraryNameNode = null; |
| 564 String partsLibraryName = _UNKNOWN_LIBRARY_NAME; |
| 559 bool hasHtmlImport = false; | 565 bool hasHtmlImport = false; |
| 560 bool hasPartDirective = false; | 566 bool hasPartDirective = false; |
| 561 FunctionElement entryPoint = | 567 FunctionElement entryPoint = |
| 562 _findEntryPoint(definingCompilationUnitElement); | 568 _findEntryPoint(definingCompilationUnitElement); |
| 563 List<Directive> directivesToResolve = <Directive>[]; | 569 List<Directive> directivesToResolve = <Directive>[]; |
| 564 List<CompilationUnitElementImpl> sourcedCompilationUnits = | 570 List<CompilationUnitElementImpl> sourcedCompilationUnits = |
| 565 <CompilationUnitElementImpl>[]; | 571 <CompilationUnitElementImpl>[]; |
| 566 for (Directive directive in definingCompilationUnit.directives) { | 572 for (Directive directive in definingCompilationUnit.directives) { |
| 567 if (directive is ImportDirective) { | 573 if (directive is ImportDirective) { |
| 568 hasHtmlImport = hasHtmlImport || directive.source == htmlSource; | 574 hasHtmlImport = hasHtmlImport || directive.source == htmlSource; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 586 // Validate that the part contains a part-of directive with the same | 592 // Validate that the part contains a part-of directive with the same |
| 587 // name as the library. | 593 // name as the library. |
| 588 // | 594 // |
| 589 String partLibraryName = | 595 String partLibraryName = |
| 590 _getPartLibraryName(partSource, partUnit, directivesToResolve); | 596 _getPartLibraryName(partSource, partUnit, directivesToResolve); |
| 591 if (partLibraryName == null) { | 597 if (partLibraryName == null) { |
| 592 errors.add(new AnalysisError.con2(librarySource, partUri.offset, | 598 errors.add(new AnalysisError.con2(librarySource, partUri.offset, |
| 593 partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, | 599 partUri.length, CompileTimeErrorCode.PART_OF_NON_PART, |
| 594 [partUri.toSource()])); | 600 [partUri.toSource()])); |
| 595 } else if (libraryNameNode == null) { | 601 } else if (libraryNameNode == null) { |
| 596 // TODO(brianwilkerson) Collect the names declared by the part. | 602 if (partsLibraryName == _UNKNOWN_LIBRARY_NAME) { |
| 597 // If they are all the same then we can use that name as the | 603 partsLibraryName = partLibraryName; |
| 598 // inferred name of the library and present it in a quick-fix. | 604 } else if (partsLibraryName != partLibraryName) { |
| 599 // partLibraryNames.add(partLibraryName); | 605 partsLibraryName = null; |
| 606 } |
| 600 } else if (libraryNameNode.name != partLibraryName) { | 607 } else if (libraryNameNode.name != partLibraryName) { |
| 601 errors.add(new AnalysisError.con2(librarySource, partUri.offset, | 608 errors.add(new AnalysisError.con2(librarySource, partUri.offset, |
| 602 partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [ | 609 partUri.length, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY, [ |
| 603 libraryNameNode.name, | 610 libraryNameNode.name, |
| 604 partLibraryName | 611 partLibraryName |
| 605 ])); | 612 ])); |
| 606 } | 613 } |
| 607 if (entryPoint == null) { | 614 if (entryPoint == null) { |
| 608 entryPoint = _findEntryPoint(partElement); | 615 entryPoint = _findEntryPoint(partElement); |
| 609 } | 616 } |
| 610 directive.element = partElement; | 617 directive.element = partElement; |
| 611 sourcedCompilationUnits.add(partElement); | 618 sourcedCompilationUnits.add(partElement); |
| 612 } | 619 } |
| 613 } | 620 } |
| 614 } | 621 } |
| 615 if (hasPartDirective && libraryNameNode == null) { | 622 if (hasPartDirective && libraryNameNode == null) { |
| 616 errors.add(new AnalysisError.con1(librarySource, | 623 AnalysisError error; |
| 617 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART)); | 624 if (partsLibraryName != _UNKNOWN_LIBRARY_NAME && |
| 625 partsLibraryName != null) { |
| 626 error = new AnalysisErrorWithProperties.con1(librarySource, |
| 627 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART) |
| 628 ..setProperty(ErrorProperty.PARTS_LIBRARY_NAME, partsLibraryName); |
| 629 } else { |
| 630 error = new AnalysisError.con1(librarySource, |
| 631 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART); |
| 632 } |
| 633 errors.add(error); |
| 618 } | 634 } |
| 619 // | 635 // |
| 620 // Create and populate the library element. | 636 // Create and populate the library element. |
| 621 // | 637 // |
| 622 LibraryElementImpl libraryElement = | 638 LibraryElementImpl libraryElement = |
| 623 new LibraryElementImpl.forNode(context, libraryNameNode); | 639 new LibraryElementImpl.forNode(context, libraryNameNode); |
| 624 libraryElement.definingCompilationUnit = definingCompilationUnitElement; | 640 libraryElement.definingCompilationUnit = definingCompilationUnitElement; |
| 625 libraryElement.entryPoint = entryPoint; | 641 libraryElement.entryPoint = entryPoint; |
| 626 libraryElement.parts = sourcedCompilationUnits; | 642 libraryElement.parts = sourcedCompilationUnits; |
| 627 for (Directive directive in directivesToResolve) { | 643 for (Directive directive in directivesToResolve) { |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 } | 1093 } |
| 1078 | 1094 |
| 1079 /** | 1095 /** |
| 1080 * Create a [ScanDartTask] based on the given [target] in the given [context]. | 1096 * Create a [ScanDartTask] based on the given [target] in the given [context]. |
| 1081 */ | 1097 */ |
| 1082 static ScanDartTask createTask( | 1098 static ScanDartTask createTask( |
| 1083 AnalysisContext context, AnalysisTarget target) { | 1099 AnalysisContext context, AnalysisTarget target) { |
| 1084 return new ScanDartTask(context, target); | 1100 return new ScanDartTask(context, target); |
| 1085 } | 1101 } |
| 1086 } | 1102 } |
| OLD | NEW |