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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/search.dart

Issue 2534833004: Request SearchResult(s) of multiple kinds at once. (Closed)
Patch Set: Created 4 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/search.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/search.dart b/pkg/analyzer/lib/src/dart/analysis/search.dart
index 2c3448c3d5ca572b5832bb093f3c34118f168a5b..55d28d61cb6d8caa7fe709d7b7727e228aa1f38f 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -69,7 +69,7 @@ class Search {
}
Future<Null> _addResults(List<SearchResult> results, Element element,
- IndexRelationKind relationKind, SearchResultKind resultKind) async {
+ Map<IndexRelationKind, SearchResultKind> relationToResultKind) async {
String path = element.source.fullName;
// If the file with the element is not known, then the element is not used.
@@ -93,8 +93,8 @@ class Search {
int elementId = request.findElementId(element);
if (elementId != -1) {
CompilationUnitElement unitElement = result.unitElement;
- List<SearchResult> fileResults = request.getRelations(
- elementId, relationKind, resultKind, unitElement);
+ List<SearchResult> fileResults =
+ request.getRelations(elementId, relationToResultKind, unitElement);
results.addAll(fileResults);
}
}
@@ -102,8 +102,8 @@ class Search {
Future<List<SearchResult>> _searchReferences(Element element) async {
List<SearchResult> results = <SearchResult>[];
- await _addResults(results, element, IndexRelationKind.IS_REFERENCED_BY,
- SearchResultKind.REFERENCE);
+ await _addResults(results, element,
+ {IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.REFERENCE});
return results;
}
@@ -113,20 +113,20 @@ class Search {
PropertyAccessorElement getter = field.getter;
PropertyAccessorElement setter = field.setter;
if (!field.isSynthetic) {
- await _addResults(results, field, IndexRelationKind.IS_WRITTEN_BY,
- SearchResultKind.WRITE);
- await _addResults(results, field, IndexRelationKind.IS_REFERENCED_BY,
- SearchResultKind.REFERENCE);
+ await _addResults(results, field, {
+ IndexRelationKind.IS_WRITTEN_BY: SearchResultKind.WRITE,
+ IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.REFERENCE
+ });
}
if (getter != null) {
- await _addResults(results, getter, IndexRelationKind.IS_REFERENCED_BY,
- SearchResultKind.READ);
- await _addResults(results, getter, IndexRelationKind.IS_INVOKED_BY,
- SearchResultKind.INVOCATION);
+ await _addResults(results, getter, {
+ IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.READ,
+ IndexRelationKind.IS_INVOKED_BY: SearchResultKind.INVOCATION
+ });
}
if (setter != null) {
- await _addResults(results, setter, IndexRelationKind.IS_REFERENCED_BY,
- SearchResultKind.WRITE);
+ await _addResults(results, setter,
+ {IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.WRITE});
}
return results;
}
@@ -136,20 +136,20 @@ class Search {
element = (element as Member).baseElement;
}
List<SearchResult> results = <SearchResult>[];
- await _addResults(results, element, IndexRelationKind.IS_REFERENCED_BY,
- SearchResultKind.REFERENCE);
- await _addResults(results, element, IndexRelationKind.IS_INVOKED_BY,
- SearchResultKind.INVOCATION);
+ await _addResults(results, element, {
+ IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.REFERENCE,
+ IndexRelationKind.IS_INVOKED_BY: SearchResultKind.INVOCATION
+ });
return results;
}
Future<List<SearchResult>> _searchReferences_Getter(
PropertyAccessorElement getter) async {
List<SearchResult> results = <SearchResult>[];
- await _addResults(results, getter, IndexRelationKind.IS_REFERENCED_BY,
- SearchResultKind.REFERENCE);
- await _addResults(results, getter, IndexRelationKind.IS_INVOKED_BY,
- SearchResultKind.INVOCATION);
+ await _addResults(results, getter, {
+ IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.REFERENCE,
+ IndexRelationKind.IS_INVOKED_BY: SearchResultKind.INVOCATION
+ });
return results;
}
@@ -377,12 +377,11 @@ class _IndexRequest {
/**
* Return a list of results where an element with the given [elementId] has
- * relation of the given [indexKind].
+ * a relation with the kind from [relationToResultKind].
*/
List<SearchResult> getRelations(
int elementId,
- IndexRelationKind indexKind,
- SearchResultKind searchKind,
+ Map<IndexRelationKind, SearchResultKind> relationToResultKind,
CompilationUnitElement enclosingUnitElement) {
// Find the first usage of the element.
int i = _findFirstOccurrence(index.usedElements, elementId);
@@ -394,14 +393,16 @@ class _IndexRequest {
for (;
i < index.usedElements.length && index.usedElements[i] == elementId;
i++) {
- if (index.usedElementKinds[i] == indexKind) {
+ IndexRelationKind relationKind = index.usedElementKinds[i];
+ SearchResultKind resultKind = relationToResultKind[relationKind];
+ if (resultKind != null) {
int offset = index.usedElementOffsets[i];
Element enclosingElement =
_getEnclosingElement(enclosingUnitElement, offset);
results.add(new SearchResult._(
null,
enclosingElement,
- searchKind,
+ resultKind,
offset,
index.usedElementLengths[i],
true,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698