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

Unified Diff: pkg/analyzer/lib/src/generated/element.dart

Issue 1075773002: Use file/offset/kind triplet as elements id. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks for review comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/test/services/index/store/split_store_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/element.dart
diff --git a/pkg/analyzer/lib/src/generated/element.dart b/pkg/analyzer/lib/src/generated/element.dart
index c7edef65554253e71bf95f659b6810e2bd447674..d2f11b6faf70fa4ab38996fb7741abb01943383f 100644
--- a/pkg/analyzer/lib/src/generated/element.dart
+++ b/pkg/analyzer/lib/src/generated/element.dart
@@ -6766,6 +6766,11 @@ abstract class LibraryElement implements Element {
List<LibraryElement> get visibleLibraries;
/**
+ * Return the element at the given [offset], maybe `null` if no such element.
+ */
+ Element getElementAt(int offset);
+
+ /**
* Return a list containing all of the imports that share the given [prefix],
* or an empty array if there are no such imports.
*/
@@ -6835,6 +6840,11 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
FunctionElement _loadLibraryFunction;
/**
+ * A map from offsets to elements of this library at these offsets.
+ */
+ final Map<int, Element> _elementMap = new HashMap<int, Element>();
+
+ /**
* The export [Namespace] of this library, `null` if it has not been
* computed yet.
*/
@@ -7134,6 +7144,14 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
}
@override
+ Element getElementAt(int offset) {
+ if (_elementMap.isEmpty) {
+ accept(new _BuildOffsetToElementMap(_elementMap));
+ }
+ return _elementMap[offset];
+ }
+
+ @override
List<ImportElement> getImportsWithPrefix(PrefixElement prefixElement) {
int count = _imports.length;
List<ImportElement> importList = new List<ImportElement>();
@@ -10105,3 +10123,21 @@ class VoidTypeImpl extends TypeImpl implements VoidType {
VoidTypeImpl substitute2(
List<DartType> argumentTypes, List<DartType> parameterTypes) => this;
}
+
+/**
+ * A visitor that visit all the elements recursively and fill the given [map].
+ */
+class _BuildOffsetToElementMap extends GeneralizingElementVisitor {
+ final Map<int, Element> map;
+
+ _BuildOffsetToElementMap(this.map);
+
+ @override
+ void visitElement(Element element) {
+ int offset = element.nameOffset;
+ if (offset != -1) {
+ map[offset] = element;
+ }
+ super.visitElement(element);
+ }
+}
« no previous file with comments | « pkg/analysis_server/test/services/index/store/split_store_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698