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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 | 463 |
464 /** | 464 /** |
465 * A list containing all of the methods contained in this class. | 465 * A list containing all of the methods contained in this class. |
466 */ | 466 */ |
467 List<MethodElement> _methods; | 467 List<MethodElement> _methods; |
468 | 468 |
469 /** | 469 /** |
470 * A flag indicating whether the types associated with the instance members of | 470 * A flag indicating whether the types associated with the instance members of |
471 * this class have been inferred. | 471 * this class have been inferred. |
472 */ | 472 */ |
473 bool hasBeenInferred = false; | 473 bool _hasBeenInferred = false; |
474 | 474 |
475 /** | 475 /** |
476 * Initialize a newly created class element to have the given [name] at the | 476 * Initialize a newly created class element to have the given [name] at the |
477 * given [offset] in the file that contains the declaration of this element. | 477 * given [offset] in the file that contains the declaration of this element. |
478 */ | 478 */ |
479 ClassElementImpl(String name, int offset) | 479 ClassElementImpl(String name, int offset) |
480 : _unlinkedClass = null, | 480 : _unlinkedClass = null, |
481 super(name, offset); | 481 super(name, offset); |
482 | 482 |
483 /** | 483 /** |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 } | 649 } |
650 return _fields ?? const <FieldElement>[]; | 650 return _fields ?? const <FieldElement>[]; |
651 } | 651 } |
652 | 652 |
653 @override | 653 @override |
654 void set fields(List<FieldElement> fields) { | 654 void set fields(List<FieldElement> fields) { |
655 assert(_unlinkedClass == null); | 655 assert(_unlinkedClass == null); |
656 super.fields = fields; | 656 super.fields = fields; |
657 } | 657 } |
658 | 658 |
| 659 bool get hasBeenInferred { |
| 660 if (_unlinkedClass != null) { |
| 661 return context.analysisOptions.strongMode; |
| 662 } |
| 663 return _hasBeenInferred; |
| 664 } |
| 665 |
| 666 void set hasBeenInferred(bool hasBeenInferred) { |
| 667 assert(_unlinkedClass == null); |
| 668 _hasBeenInferred = hasBeenInferred; |
| 669 } |
| 670 |
659 @override | 671 @override |
660 bool get hasNonFinalField { | 672 bool get hasNonFinalField { |
661 List<ClassElement> classesToVisit = new List<ClassElement>(); | 673 List<ClassElement> classesToVisit = new List<ClassElement>(); |
662 HashSet<ClassElement> visitedClasses = new HashSet<ClassElement>(); | 674 HashSet<ClassElement> visitedClasses = new HashSet<ClassElement>(); |
663 classesToVisit.add(this); | 675 classesToVisit.add(this); |
664 while (!classesToVisit.isEmpty) { | 676 while (!classesToVisit.isEmpty) { |
665 ClassElement currentElement = classesToVisit.removeAt(0); | 677 ClassElement currentElement = classesToVisit.removeAt(0); |
666 if (visitedClasses.add(currentElement)) { | 678 if (visitedClasses.add(currentElement)) { |
667 // check fields | 679 // check fields |
668 for (FieldElement field in currentElement.fields) { | 680 for (FieldElement field in currentElement.fields) { |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 | 1332 |
1321 /** | 1333 /** |
1322 * A list containing all of the function type aliases contained in this | 1334 * A list containing all of the function type aliases contained in this |
1323 * compilation unit. | 1335 * compilation unit. |
1324 */ | 1336 */ |
1325 List<FunctionTypeAliasElement> _typeAliases; | 1337 List<FunctionTypeAliasElement> _typeAliases; |
1326 | 1338 |
1327 /** | 1339 /** |
1328 * A list containing all of the types contained in this compilation unit. | 1340 * A list containing all of the types contained in this compilation unit. |
1329 */ | 1341 */ |
1330 List<ClassElement> _types = ClassElement.EMPTY_LIST; | 1342 List<ClassElement> _types; |
1331 | 1343 |
1332 /** | 1344 /** |
1333 * A list containing all of the variables contained in this compilation unit. | 1345 * A list containing all of the variables contained in this compilation unit. |
1334 */ | 1346 */ |
1335 List<TopLevelVariableElement> _variables; | 1347 List<TopLevelVariableElement> _variables; |
1336 | 1348 |
1337 /** | 1349 /** |
1338 * A map from offsets to elements of this unit at these offsets. | 1350 * A map from offsets to elements of this unit at these offsets. |
1339 */ | 1351 */ |
1340 final Map<int, Element> _offsetToElementMap = new HashMap<int, Element>(); | 1352 final Map<int, Element> _offsetToElementMap = new HashMap<int, Element>(); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 for (FunctionTypeAliasElement typeAlias in typeAliases) { | 1572 for (FunctionTypeAliasElement typeAlias in typeAliases) { |
1561 (typeAlias as FunctionTypeAliasElementImpl).enclosingElement = this; | 1573 (typeAlias as FunctionTypeAliasElementImpl).enclosingElement = this; |
1562 } | 1574 } |
1563 this._typeAliases = typeAliases; | 1575 this._typeAliases = typeAliases; |
1564 } | 1576 } |
1565 | 1577 |
1566 @override | 1578 @override |
1567 TypeParameterizedElementMixin get typeParameterContext => null; | 1579 TypeParameterizedElementMixin get typeParameterContext => null; |
1568 | 1580 |
1569 @override | 1581 @override |
1570 List<ClassElement> get types => _types; | 1582 List<ClassElement> get types { |
| 1583 if (_unlinkedUnit != null) { |
| 1584 _types ??= _unlinkedUnit.classes |
| 1585 .map((c) => new ClassElementImpl.forSerialized(c, this)) |
| 1586 .toList(growable: false); |
| 1587 } |
| 1588 return _types ?? const <ClassElement>[]; |
| 1589 } |
1571 | 1590 |
1572 /** | 1591 /** |
1573 * Set the types contained in this compilation unit to the given [types]. | 1592 * Set the types contained in this compilation unit to the given [types]. |
1574 */ | 1593 */ |
1575 void set types(List<ClassElement> types) { | 1594 void set types(List<ClassElement> types) { |
| 1595 assert(_unlinkedUnit == null); |
1576 for (ClassElement type in types) { | 1596 for (ClassElement type in types) { |
1577 // Another implementation of ClassElement is _DeferredClassElement, | 1597 // Another implementation of ClassElement is _DeferredClassElement, |
1578 // which is used to resynthesize classes lazily. We cannot cast it | 1598 // which is used to resynthesize classes lazily. We cannot cast it |
1579 // to ClassElementImpl, and it already can provide correct values of the | 1599 // to ClassElementImpl, and it already can provide correct values of the |
1580 // 'enclosingElement' property. | 1600 // 'enclosingElement' property. |
1581 if (type is ClassElementImpl) { | 1601 if (type is ClassElementImpl) { |
1582 type.enclosingElement = this; | 1602 type.enclosingElement = this; |
1583 } | 1603 } |
1584 } | 1604 } |
1585 this._types = types; | 1605 this._types = types; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 if (variableImpl.identifier == identifier) { | 1661 if (variableImpl.identifier == identifier) { |
1642 return variableImpl; | 1662 return variableImpl; |
1643 } | 1663 } |
1644 } | 1664 } |
1645 for (FunctionElement function in functions) { | 1665 for (FunctionElement function in functions) { |
1646 FunctionElementImpl functionImpl = function; | 1666 FunctionElementImpl functionImpl = function; |
1647 if (functionImpl.identifier == identifier) { | 1667 if (functionImpl.identifier == identifier) { |
1648 return functionImpl; | 1668 return functionImpl; |
1649 } | 1669 } |
1650 } | 1670 } |
1651 for (FunctionTypeAliasElement typeAlias in _typeAliases) { | 1671 for (FunctionTypeAliasElement typeAlias in functionTypeAliases) { |
1652 FunctionTypeAliasElementImpl typeAliasImpl = typeAlias; | 1672 FunctionTypeAliasElementImpl typeAliasImpl = typeAlias; |
1653 if (typeAliasImpl.identifier == identifier) { | 1673 if (typeAliasImpl.identifier == identifier) { |
1654 return typeAliasImpl; | 1674 return typeAliasImpl; |
1655 } | 1675 } |
1656 } | 1676 } |
1657 for (ClassElement type in _types) { | 1677 for (ClassElement type in types) { |
1658 ClassElementImpl typeImpl = type; | 1678 ClassElementImpl typeImpl = type; |
1659 if (typeImpl.name == identifier) { | 1679 if (typeImpl.name == identifier) { |
1660 return typeImpl; | 1680 return typeImpl; |
1661 } | 1681 } |
1662 } | 1682 } |
1663 for (ClassElement type in _enums) { | 1683 for (ClassElement type in _enums) { |
1664 EnumElementImpl typeImpl = type; | 1684 EnumElementImpl typeImpl = type; |
1665 if (typeImpl.identifier == identifier) { | 1685 if (typeImpl.identifier == identifier) { |
1666 return typeImpl; | 1686 return typeImpl; |
1667 } | 1687 } |
(...skipping 14 matching lines...) Expand all Loading... |
1682 for (ClassElement enumDeclaration in _enums) { | 1702 for (ClassElement enumDeclaration in _enums) { |
1683 if (enumDeclaration.name == enumName) { | 1703 if (enumDeclaration.name == enumName) { |
1684 return enumDeclaration; | 1704 return enumDeclaration; |
1685 } | 1705 } |
1686 } | 1706 } |
1687 return null; | 1707 return null; |
1688 } | 1708 } |
1689 | 1709 |
1690 @override | 1710 @override |
1691 ClassElement getType(String className) { | 1711 ClassElement getType(String className) { |
1692 for (ClassElement type in _types) { | 1712 for (ClassElement type in types) { |
1693 if (type.name == className) { | 1713 if (type.name == className) { |
1694 return type; | 1714 return type; |
1695 } | 1715 } |
1696 } | 1716 } |
1697 return null; | 1717 return null; |
1698 } | 1718 } |
1699 | 1719 |
1700 /** | 1720 /** |
1701 * Replace the given [from] top-level variable with [to] in this compilation u
nit. | 1721 * Replace the given [from] top-level variable with [to] in this compilation u
nit. |
1702 */ | 1722 */ |
(...skipping 20 matching lines...) Expand all Loading... |
1723 annotationMap ??= new HashMap<int, List<ElementAnnotation>>(); | 1743 annotationMap ??= new HashMap<int, List<ElementAnnotation>>(); |
1724 annotationMap[offset] = annotations; | 1744 annotationMap[offset] = annotations; |
1725 } | 1745 } |
1726 | 1746 |
1727 @override | 1747 @override |
1728 void visitChildren(ElementVisitor visitor) { | 1748 void visitChildren(ElementVisitor visitor) { |
1729 super.visitChildren(visitor); | 1749 super.visitChildren(visitor); |
1730 safelyVisitChildren(accessors, visitor); | 1750 safelyVisitChildren(accessors, visitor); |
1731 safelyVisitChildren(_enums, visitor); | 1751 safelyVisitChildren(_enums, visitor); |
1732 safelyVisitChildren(functions, visitor); | 1752 safelyVisitChildren(functions, visitor); |
1733 safelyVisitChildren(_typeAliases, visitor); | 1753 safelyVisitChildren(functionTypeAliases, visitor); |
1734 safelyVisitChildren(_types, visitor); | 1754 safelyVisitChildren(types, visitor); |
1735 safelyVisitChildren(topLevelVariables, visitor); | 1755 safelyVisitChildren(topLevelVariables, visitor); |
1736 } | 1756 } |
1737 } | 1757 } |
1738 | 1758 |
1739 /** | 1759 /** |
1740 * A [FieldElement] for a 'const' or 'final' field that has an initializer. | 1760 * A [FieldElement] for a 'const' or 'final' field that has an initializer. |
1741 * | 1761 * |
1742 * TODO(paulberry): we should rename this class to reflect the fact that it's | 1762 * TODO(paulberry): we should rename this class to reflect the fact that it's |
1743 * used for both const and final fields. However, we shouldn't do so until | 1763 * used for both const and final fields. However, we shouldn't do so until |
1744 * we've created an API for reading the values of constants; until that API is | 1764 * we've created an API for reading the values of constants; until that API is |
(...skipping 6471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8216 | 8236 |
8217 @override | 8237 @override |
8218 void visitElement(Element element) { | 8238 void visitElement(Element element) { |
8219 int offset = element.nameOffset; | 8239 int offset = element.nameOffset; |
8220 if (offset != -1) { | 8240 if (offset != -1) { |
8221 map[offset] = element; | 8241 map[offset] = element; |
8222 } | 8242 } |
8223 super.visitElement(element); | 8243 super.visitElement(element); |
8224 } | 8244 } |
8225 } | 8245 } |
OLD | NEW |