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

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

Issue 894853004: Support for inspecting index. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
Index: pkg/analysis_server/lib/src/services/index/store/split_store.dart
diff --git a/pkg/analysis_server/lib/src/services/index/store/split_store.dart b/pkg/analysis_server/lib/src/services/index/store/split_store.dart
index d16d29a5b998cddab709f69030e8589069437060..fc1ca31616d9a87571296627fddb1db75f9af3d2 100644
--- a/pkg/analysis_server/lib/src/services/index/store/split_store.dart
+++ b/pkg/analysis_server/lib/src/services/index/store/split_store.dart
@@ -34,6 +34,11 @@ abstract class FileManager {
void delete(String name);
/**
+ * Returns names of all known nodes.
+ */
+ List<String> inspect_getAllNodeNames();
+
+ /**
* Read the entire file contents as a list of bytes.
*/
Future<List<int>> read(String name);
@@ -89,6 +94,13 @@ class FileNodeManager implements NodeManager {
});
}
+ /**
+ * Returns names of all known nodes.
+ */
+ List<String> inspect_getAllNodeNames() {
+ return _fileManager.inspect_getAllNodeNames();
+ }
+
@override
IndexNode newNode(AnalysisContext context) =>
new IndexNode(context, elementCodec, _relationshipCodec);
@@ -280,6 +292,32 @@ class IndexNode {
}
/**
+ * Returns [InspectLocation]s for the element with the given ID.
+ */
+ List<InspectLocation> inspect_getRelations(String name, int elementId) {
+ List<InspectLocation> result = <InspectLocation>[];
+ _relations.forEach((RelationKeyData key, locations) {
+ if (key.elementId == elementId) {
+ for (LocationData location in locations) {
+ Relationship relationship =
+ _relationshipCodec.decode(key.relationshipId);
+ List<String> path =
+ _elementCodec.inspect_decodePath(location.elementId);
+ result.add(
+ new InspectLocation(
+ name,
+ relationship,
+ path,
+ location.offset,
+ location.length,
+ location.flags));
+ }
+ }
+ });
+ return result;
+ }
+
+ /**
* Records that the given [element] and [location] have the given [relationship].
*
* [element] - the [Element] that is related to the location.
@@ -305,6 +343,19 @@ class IndexNode {
}
+class InspectLocation {
+ final String nodeName;
+ final Relationship relationship;
+ final List<String> path;
+ final int offset;
+ final int length;
+ final int flags;
+
+ InspectLocation(this.nodeName, this.relationship, this.path, this.offset,
+ this.length, this.flags);
+}
+
+
/**
* A container with information about a [Location].
*/
@@ -681,6 +732,45 @@ class SplitIndexStore implements IndexStore {
});
}
+ /**
+ * Returns all relations with [Element]s with the given [name].
+ */
+ Future<Map<List<String>, List<InspectLocation>>>
+ inspect_getElementRelations(String name) {
+ Map<List<String>, List<InspectLocation>> result = <List<String>,
+ List<InspectLocation>>{};
+ // prepare elements
+ Map<int, List<String>> elementMap = _elementCodec.inspect_getElements(name);
+ // prepare relations with each element
+ List<Future> futures = <Future>[];
+ if (_nodeManager is FileNodeManager) {
+ List<String> nodeNames =
+ (_nodeManager as FileNodeManager).inspect_getAllNodeNames();
+ nodeNames.forEach((nodeName) {
+ Future<IndexNode> nodeFuture = _nodeManager.getNode(nodeName);
+ Future relationsFuture = nodeFuture.then((node) {
+ if (node != null) {
+ elementMap.forEach((int elementId, List<String> elementPath) {
+ List<InspectLocation> relations =
+ node.inspect_getRelations(nodeName, elementId);
+ List<InspectLocation> resultLocations = result[elementPath];
+ if (resultLocations == null) {
+ resultLocations = <InspectLocation>[];
+ result[elementPath] = resultLocations;
+ }
+ resultLocations.addAll(relations);
+ });
+ }
+ });
+ futures.add(relationsFuture);
+ });
+ }
+ // wait for all nodex
+ return Future.wait(futures).then((_) {
+ return result;
+ });
+ }
+
@override
void recordRelationship(Element element, Relationship relationship,
Location location) {

Powered by Google App Engine
This is Rietveld 408576698