| 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'; |
| 11 import 'package:analyzer/dart/ast/token.dart'; | 11 import 'package:analyzer/dart/ast/token.dart'; |
| 12 import 'package:analyzer/dart/constant/value.dart'; | 12 import 'package:analyzer/dart/constant/value.dart'; |
| 13 import 'package:analyzer/dart/element/element.dart'; | 13 import 'package:analyzer/dart/element/element.dart'; |
| 14 import 'package:analyzer/dart/element/type.dart'; | 14 import 'package:analyzer/dart/element/type.dart'; |
| 15 import 'package:analyzer/dart/element/visitor.dart'; | |
| 16 import 'package:analyzer/src/dart/ast/utilities.dart'; | 15 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 17 import 'package:analyzer/src/dart/constant/value.dart'; | 16 import 'package:analyzer/src/dart/constant/value.dart'; |
| 18 import 'package:analyzer/src/dart/element/handle.dart'; | 17 import 'package:analyzer/src/dart/element/handle.dart'; |
| 19 import 'package:analyzer/src/dart/element/type.dart'; | 18 import 'package:analyzer/src/dart/element/type.dart'; |
| 20 import 'package:analyzer/src/error/codes.dart' show CompileTimeErrorCode; | 19 import 'package:analyzer/src/error/codes.dart' show CompileTimeErrorCode; |
| 21 import 'package:analyzer/src/generated/constant.dart' show EvaluationResultImpl; | 20 import 'package:analyzer/src/generated/constant.dart' show EvaluationResultImpl; |
| 22 import 'package:analyzer/src/generated/engine.dart' | 21 import 'package:analyzer/src/generated/engine.dart' |
| 23 show AnalysisContext, AnalysisEngine; | 22 show AnalysisContext, AnalysisEngine; |
| 24 import 'package:analyzer/src/generated/java_engine.dart'; | 23 import 'package:analyzer/src/generated/java_engine.dart'; |
| 25 import 'package:analyzer/src/generated/resolver.dart'; | 24 import 'package:analyzer/src/generated/resolver.dart'; |
| (...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 * A list containing all of the types contained in this compilation unit. | 1328 * A list containing all of the types contained in this compilation unit. |
| 1330 */ | 1329 */ |
| 1331 List<ClassElement> _types; | 1330 List<ClassElement> _types; |
| 1332 | 1331 |
| 1333 /** | 1332 /** |
| 1334 * A list containing all of the variables contained in this compilation unit. | 1333 * A list containing all of the variables contained in this compilation unit. |
| 1335 */ | 1334 */ |
| 1336 List<TopLevelVariableElement> _variables; | 1335 List<TopLevelVariableElement> _variables; |
| 1337 | 1336 |
| 1338 /** | 1337 /** |
| 1339 * A map from offsets to elements of this unit at these offsets. | |
| 1340 */ | |
| 1341 final Map<int, Element> _offsetToElementMap = new HashMap<int, Element>(); | |
| 1342 | |
| 1343 /** | |
| 1344 * Resynthesized explicit top-level property accessors. | 1338 * Resynthesized explicit top-level property accessors. |
| 1345 */ | 1339 */ |
| 1346 UnitExplicitTopLevelAccessors _explicitTopLevelAccessors; | 1340 UnitExplicitTopLevelAccessors _explicitTopLevelAccessors; |
| 1347 | 1341 |
| 1348 /** | 1342 /** |
| 1349 * Resynthesized explicit top-level variables. | 1343 * Resynthesized explicit top-level variables. |
| 1350 */ | 1344 */ |
| 1351 UnitExplicitTopLevelVariables _explicitTopLevelVariables; | 1345 UnitExplicitTopLevelVariables _explicitTopLevelVariables; |
| 1352 | 1346 |
| 1353 /** | 1347 /** |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1607 } | 1601 } |
| 1608 | 1602 |
| 1609 @override | 1603 @override |
| 1610 bool operator ==(Object object) => | 1604 bool operator ==(Object object) => |
| 1611 object is CompilationUnitElementImpl && source == object.source; | 1605 object is CompilationUnitElementImpl && source == object.source; |
| 1612 | 1606 |
| 1613 @override | 1607 @override |
| 1614 T accept<T>(ElementVisitor<T> visitor) => | 1608 T accept<T>(ElementVisitor<T> visitor) => |
| 1615 visitor.visitCompilationUnitElement(this); | 1609 visitor.visitCompilationUnitElement(this); |
| 1616 | 1610 |
| 1617 /** | |
| 1618 * This method is invoked after this unit was incrementally resolved. | |
| 1619 */ | |
| 1620 void afterIncrementalResolution() { | |
| 1621 _offsetToElementMap.clear(); | |
| 1622 } | |
| 1623 | |
| 1624 @override | 1611 @override |
| 1625 void appendTo(StringBuffer buffer) { | 1612 void appendTo(StringBuffer buffer) { |
| 1626 if (source == null) { | 1613 if (source == null) { |
| 1627 buffer.write("{compilation unit}"); | 1614 buffer.write("{compilation unit}"); |
| 1628 } else { | 1615 } else { |
| 1629 buffer.write(source.fullName); | 1616 buffer.write(source.fullName); |
| 1630 } | 1617 } |
| 1631 } | 1618 } |
| 1632 | 1619 |
| 1633 @override | 1620 @override |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1685 for (ClassElement type in _enums) { | 1672 for (ClassElement type in _enums) { |
| 1686 EnumElementImpl typeImpl = type; | 1673 EnumElementImpl typeImpl = type; |
| 1687 if (typeImpl.identifier == identifier) { | 1674 if (typeImpl.identifier == identifier) { |
| 1688 return typeImpl; | 1675 return typeImpl; |
| 1689 } | 1676 } |
| 1690 } | 1677 } |
| 1691 return null; | 1678 return null; |
| 1692 } | 1679 } |
| 1693 | 1680 |
| 1694 @override | 1681 @override |
| 1695 Element getElementAt(int offset) { | |
| 1696 if (_offsetToElementMap.isEmpty) { | |
| 1697 accept(new _BuildOffsetToElementMap(_offsetToElementMap)); | |
| 1698 } | |
| 1699 return _offsetToElementMap[offset]; | |
| 1700 } | |
| 1701 | |
| 1702 @override | |
| 1703 ClassElement getEnum(String enumName) { | 1682 ClassElement getEnum(String enumName) { |
| 1704 for (ClassElement enumDeclaration in _enums) { | 1683 for (ClassElement enumDeclaration in _enums) { |
| 1705 if (enumDeclaration.name == enumName) { | 1684 if (enumDeclaration.name == enumName) { |
| 1706 return enumDeclaration; | 1685 return enumDeclaration; |
| 1707 } | 1686 } |
| 1708 } | 1687 } |
| 1709 return null; | 1688 return null; |
| 1710 } | 1689 } |
| 1711 | 1690 |
| 1712 @override | 1691 @override |
| (...skipping 7349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9062 | 9041 |
| 9063 @override | 9042 @override |
| 9064 DartObject computeConstantValue() => null; | 9043 DartObject computeConstantValue() => null; |
| 9065 | 9044 |
| 9066 @override | 9045 @override |
| 9067 void visitChildren(ElementVisitor visitor) { | 9046 void visitChildren(ElementVisitor visitor) { |
| 9068 super.visitChildren(visitor); | 9047 super.visitChildren(visitor); |
| 9069 _initializer?.accept(visitor); | 9048 _initializer?.accept(visitor); |
| 9070 } | 9049 } |
| 9071 } | 9050 } |
| 9072 | |
| 9073 /** | |
| 9074 * A visitor that visit all the elements recursively and fill the given [map]. | |
| 9075 */ | |
| 9076 class _BuildOffsetToElementMap extends GeneralizingElementVisitor { | |
| 9077 final Map<int, Element> map; | |
| 9078 | |
| 9079 _BuildOffsetToElementMap(this.map); | |
| 9080 | |
| 9081 @override | |
| 9082 void visitElement(Element element) { | |
| 9083 int offset = element.nameOffset; | |
| 9084 if (offset != -1) { | |
| 9085 map[offset] = element; | |
| 9086 } | |
| 9087 super.visitElement(element); | |
| 9088 } | |
| 9089 } | |
| OLD | NEW |