| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.dart.element.element; | 5 library analyzer.src.dart.element.element; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 3600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3611 return buffer.toString(); | 3611 return buffer.toString(); |
| 3612 } | 3612 } |
| 3613 } | 3613 } |
| 3614 | 3614 |
| 3615 /** | 3615 /** |
| 3616 * A concrete implementation of an [ImportElement]. | 3616 * A concrete implementation of an [ImportElement]. |
| 3617 */ | 3617 */ |
| 3618 class ImportElementImpl extends UriReferencedElementImpl | 3618 class ImportElementImpl extends UriReferencedElementImpl |
| 3619 implements ImportElement { | 3619 implements ImportElement { |
| 3620 /** | 3620 /** |
| 3621 * The unlinked representation of the import in the summary. |
| 3622 */ |
| 3623 final UnlinkedImport _unlinkedImport; |
| 3624 |
| 3625 /** |
| 3626 * The index of the dependency in the `imports` list. |
| 3627 */ |
| 3628 final int _linkedDependency; |
| 3629 |
| 3630 /** |
| 3621 * The offset of the prefix of this import in the file that contains the this | 3631 * The offset of the prefix of this import in the file that contains the this |
| 3622 * import directive, or `-1` if this import is synthetic. | 3632 * import directive, or `-1` if this import is synthetic. |
| 3623 */ | 3633 */ |
| 3624 int prefixOffset = 0; | 3634 int _prefixOffset = 0; |
| 3625 | 3635 |
| 3626 /** | 3636 /** |
| 3627 * The library that is imported into this library by this import directive. | 3637 * The library that is imported into this library by this import directive. |
| 3628 */ | 3638 */ |
| 3629 LibraryElement importedLibrary; | 3639 LibraryElement _importedLibrary; |
| 3630 | 3640 |
| 3631 /** | 3641 /** |
| 3632 * The combinators that were specified as part of the import directive in the | 3642 * The combinators that were specified as part of the import directive in the |
| 3633 * order in which they were specified. | 3643 * order in which they were specified. |
| 3634 */ | 3644 */ |
| 3635 List<NamespaceCombinator> combinators = NamespaceCombinator.EMPTY_LIST; | 3645 List<NamespaceCombinator> combinators = NamespaceCombinator.EMPTY_LIST; |
| 3636 | 3646 |
| 3637 /** | 3647 /** |
| 3638 * The prefix that was specified as part of the import directive, or `null` if | 3648 * The prefix that was specified as part of the import directive, or `null` if |
| 3639 * there was no prefix specified. | 3649 * there was no prefix specified. |
| 3640 */ | 3650 */ |
| 3641 PrefixElement prefix; | 3651 PrefixElement _prefix; |
| 3642 | 3652 |
| 3643 /** | 3653 /** |
| 3644 * Initialize a newly created import element at the given [offset]. | 3654 * Initialize a newly created import element at the given [offset]. |
| 3645 * The offset may be `-1` if the import is synthetic. | 3655 * The offset may be `-1` if the import is synthetic. |
| 3646 */ | 3656 */ |
| 3647 ImportElementImpl(int offset) : super(null, offset); | 3657 ImportElementImpl(int offset) |
| 3658 : _unlinkedImport = null, |
| 3659 _linkedDependency = null, |
| 3660 super(null, offset); |
| 3661 |
| 3662 /** |
| 3663 * Initialize using the given serialized information. |
| 3664 */ |
| 3665 ImportElementImpl.forSerialized(this._unlinkedImport, this._linkedDependency, |
| 3666 LibraryElementImpl enclosingLibrary) |
| 3667 : super.forSerialized(enclosingLibrary); |
| 3648 | 3668 |
| 3649 /** | 3669 /** |
| 3650 * Set whether this import is for a deferred library. | 3670 * Set whether this import is for a deferred library. |
| 3651 */ | 3671 */ |
| 3652 void set deferred(bool isDeferred) { | 3672 void set deferred(bool isDeferred) { |
| 3673 assert(_unlinkedImport == null); |
| 3653 setModifier(Modifier.DEFERRED, isDeferred); | 3674 setModifier(Modifier.DEFERRED, isDeferred); |
| 3654 } | 3675 } |
| 3655 | 3676 |
| 3656 @override | 3677 @override |
| 3657 String get identifier => "${importedLibrary.identifier}@$nameOffset"; | 3678 String get identifier => "${importedLibrary.identifier}@$nameOffset"; |
| 3658 | 3679 |
| 3659 @override | 3680 @override |
| 3660 bool get isDeferred => hasModifier(Modifier.DEFERRED); | 3681 LibraryElement get importedLibrary { |
| 3682 if (_linkedDependency != null) { |
| 3683 if (_importedLibrary == null) { |
| 3684 LibraryElementImpl library = enclosingElement as LibraryElementImpl; |
| 3685 if (_linkedDependency == 0) { |
| 3686 _importedLibrary = library; |
| 3687 } else { |
| 3688 _importedLibrary = library.resynthesizerContext |
| 3689 .buildImportedLibrary(_linkedDependency); |
| 3690 } |
| 3691 } |
| 3692 } |
| 3693 return _importedLibrary; |
| 3694 } |
| 3695 |
| 3696 void set importedLibrary(LibraryElement importedLibrary) { |
| 3697 assert(_unlinkedImport == null); |
| 3698 _importedLibrary = importedLibrary; |
| 3699 } |
| 3700 |
| 3701 @override |
| 3702 bool get isDeferred { |
| 3703 if (_unlinkedImport != null) { |
| 3704 return _unlinkedImport.isDeferred; |
| 3705 } |
| 3706 return hasModifier(Modifier.DEFERRED); |
| 3707 } |
| 3708 |
| 3709 @override |
| 3710 bool get isSynthetic { |
| 3711 if (_unlinkedImport != null) { |
| 3712 return _unlinkedImport.isImplicit; |
| 3713 } |
| 3714 return super.isSynthetic; |
| 3715 } |
| 3661 | 3716 |
| 3662 @override | 3717 @override |
| 3663 ElementKind get kind => ElementKind.IMPORT; | 3718 ElementKind get kind => ElementKind.IMPORT; |
| 3664 | 3719 |
| 3665 @override | 3720 @override |
| 3721 List<ElementAnnotation> get metadata { |
| 3722 if (_unlinkedImport != null) { |
| 3723 if (_metadata == null) { |
| 3724 CompilationUnitElementImpl definingUnit = |
| 3725 library.definingCompilationUnit as CompilationUnitElementImpl; |
| 3726 return _metadata ??= _unlinkedImport.annotations |
| 3727 .map((a) => |
| 3728 definingUnit.resynthesizerContext.buildAnnotation(this, a)) |
| 3729 .toList(); |
| 3730 } |
| 3731 } |
| 3732 return super.metadata; |
| 3733 } |
| 3734 |
| 3735 void set metadata(List<ElementAnnotation> metadata) { |
| 3736 assert(_unlinkedImport == null); |
| 3737 super.metadata = metadata; |
| 3738 } |
| 3739 |
| 3740 @override |
| 3741 int get nameOffset { |
| 3742 if (_unlinkedImport != null) { |
| 3743 if (_unlinkedImport.isImplicit) { |
| 3744 return -1; |
| 3745 } |
| 3746 return _unlinkedImport.offset; |
| 3747 } |
| 3748 return super.nameOffset; |
| 3749 } |
| 3750 |
| 3751 PrefixElement get prefix { |
| 3752 if (_unlinkedImport != null) { |
| 3753 if (_unlinkedImport.prefixReference != 0) { |
| 3754 _prefix = new PrefixElementImpl.forSerialized(_unlinkedImport, this); |
| 3755 } |
| 3756 } |
| 3757 return _prefix; |
| 3758 } |
| 3759 |
| 3760 void set prefix(PrefixElement prefix) { |
| 3761 assert(_unlinkedImport == null); |
| 3762 _prefix = prefix; |
| 3763 } |
| 3764 |
| 3765 @override |
| 3766 int get prefixOffset { |
| 3767 if (_unlinkedImport != null) { |
| 3768 return _unlinkedImport.prefixOffset; |
| 3769 } |
| 3770 return _prefixOffset; |
| 3771 } |
| 3772 |
| 3773 void set prefixOffset(int prefixOffset) { |
| 3774 assert(_unlinkedImport == null); |
| 3775 _prefixOffset = prefixOffset; |
| 3776 } |
| 3777 |
| 3778 @override |
| 3779 String get uri { |
| 3780 if (_unlinkedImport != null) { |
| 3781 if (_unlinkedImport.isImplicit) { |
| 3782 return null; |
| 3783 } |
| 3784 return _unlinkedImport.uri; |
| 3785 } |
| 3786 return super.uri; |
| 3787 } |
| 3788 |
| 3789 @override |
| 3790 void set uri(String uri) { |
| 3791 assert(_unlinkedImport == null); |
| 3792 super.uri = uri; |
| 3793 } |
| 3794 |
| 3795 @override |
| 3796 int get uriEnd { |
| 3797 if (_unlinkedImport != null) { |
| 3798 if (_unlinkedImport.isImplicit) { |
| 3799 return -1; |
| 3800 } |
| 3801 return _unlinkedImport.uriEnd; |
| 3802 } |
| 3803 return super.uriEnd; |
| 3804 } |
| 3805 |
| 3806 @override |
| 3807 void set uriEnd(int uriEnd) { |
| 3808 assert(_unlinkedImport == null); |
| 3809 super.uriEnd = uriEnd; |
| 3810 } |
| 3811 |
| 3812 @override |
| 3813 int get uriOffset { |
| 3814 if (_unlinkedImport != null) { |
| 3815 if (_unlinkedImport.isImplicit) { |
| 3816 return -1; |
| 3817 } |
| 3818 return _unlinkedImport.uriOffset; |
| 3819 } |
| 3820 return super.uriOffset; |
| 3821 } |
| 3822 |
| 3823 @override |
| 3824 void set uriOffset(int uriOffset) { |
| 3825 assert(_unlinkedImport == null); |
| 3826 super.uriOffset = uriOffset; |
| 3827 } |
| 3828 |
| 3829 @override |
| 3666 accept(ElementVisitor visitor) => visitor.visitImportElement(this); | 3830 accept(ElementVisitor visitor) => visitor.visitImportElement(this); |
| 3667 | 3831 |
| 3668 @override | 3832 @override |
| 3669 void appendTo(StringBuffer buffer) { | 3833 void appendTo(StringBuffer buffer) { |
| 3670 buffer.write("import "); | 3834 buffer.write("import "); |
| 3671 (importedLibrary as LibraryElementImpl).appendTo(buffer); | 3835 (importedLibrary as LibraryElementImpl).appendTo(buffer); |
| 3672 } | 3836 } |
| 3673 | 3837 |
| 3674 @override | 3838 @override |
| 3675 void visitChildren(ElementVisitor visitor) { | 3839 void visitChildren(ElementVisitor visitor) { |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4422 | 4586 |
| 4423 /** | 4587 /** |
| 4424 * The context in which the library is resynthesized. | 4588 * The context in which the library is resynthesized. |
| 4425 */ | 4589 */ |
| 4426 abstract class LibraryResynthesizerContext { | 4590 abstract class LibraryResynthesizerContext { |
| 4427 /** | 4591 /** |
| 4428 * Return the export namespace of the library. | 4592 * Return the export namespace of the library. |
| 4429 */ | 4593 */ |
| 4430 Namespace buildExportNamespace(); | 4594 Namespace buildExportNamespace(); |
| 4431 | 4595 |
| 4596 LibraryElement buildImportedLibrary(int dependency); |
| 4597 |
| 4432 /** | 4598 /** |
| 4433 * Return the public namespace of the library. | 4599 * Return the public namespace of the library. |
| 4434 */ | 4600 */ |
| 4435 Namespace buildPublicNamespace(); | 4601 Namespace buildPublicNamespace(); |
| 4436 | 4602 |
| 4437 /** | 4603 /** |
| 4438 * Find the entry point of the library. | 4604 * Find the entry point of the library. |
| 4439 */ | 4605 */ |
| 4440 FunctionElement findEntryPoint(); | 4606 FunctionElement findEntryPoint(); |
| 4441 | 4607 |
| (...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5479 buffer.write(defaultValueCode); | 5645 buffer.write(defaultValueCode); |
| 5480 } | 5646 } |
| 5481 } | 5647 } |
| 5482 } | 5648 } |
| 5483 | 5649 |
| 5484 /** | 5650 /** |
| 5485 * A concrete implementation of a [PrefixElement]. | 5651 * A concrete implementation of a [PrefixElement]. |
| 5486 */ | 5652 */ |
| 5487 class PrefixElementImpl extends ElementImpl implements PrefixElement { | 5653 class PrefixElementImpl extends ElementImpl implements PrefixElement { |
| 5488 /** | 5654 /** |
| 5655 * The unlinked representation of the import in the summary. |
| 5656 */ |
| 5657 final UnlinkedImport _unlinkedImport; |
| 5658 |
| 5659 /** |
| 5489 * Initialize a newly created method element to have the given [name] and | 5660 * Initialize a newly created method element to have the given [name] and |
| 5490 * [nameOffset]. | 5661 * [nameOffset]. |
| 5491 */ | 5662 */ |
| 5492 PrefixElementImpl(String name, int nameOffset) : super(name, nameOffset); | 5663 PrefixElementImpl(String name, int nameOffset) |
| 5664 : _unlinkedImport = null, |
| 5665 super(name, nameOffset); |
| 5493 | 5666 |
| 5494 /** | 5667 /** |
| 5495 * Initialize a newly created prefix element to have the given [name]. | 5668 * Initialize a newly created prefix element to have the given [name]. |
| 5496 */ | 5669 */ |
| 5497 PrefixElementImpl.forNode(Identifier name) : super.forNode(name); | 5670 PrefixElementImpl.forNode(Identifier name) |
| 5671 : _unlinkedImport = null, |
| 5672 super.forNode(name); |
| 5673 |
| 5674 /** |
| 5675 * Initialize using the given serialized information. |
| 5676 */ |
| 5677 PrefixElementImpl.forSerialized( |
| 5678 this._unlinkedImport, ImportElementImpl enclosingImport) |
| 5679 : super.forSerialized(enclosingImport); |
| 5680 |
| 5681 @override |
| 5682 String get displayName => name; |
| 5498 | 5683 |
| 5499 @override | 5684 @override |
| 5500 LibraryElement get enclosingElement => | 5685 LibraryElement get enclosingElement => |
| 5501 super.enclosingElement as LibraryElement; | 5686 super.enclosingElement as LibraryElement; |
| 5502 | 5687 |
| 5503 @override | 5688 @override |
| 5504 String get identifier => "_${super.identifier}"; | 5689 String get identifier => "_${super.identifier}"; |
| 5505 | 5690 |
| 5506 @override | 5691 @override |
| 5507 List<LibraryElement> get importedLibraries => LibraryElement.EMPTY_LIST; | 5692 List<LibraryElement> get importedLibraries => LibraryElement.EMPTY_LIST; |
| 5508 | 5693 |
| 5509 @override | 5694 @override |
| 5510 ElementKind get kind => ElementKind.PREFIX; | 5695 ElementKind get kind => ElementKind.PREFIX; |
| 5511 | 5696 |
| 5512 @override | 5697 @override |
| 5698 String get name { |
| 5699 if (_unlinkedImport != null) { |
| 5700 if (_name == null) { |
| 5701 LibraryElementImpl library = |
| 5702 enclosingElement.enclosingElement as LibraryElementImpl; |
| 5703 int prefixId = _unlinkedImport.prefixReference; |
| 5704 return _name = library._unlinkedDefiningUnit.references[prefixId].name; |
| 5705 } |
| 5706 } |
| 5707 return super.name; |
| 5708 } |
| 5709 |
| 5710 @override |
| 5711 int get nameOffset { |
| 5712 if (_unlinkedImport != null) { |
| 5713 return _unlinkedImport.prefixOffset; |
| 5714 } |
| 5715 return super.nameOffset; |
| 5716 } |
| 5717 |
| 5718 @override |
| 5513 accept(ElementVisitor visitor) => visitor.visitPrefixElement(this); | 5719 accept(ElementVisitor visitor) => visitor.visitPrefixElement(this); |
| 5514 | 5720 |
| 5515 @override | 5721 @override |
| 5516 void appendTo(StringBuffer buffer) { | 5722 void appendTo(StringBuffer buffer) { |
| 5517 buffer.write("as "); | 5723 buffer.write("as "); |
| 5518 super.appendTo(buffer); | 5724 super.appendTo(buffer); |
| 5519 } | 5725 } |
| 5520 } | 5726 } |
| 5521 | 5727 |
| 5522 /** | 5728 /** |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6341 | 6547 |
| 6342 @override | 6548 @override |
| 6343 void visitElement(Element element) { | 6549 void visitElement(Element element) { |
| 6344 int offset = element.nameOffset; | 6550 int offset = element.nameOffset; |
| 6345 if (offset != -1) { | 6551 if (offset != -1) { |
| 6346 map[offset] = element; | 6552 map[offset] = element; |
| 6347 } | 6553 } |
| 6348 super.visitElement(element); | 6554 super.visitElement(element); |
| 6349 } | 6555 } |
| 6350 } | 6556 } |
| OLD | NEW |