Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: pkg/analyzer/lib/src/generated/element.dart

Issue 1080503003: Move getElementAt() to CompilationUnitElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.element; 8 library engine.element;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 */ 1206 */
1207 List<TopLevelVariableElement> get topLevelVariables; 1207 List<TopLevelVariableElement> get topLevelVariables;
1208 1208
1209 /** 1209 /**
1210 * Return a list containing all of the classes contained in this compilation 1210 * Return a list containing all of the classes contained in this compilation
1211 * unit. 1211 * unit.
1212 */ 1212 */
1213 List<ClassElement> get types; 1213 List<ClassElement> get types;
1214 1214
1215 /** 1215 /**
1216 * Return the element at the given [offset], maybe `null` if no such element.
1217 */
1218 Element getElementAt(int offset);
1219
1220 /**
1216 * Return the enum defined in this compilation unit that has the given [name], 1221 * Return the enum defined in this compilation unit that has the given [name],
1217 * or `null` if this compilation unit does not define an enum with the given 1222 * or `null` if this compilation unit does not define an enum with the given
1218 * name. 1223 * name.
1219 */ 1224 */
1220 ClassElement getEnum(String name); 1225 ClassElement getEnum(String name);
1221 1226
1222 /** 1227 /**
1223 * Return the class defined in this compilation unit that has the given 1228 * Return the class defined in this compilation unit that has the given
1224 * [name], or `null` if this compilation unit does not define a class with the 1229 * [name], or `null` if this compilation unit does not define a class with the
1225 * given name. 1230 * given name.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 */ 1278 */
1274 List<ClassElement> _types = ClassElementImpl.EMPTY_ARRAY; 1279 List<ClassElement> _types = ClassElementImpl.EMPTY_ARRAY;
1275 1280
1276 /** 1281 /**
1277 * A list containing all of the variables contained in this compilation unit. 1282 * A list containing all of the variables contained in this compilation unit.
1278 */ 1283 */
1279 List<TopLevelVariableElement> _variables = 1284 List<TopLevelVariableElement> _variables =
1280 TopLevelVariableElementImpl.EMPTY_ARRAY; 1285 TopLevelVariableElementImpl.EMPTY_ARRAY;
1281 1286
1282 /** 1287 /**
1288 * A map from offsets to elements of this unit at these offsets.
1289 */
1290 final Map<int, Element> _offsetToElementMap = new HashMap<int, Element>();
1291
1292 /**
1283 * Initialize a newly created compilation unit element to have the given 1293 * Initialize a newly created compilation unit element to have the given
1284 * [name]. 1294 * [name].
1285 */ 1295 */
1286 CompilationUnitElementImpl(String name) : super(name, -1); 1296 CompilationUnitElementImpl(String name) : super(name, -1);
1287 1297
1288 @override 1298 @override
1289 List<PropertyAccessorElement> get accessors => _accessors; 1299 List<PropertyAccessorElement> get accessors => _accessors;
1290 1300
1291 /** 1301 /**
1292 * Set the top-level accessors (getters and setters) contained in this 1302 * Set the top-level accessors (getters and setters) contained in this
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 this._types = types; 1403 this._types = types;
1394 } 1404 }
1395 1405
1396 @override 1406 @override
1397 bool operator ==(Object object) => 1407 bool operator ==(Object object) =>
1398 object is CompilationUnitElementImpl && source == object.source; 1408 object is CompilationUnitElementImpl && source == object.source;
1399 1409
1400 @override 1410 @override
1401 accept(ElementVisitor visitor) => visitor.visitCompilationUnitElement(this); 1411 accept(ElementVisitor visitor) => visitor.visitCompilationUnitElement(this);
1402 1412
1413 /**
1414 * This method is invoked after this unit was incrementally resolved.
1415 */
1416 void afterIncrementalResolution() {
1417 _offsetToElementMap.clear();
1418 }
1419
1403 @override 1420 @override
1404 void appendTo(StringBuffer buffer) { 1421 void appendTo(StringBuffer buffer) {
1405 if (source == null) { 1422 if (source == null) {
1406 buffer.write("{compilation unit}"); 1423 buffer.write("{compilation unit}");
1407 } else { 1424 } else {
1408 buffer.write(source.fullName); 1425 buffer.write(source.fullName);
1409 } 1426 }
1410 } 1427 }
1411 1428
1412 @override 1429 @override
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 } 1461 }
1445 for (ClassElement type in _enums) { 1462 for (ClassElement type in _enums) {
1446 if ((type as ClassElementImpl).identifier == identifier) { 1463 if ((type as ClassElementImpl).identifier == identifier) {
1447 return type as ClassElementImpl; 1464 return type as ClassElementImpl;
1448 } 1465 }
1449 } 1466 }
1450 return null; 1467 return null;
1451 } 1468 }
1452 1469
1453 @override 1470 @override
1471 Element getElementAt(int offset) {
1472 if (_offsetToElementMap.isEmpty) {
1473 accept(new _BuildOffsetToElementMap(_offsetToElementMap));
1474 }
1475 return _offsetToElementMap[offset];
1476 }
1477
1478 @override
1454 ClassElement getEnum(String enumName) { 1479 ClassElement getEnum(String enumName) {
1455 for (ClassElement enumDeclaration in _enums) { 1480 for (ClassElement enumDeclaration in _enums) {
1456 if (enumDeclaration.name == enumName) { 1481 if (enumDeclaration.name == enumName) {
1457 return enumDeclaration; 1482 return enumDeclaration;
1458 } 1483 }
1459 } 1484 }
1460 return null; 1485 return null;
1461 } 1486 }
1462 1487
1463 @override 1488 @override
(...skipping 5295 matching lines...) Expand 10 before | Expand all | Expand 10 after
6759 * the `part` directive. 6784 * the `part` directive.
6760 */ 6785 */
6761 List<CompilationUnitElement> get units; 6786 List<CompilationUnitElement> get units;
6762 6787
6763 /** 6788 /**
6764 * Return a list containing all directly and indirectly imported libraries. 6789 * Return a list containing all directly and indirectly imported libraries.
6765 */ 6790 */
6766 List<LibraryElement> get visibleLibraries; 6791 List<LibraryElement> get visibleLibraries;
6767 6792
6768 /** 6793 /**
6769 * Return the element at the given [offset], maybe `null` if no such element.
6770 */
6771 Element getElementAt(int offset);
6772
6773 /**
6774 * Return a list containing all of the imports that share the given [prefix], 6794 * Return a list containing all of the imports that share the given [prefix],
6775 * or an empty array if there are no such imports. 6795 * or an empty array if there are no such imports.
6776 */ 6796 */
6777 List<ImportElement> getImportsWithPrefix(PrefixElement prefix); 6797 List<ImportElement> getImportsWithPrefix(PrefixElement prefix);
6778 6798
6779 /** 6799 /**
6780 * Return the class defined in this library that has the given [name], or 6800 * Return the class defined in this library that has the given [name], or
6781 * `null` if this library does not define a class with the given name. 6801 * `null` if this library does not define a class with the given name.
6782 */ 6802 */
6783 ClassElement getType(String className); 6803 ClassElement getType(String className);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
6833 */ 6853 */
6834 List<CompilationUnitElement> _parts = CompilationUnitElementImpl.EMPTY_ARRAY; 6854 List<CompilationUnitElement> _parts = CompilationUnitElementImpl.EMPTY_ARRAY;
6835 6855
6836 /** 6856 /**
6837 * The element representing the synthetic function `loadLibrary` that is 6857 * The element representing the synthetic function `loadLibrary` that is
6838 * defined for this library, or `null` if the element has not yet been created . 6858 * defined for this library, or `null` if the element has not yet been created .
6839 */ 6859 */
6840 FunctionElement _loadLibraryFunction; 6860 FunctionElement _loadLibraryFunction;
6841 6861
6842 /** 6862 /**
6843 * A map from offsets to elements of this library at these offsets.
6844 */
6845 final Map<int, Element> _offsetToElementMap = new HashMap<int, Element>();
6846
6847 /**
6848 * The export [Namespace] of this library, `null` if it has not been 6863 * The export [Namespace] of this library, `null` if it has not been
6849 * computed yet. 6864 * computed yet.
6850 */ 6865 */
6851 @override 6866 @override
6852 Namespace exportNamespace; 6867 Namespace exportNamespace;
6853 6868
6854 /** 6869 /**
6855 * The public [Namespace] of this library, `null` if it has not been 6870 * The public [Namespace] of this library, `null` if it has not been
6856 * computed yet. 6871 * computed yet.
6857 */ 6872 */
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
7112 return new List.from(visibleLibraries); 7127 return new List.from(visibleLibraries);
7113 } 7128 }
7114 7129
7115 @override 7130 @override
7116 bool operator ==(Object object) => object is LibraryElementImpl && 7131 bool operator ==(Object object) => object is LibraryElementImpl &&
7117 _definingCompilationUnit == object.definingCompilationUnit; 7132 _definingCompilationUnit == object.definingCompilationUnit;
7118 7133
7119 @override 7134 @override
7120 accept(ElementVisitor visitor) => visitor.visitLibraryElement(this); 7135 accept(ElementVisitor visitor) => visitor.visitLibraryElement(this);
7121 7136
7122 /**
7123 * This method is invoked after this library was incrementally resolved.
7124 */
7125 void afterIncrementalResolution() {
7126 _offsetToElementMap.clear();
7127 }
7128
7129 @override 7137 @override
7130 ElementImpl getChild(String identifier) { 7138 ElementImpl getChild(String identifier) {
7131 if ((_definingCompilationUnit as CompilationUnitElementImpl).identifier == 7139 if ((_definingCompilationUnit as CompilationUnitElementImpl).identifier ==
7132 identifier) { 7140 identifier) {
7133 return _definingCompilationUnit as CompilationUnitElementImpl; 7141 return _definingCompilationUnit as CompilationUnitElementImpl;
7134 } 7142 }
7135 for (CompilationUnitElement part in _parts) { 7143 for (CompilationUnitElement part in _parts) {
7136 if ((part as CompilationUnitElementImpl).identifier == identifier) { 7144 if ((part as CompilationUnitElementImpl).identifier == identifier) {
7137 return part as CompilationUnitElementImpl; 7145 return part as CompilationUnitElementImpl;
7138 } 7146 }
7139 } 7147 }
7140 for (ImportElement importElement in _imports) { 7148 for (ImportElement importElement in _imports) {
7141 if ((importElement as ImportElementImpl).identifier == identifier) { 7149 if ((importElement as ImportElementImpl).identifier == identifier) {
7142 return importElement as ImportElementImpl; 7150 return importElement as ImportElementImpl;
7143 } 7151 }
7144 } 7152 }
7145 for (ExportElement exportElement in _exports) { 7153 for (ExportElement exportElement in _exports) {
7146 if ((exportElement as ExportElementImpl).identifier == identifier) { 7154 if ((exportElement as ExportElementImpl).identifier == identifier) {
7147 return exportElement as ExportElementImpl; 7155 return exportElement as ExportElementImpl;
7148 } 7156 }
7149 } 7157 }
7150 return null; 7158 return null;
7151 } 7159 }
7152 7160
7153 @override 7161 @override
7154 Element getElementAt(int offset) {
7155 if (_offsetToElementMap.isEmpty) {
7156 accept(new _BuildOffsetToElementMap(_offsetToElementMap));
7157 }
7158 return _offsetToElementMap[offset];
7159 }
7160
7161 @override
7162 List<ImportElement> getImportsWithPrefix(PrefixElement prefixElement) { 7162 List<ImportElement> getImportsWithPrefix(PrefixElement prefixElement) {
7163 int count = _imports.length; 7163 int count = _imports.length;
7164 List<ImportElement> importList = new List<ImportElement>(); 7164 List<ImportElement> importList = new List<ImportElement>();
7165 for (int i = 0; i < count; i++) { 7165 for (int i = 0; i < count; i++) {
7166 if (identical(_imports[i].prefix, prefixElement)) { 7166 if (identical(_imports[i].prefix, prefixElement)) {
7167 importList.add(_imports[i]); 7167 importList.add(_imports[i]);
7168 } 7168 }
7169 } 7169 }
7170 return importList; 7170 return importList;
7171 } 7171 }
(...skipping 2969 matching lines...) Expand 10 before | Expand all | Expand 10 after
10141 10141
10142 @override 10142 @override
10143 void visitElement(Element element) { 10143 void visitElement(Element element) {
10144 int offset = element.nameOffset; 10144 int offset = element.nameOffset;
10145 if (offset != -1) { 10145 if (offset != -1) {
10146 map[offset] = element; 10146 map[offset] = element;
10147 } 10147 }
10148 super.visitElement(element); 10148 super.visitElement(element);
10149 } 10149 }
10150 } 10150 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/index/store/codec.dart ('k') | pkg/analyzer/lib/src/generated/element_handle.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698