Chromium Code Reviews| 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 d9e81188767a150b68e307582a869b792be30e70..c6e9332aa125c041494db845889671266f094703 100644 |
| --- a/pkg/analyzer/lib/src/dart/analysis/search.dart |
| +++ b/pkg/analyzer/lib/src/dart/analysis/search.dart |
| @@ -142,6 +142,40 @@ class Search { |
| return elements; |
| } |
| + /** |
| + * Returns unresolved references to the given [name]. |
| + */ |
| + Future<List<SearchResult>> unresolvedMemberReferences(String name) async { |
| + if (name == null) { |
| + return const <SearchResult>[]; |
| + } |
| + |
| + // Prepare the list of files that reference the name. |
| + List<String> files = await _driver.getFilesReferencingName(name); |
| + |
| + // Check the index of every file that references the element name. |
| + List<SearchResult> results = []; |
| + for (String file in files) { |
| + AnalysisDriverUnitIndex index = await _driver.getIndex(file); |
| + _IndexRequest request = new _IndexRequest(index); |
| + var fileResults = await request.getUnresolvedMemberReferences( |
| + name, |
| + const { |
| + IndexRelationKind.IS_READ_BY: SearchResultKind.READ, |
| + IndexRelationKind.IS_WRITTEN_BY: SearchResultKind.WRITE, |
| + IndexRelationKind.IS_READ_WRITTEN_BY: SearchResultKind.READ_WRITE, |
| + IndexRelationKind.IS_INVOKED_BY: SearchResultKind.INVOCATION |
| + }, |
| + () => _driver.getUnitElement(file)); |
| + results.addAll(fileResults); |
| +// await _addResultsInFile(results, element, relationToResultKind, file); |
|
Brian Wilkerson
2017/01/23 21:31:12
Remove?
|
| + } |
| + |
| + return results; |
| + |
| + // TODO(scheglov) |
| + } |
| + |
| Future<Null> _addResults(List<SearchResult> results, Element element, |
| Map<IndexRelationKind, SearchResultKind> relationToResultKind) async { |
| // Prepare the element name. |
| @@ -704,6 +738,45 @@ class _IndexRequest { |
| } |
| /** |
| + * Return a list of results where a class members with the given [name] is |
| + * referenced with a qualifier, but is not resolved. |
| + */ |
| + Future<List<SearchResult>> getUnresolvedMemberReferences( |
| + String name, |
| + Map<IndexRelationKind, SearchResultKind> relationToResultKind, |
| + Future<CompilationUnitElement> getEnclosingUnitElement()) async { |
| + // Find the name identifier. |
| + int nameId = getStringId(name); |
| + if (nameId == -1) { |
| + return const <SearchResult>[]; |
| + } |
| + |
| + // Find the first usage of the name. |
| + int i = _findFirstOccurrence(index.usedNames, nameId); |
| + if (i == -1) { |
| + return const <SearchResult>[]; |
| + } |
| + |
| + // Create results for every usage of the name. |
| + List<SearchResult> results = <SearchResult>[]; |
| + CompilationUnitElement enclosingUnitElement = null; |
| + for (; i < index.usedNames.length && index.usedNames[i] == nameId; i++) { |
| + IndexRelationKind relationKind = index.usedNameKinds[i]; |
| + SearchResultKind resultKind = relationToResultKind[relationKind]; |
| + if (resultKind != null) { |
| + int offset = index.usedNameOffsets[i]; |
| + enclosingUnitElement ??= await getEnclosingUnitElement(); |
| + Element enclosingElement = |
| + _getEnclosingElement(enclosingUnitElement, offset); |
| + results.add(new SearchResult._(enclosingElement, resultKind, offset, |
| + name.length, false, index.usedNameIsQualifiedFlags[i])); |
| + } |
| + } |
| + |
| + return results; |
| + } |
| + |
| + /** |
| * Return the identifier of the [uri] in the [index] or `-1` if the [uri] is |
| * not used in the [index]. |
| */ |