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/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1666 * A cached copy of the calculated hashCode for this element. | 1666 * A cached copy of the calculated hashCode for this element. |
1667 */ | 1667 */ |
1668 int _cachedHashCode; | 1668 int _cachedHashCode; |
1669 | 1669 |
1670 /** | 1670 /** |
1671 * A cached copy of the calculated location for this element. | 1671 * A cached copy of the calculated location for this element. |
1672 */ | 1672 */ |
1673 ElementLocation _cachedLocation; | 1673 ElementLocation _cachedLocation; |
1674 | 1674 |
1675 /** | 1675 /** |
1676 * The documentation comment for this element. | |
1677 */ | |
1678 String _docComment; | |
1679 | |
1680 /** | |
1676 * The offset to the beginning of the documentation comment, | 1681 * The offset to the beginning of the documentation comment, |
1677 * or `null` if this element does not have a documentation comment. | 1682 * or `null` if this element does not have a documentation comment. |
1678 */ | 1683 */ |
1679 int _docRangeOffset; | 1684 int _docRangeOffset; |
1680 | 1685 |
1681 /** | 1686 /** |
1682 * The length of the documentation comment range for this element. | 1687 * The length of the documentation comment range for this element. |
1683 */ | 1688 */ |
1684 int _docRangeLength; | 1689 int _docRangeLength; |
1685 | 1690 |
(...skipping 16 matching lines...) Expand all Loading... | |
1702 if (_enclosingElement == null) { | 1707 if (_enclosingElement == null) { |
1703 return null; | 1708 return null; |
1704 } | 1709 } |
1705 return _enclosingElement.context; | 1710 return _enclosingElement.context; |
1706 } | 1711 } |
1707 | 1712 |
1708 @override | 1713 @override |
1709 String get displayName => _name; | 1714 String get displayName => _name; |
1710 | 1715 |
1711 @override | 1716 @override |
1712 SourceRange get docRange { | 1717 SourceRange get docRange { |
scheglov
2015/12/17 22:10:14
Did we decide to remove this?
pquitslund
2015/12/17 22:12:56
We did and then reconsidered. It would break API
| |
1713 if (_docRangeOffset != null && _docRangeLength != null) { | 1718 if (_docRangeOffset != null && _docRangeLength != null) { |
1714 return new SourceRange(_docRangeOffset, _docRangeLength); | 1719 return new SourceRange(_docRangeOffset, _docRangeLength); |
1715 } | 1720 } |
1716 return null; | 1721 return null; |
1717 } | 1722 } |
1718 | 1723 |
1719 @override | 1724 @override |
1725 String get documentationComment => _docComment; | |
1726 | |
1727 /** | |
1728 * The documentation comment source for this element. | |
1729 */ | |
1730 void set documentationComment(String doc) { | |
1731 _docComment = doc?.replaceAll('\r\n', '\n'); | |
1732 } | |
1733 | |
1734 @override | |
1720 Element get enclosingElement => _enclosingElement; | 1735 Element get enclosingElement => _enclosingElement; |
1721 | 1736 |
1722 /** | 1737 /** |
1723 * Set the enclosing element of this element to the given [element]. | 1738 * Set the enclosing element of this element to the given [element]. |
1724 */ | 1739 */ |
1725 void set enclosingElement(Element element) { | 1740 void set enclosingElement(Element element) { |
1726 _enclosingElement = element as ElementImpl; | 1741 _enclosingElement = element as ElementImpl; |
1727 _cachedLocation = null; | 1742 _cachedLocation = null; |
1728 _cachedHashCode = null; | 1743 _cachedHashCode = null; |
1729 } | 1744 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1859 if (_name == null) { | 1874 if (_name == null) { |
1860 buffer.write("<unnamed "); | 1875 buffer.write("<unnamed "); |
1861 buffer.write(runtimeType.toString()); | 1876 buffer.write(runtimeType.toString()); |
1862 buffer.write(">"); | 1877 buffer.write(">"); |
1863 } else { | 1878 } else { |
1864 buffer.write(_name); | 1879 buffer.write(_name); |
1865 } | 1880 } |
1866 } | 1881 } |
1867 | 1882 |
1868 @override | 1883 @override |
1869 String computeDocumentationComment() { | 1884 String computeDocumentationComment() => _docComment; |
1870 AnalysisContext context = this.context; | |
1871 if (context == null) { | |
1872 return null; | |
1873 } | |
1874 return context.computeDocumentationComment(this); | |
1875 } | |
1876 | 1885 |
1877 @override | 1886 @override |
1878 AstNode computeNode() => getNodeMatching((node) => node is AstNode); | 1887 AstNode computeNode() => getNodeMatching((node) => node is AstNode); |
1879 | 1888 |
1880 /** | 1889 /** |
1881 * Set this element as the enclosing element for given [element]. | 1890 * Set this element as the enclosing element for given [element]. |
1882 */ | 1891 */ |
1883 void encloseElement(ElementImpl element) { | 1892 void encloseElement(ElementImpl element) { |
1884 element.enclosingElement = this; | 1893 element.enclosingElement = this; |
1885 } | 1894 } |
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3229 } | 3238 } |
3230 | 3239 |
3231 @override | 3240 @override |
3232 List<LibraryElement> get visibleLibraries { | 3241 List<LibraryElement> get visibleLibraries { |
3233 Set<LibraryElement> visibleLibraries = new Set(); | 3242 Set<LibraryElement> visibleLibraries = new Set(); |
3234 _addVisibleLibraries(visibleLibraries, false); | 3243 _addVisibleLibraries(visibleLibraries, false); |
3235 return new List.from(visibleLibraries); | 3244 return new List.from(visibleLibraries); |
3236 } | 3245 } |
3237 | 3246 |
3238 @override | 3247 @override |
3239 bool operator ==(Object object) => object is LibraryElementImpl && | 3248 bool operator ==(Object object) => |
3249 object is LibraryElementImpl && | |
3240 _definingCompilationUnit == object.definingCompilationUnit; | 3250 _definingCompilationUnit == object.definingCompilationUnit; |
3241 | 3251 |
3242 @override | 3252 @override |
3243 accept(ElementVisitor visitor) => visitor.visitLibraryElement(this); | 3253 accept(ElementVisitor visitor) => visitor.visitLibraryElement(this); |
3244 | 3254 |
3245 /** | 3255 /** |
3246 * Create the [FunctionElement] to be returned by [loadLibraryFunction], | 3256 * Create the [FunctionElement] to be returned by [loadLibraryFunction], |
3247 * using types provided by [typeProvider]. | 3257 * using types provided by [typeProvider]. |
3248 */ | 3258 */ |
3249 void createLoadLibraryFunction(TypeProvider typeProvider) { | 3259 void createLoadLibraryFunction(TypeProvider typeProvider) { |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3651 _name = conflictingElements[0].name; | 3661 _name = conflictingElements[0].name; |
3652 } | 3662 } |
3653 | 3663 |
3654 @override | 3664 @override |
3655 String get displayName => _name; | 3665 String get displayName => _name; |
3656 | 3666 |
3657 @override | 3667 @override |
3658 SourceRange get docRange => null; | 3668 SourceRange get docRange => null; |
3659 | 3669 |
3660 @override | 3670 @override |
3671 String get documentationComment => null; | |
3672 | |
3673 @override | |
3661 Element get enclosingElement => null; | 3674 Element get enclosingElement => null; |
3662 | 3675 |
3663 @override | 3676 @override |
3664 bool get isDeprecated => false; | 3677 bool get isDeprecated => false; |
3665 | 3678 |
3666 @override | 3679 @override |
3667 bool get isOverride => false; | 3680 bool get isOverride => false; |
3668 | 3681 |
3669 @override | 3682 @override |
3670 bool get isPrivate { | 3683 bool get isPrivate { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3787 static void _add(HashSet<Element> elements, Element element) { | 3800 static void _add(HashSet<Element> elements, Element element) { |
3788 if (element is MultiplyDefinedElementImpl) { | 3801 if (element is MultiplyDefinedElementImpl) { |
3789 for (Element conflictingElement in element.conflictingElements) { | 3802 for (Element conflictingElement in element.conflictingElements) { |
3790 elements.add(conflictingElement); | 3803 elements.add(conflictingElement); |
3791 } | 3804 } |
3792 } else { | 3805 } else { |
3793 elements.add(element); | 3806 elements.add(element); |
3794 } | 3807 } |
3795 } | 3808 } |
3796 | 3809 |
3810 // TODO: implement documentationComment | |
scheglov
2015/12/17 22:10:14
Did you want to fix this in this CL?
pquitslund
2015/12/17 22:12:56
Whoops! Yes. Thanks!
| |
3797 /** | 3811 /** |
3798 * Use the given elements to construct a list of conflicting elements. If | 3812 * Use the given elements to construct a list of conflicting elements. If |
3799 * either the [firstElement] or [secondElement] are multiply-defined elements | 3813 * either the [firstElement] or [secondElement] are multiply-defined elements |
3800 * then the conflicting elements they represent will be included in the array. | 3814 * then the conflicting elements they represent will be included in the array. |
3801 * Otherwise, the element itself will be included. | 3815 * Otherwise, the element itself will be included. |
3802 */ | 3816 */ |
3803 static List<Element> _computeConflictingElements( | 3817 static List<Element> _computeConflictingElements( |
3804 Element firstElement, Element secondElement) { | 3818 Element firstElement, Element secondElement) { |
3805 HashSet<Element> elements = new HashSet<Element>(); | 3819 HashSet<Element> elements = new HashSet<Element>(); |
3806 _add(elements, firstElement); | 3820 _add(elements, firstElement); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4219 } | 4233 } |
4220 | 4234 |
4221 /** | 4235 /** |
4222 * Set whether this accessor is static. | 4236 * Set whether this accessor is static. |
4223 */ | 4237 */ |
4224 void set static(bool isStatic) { | 4238 void set static(bool isStatic) { |
4225 setModifier(Modifier.STATIC, isStatic); | 4239 setModifier(Modifier.STATIC, isStatic); |
4226 } | 4240 } |
4227 | 4241 |
4228 @override | 4242 @override |
4229 bool operator ==(Object object) => super == object && | 4243 bool operator ==(Object object) => |
4244 super == object && | |
4230 isGetter == (object as PropertyAccessorElement).isGetter; | 4245 isGetter == (object as PropertyAccessorElement).isGetter; |
4231 | 4246 |
4232 @override | 4247 @override |
4233 accept(ElementVisitor visitor) => visitor.visitPropertyAccessorElement(this); | 4248 accept(ElementVisitor visitor) => visitor.visitPropertyAccessorElement(this); |
4234 | 4249 |
4235 @override | 4250 @override |
4236 void appendTo(StringBuffer buffer) { | 4251 void appendTo(StringBuffer buffer) { |
4237 buffer.write(isGetter ? "get " : "set "); | 4252 buffer.write(isGetter ? "get " : "set "); |
4238 buffer.write(variable.displayName); | 4253 buffer.write(variable.displayName); |
4239 super.appendTo(buffer); | 4254 super.appendTo(buffer); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4562 | 4577 |
4563 @override | 4578 @override |
4564 void visitElement(Element element) { | 4579 void visitElement(Element element) { |
4565 int offset = element.nameOffset; | 4580 int offset = element.nameOffset; |
4566 if (offset != -1) { | 4581 if (offset != -1) { |
4567 map[offset] = element; | 4582 map[offset] = element; |
4568 } | 4583 } |
4569 super.visitElement(element); | 4584 super.visitElement(element); |
4570 } | 4585 } |
4571 } | 4586 } |
OLD | NEW |