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

Unified Diff: pkg/analysis_server/lib/src/services/index/store/codec.dart

Issue 703963002: Use Element's source paths instead of URIs as a key in the index. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | « no previous file | pkg/analysis_server/lib/src/services/index/store/split_store.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/index/store/codec.dart
diff --git a/pkg/analysis_server/lib/src/services/index/store/codec.dart b/pkg/analysis_server/lib/src/services/index/store/codec.dart
index 603013445d947b71d11e2ef643fab5b5e75a8709..ec2bb94bd11ec12e2448fb7f3b5c4e3984ef2886 100644
--- a/pkg/analysis_server/lib/src/services/index/store/codec.dart
+++ b/pkg/analysis_server/lib/src/services/index/store/codec.dart
@@ -10,6 +10,7 @@ import 'package:analysis_server/src/services/index/index.dart';
import 'package:analysis_server/src/services/index/store/collection.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/engine.dart';
+import 'package:analyzer/src/generated/source.dart';
/**
@@ -98,9 +99,12 @@ class ElementCodec {
/**
* Returns a unique integer that corresponds to the given [Element].
+ *
+ * If [forKey] is `true` then [element] is a part of a key, so it should use
+ * file paths instead of [Element] location URIs.
*/
- int encode(Element element) {
- List<int> path = _getLocationPath(element);
+ int encode(Element element, bool forKey) {
+ List<int> path = _getLocationPath(element, forKey);
int index = _pathToIndex[path];
if (index == null) {
index = _indexToPath.length;
@@ -111,7 +115,7 @@ class ElementCodec {
}
/**
- * Returns an integer that corresponds to an approximated location of the given {@link Element}.
+ * Returns an integer that corresponds to an approximated location of [element].
*/
int encodeHash(Element element) {
List<int> path = _getLocationPathLimited(element);
@@ -139,8 +143,22 @@ class ElementCodec {
return components;
}
- List<int> _getLocationPath(Element element) {
+ /**
+ * If [usePath] is `true` then [Source] path should be used instead of URI.
+ */
+ List<int> _getLocationPath(Element element, bool usePath) {
+ // prepare the location components
List<String> components = element.location.components;
+ if (usePath) {
+ LibraryElement library = element.library;
+ if (library != null) {
+ components[0] = library.source.fullName;
+ if (element.enclosingElement is CompilationUnitElement) {
+ components[1] = library.definingCompilationUnit.source.fullName;
+ }
+ }
+ }
+ // encode the location
int length = components.length;
if (_hasLocalOffset(components)) {
List<int> path = new List<int>();
@@ -167,20 +185,33 @@ class ElementCodec {
}
/**
- * Returns an approximation of the given {@link Element}'s location.
+ * Returns an approximation of the [element]'s location.
*/
List<int> _getLocationPathLimited(Element element) {
- List<String> components = element.location.components;
- int length = components.length;
- String firstComponent = components[0];
- String lastComponent = components[length - 1];
- lastComponent = _substringBeforeAt(lastComponent);
+ String firstComponent;
+ {
+ LibraryElement libraryElement = element.library;
+ if (libraryElement != null) {
+ firstComponent = libraryElement.source.fullName;
+ } else {
+ firstComponent = 'null';
+ }
+ }
+ String lastComponent = element.displayName;
int firstId = _stringCodec.encode(firstComponent);
int lastId = _stringCodec.encode(lastComponent);
return <int>[firstId, lastId];
}
- bool _hasLocalOffset(List<String> components) {
+ static String _getComponentUnit(Element element) {
+ LibraryElement libraryElement = element.library;
+ if (libraryElement == null) {
+ return 'null';
+ }
+ return libraryElement.definingCompilationUnit.source.fullName;
+ }
+
+ static bool _hasLocalOffset(List<String> components) {
for (String component in components) {
if (component.indexOf('@') != -1) {
return true;
@@ -189,7 +220,7 @@ class ElementCodec {
return false;
}
- String _substringBeforeAt(String str) {
+ static String _substringBeforeAt(String str) {
int atOffset = str.indexOf('@');
if (atOffset != -1) {
str = str.substring(0, atOffset);
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/index/store/split_store.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698