Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/visitor.dart'; | 10 import 'package:analyzer/dart/element/visitor.dart'; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 unitElement.accessors.forEach(addElement); | 135 unitElement.accessors.forEach(addElement); |
| 136 unitElement.enums.forEach(addElement); | 136 unitElement.enums.forEach(addElement); |
| 137 unitElement.functions.forEach(addElement); | 137 unitElement.functions.forEach(addElement); |
| 138 unitElement.functionTypeAliases.forEach(addElement); | 138 unitElement.functionTypeAliases.forEach(addElement); |
| 139 unitElement.topLevelVariables.forEach(addElement); | 139 unitElement.topLevelVariables.forEach(addElement); |
| 140 unitElement.types.forEach(addElement); | 140 unitElement.types.forEach(addElement); |
| 141 } | 141 } |
| 142 return elements; | 142 return elements; |
| 143 } | 143 } |
| 144 | 144 |
| 145 /** | |
| 146 * Returns unresolved references to the given [name]. | |
| 147 */ | |
| 148 Future<List<SearchResult>> unresolvedMemberReferences(String name) async { | |
| 149 if (name == null) { | |
| 150 return const <SearchResult>[]; | |
| 151 } | |
| 152 | |
| 153 // Prepare the list of files that reference the name. | |
| 154 List<String> files = await _driver.getFilesReferencingName(name); | |
| 155 | |
| 156 // Check the index of every file that references the element name. | |
| 157 List<SearchResult> results = []; | |
| 158 for (String file in files) { | |
| 159 AnalysisDriverUnitIndex index = await _driver.getIndex(file); | |
| 160 _IndexRequest request = new _IndexRequest(index); | |
| 161 var fileResults = await request.getUnresolvedMemberReferences( | |
| 162 name, | |
| 163 const { | |
| 164 IndexRelationKind.IS_READ_BY: SearchResultKind.READ, | |
| 165 IndexRelationKind.IS_WRITTEN_BY: SearchResultKind.WRITE, | |
| 166 IndexRelationKind.IS_READ_WRITTEN_BY: SearchResultKind.READ_WRITE, | |
| 167 IndexRelationKind.IS_INVOKED_BY: SearchResultKind.INVOCATION | |
| 168 }, | |
| 169 () => _driver.getUnitElement(file)); | |
| 170 results.addAll(fileResults); | |
| 171 // await _addResultsInFile(results, element, relationToResultKind, file); | |
|
Brian Wilkerson
2017/01/23 21:31:12
Remove?
| |
| 172 } | |
| 173 | |
| 174 return results; | |
| 175 | |
| 176 // TODO(scheglov) | |
| 177 } | |
| 178 | |
| 145 Future<Null> _addResults(List<SearchResult> results, Element element, | 179 Future<Null> _addResults(List<SearchResult> results, Element element, |
| 146 Map<IndexRelationKind, SearchResultKind> relationToResultKind) async { | 180 Map<IndexRelationKind, SearchResultKind> relationToResultKind) async { |
| 147 // Prepare the element name. | 181 // Prepare the element name. |
| 148 String name = element.displayName; | 182 String name = element.displayName; |
| 149 if (element is ConstructorElement) { | 183 if (element is ConstructorElement) { |
| 150 name = element.enclosingElement.displayName; | 184 name = element.enclosingElement.displayName; |
| 151 } | 185 } |
| 152 | 186 |
| 153 // Prepare the list of files that reference the element name. | 187 // Prepare the list of files that reference the element name. |
| 154 List<String> files = <String>[]; | 188 List<String> files = <String>[]; |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 for (int i = 0; i < index.unitLibraryUris.length; i++) { | 731 for (int i = 0; i < index.unitLibraryUris.length; i++) { |
| 698 if (index.unitLibraryUris[i] == libraryUriId && | 732 if (index.unitLibraryUris[i] == libraryUriId && |
| 699 index.unitUnitUris[i] == unitUriId) { | 733 index.unitUnitUris[i] == unitUriId) { |
| 700 return i; | 734 return i; |
| 701 } | 735 } |
| 702 } | 736 } |
| 703 return -1; | 737 return -1; |
| 704 } | 738 } |
| 705 | 739 |
| 706 /** | 740 /** |
| 741 * Return a list of results where a class members with the given [name] is | |
| 742 * referenced with a qualifier, but is not resolved. | |
| 743 */ | |
| 744 Future<List<SearchResult>> getUnresolvedMemberReferences( | |
| 745 String name, | |
| 746 Map<IndexRelationKind, SearchResultKind> relationToResultKind, | |
| 747 Future<CompilationUnitElement> getEnclosingUnitElement()) async { | |
| 748 // Find the name identifier. | |
| 749 int nameId = getStringId(name); | |
| 750 if (nameId == -1) { | |
| 751 return const <SearchResult>[]; | |
| 752 } | |
| 753 | |
| 754 // Find the first usage of the name. | |
| 755 int i = _findFirstOccurrence(index.usedNames, nameId); | |
| 756 if (i == -1) { | |
| 757 return const <SearchResult>[]; | |
| 758 } | |
| 759 | |
| 760 // Create results for every usage of the name. | |
| 761 List<SearchResult> results = <SearchResult>[]; | |
| 762 CompilationUnitElement enclosingUnitElement = null; | |
| 763 for (; i < index.usedNames.length && index.usedNames[i] == nameId; i++) { | |
| 764 IndexRelationKind relationKind = index.usedNameKinds[i]; | |
| 765 SearchResultKind resultKind = relationToResultKind[relationKind]; | |
| 766 if (resultKind != null) { | |
| 767 int offset = index.usedNameOffsets[i]; | |
| 768 enclosingUnitElement ??= await getEnclosingUnitElement(); | |
| 769 Element enclosingElement = | |
| 770 _getEnclosingElement(enclosingUnitElement, offset); | |
| 771 results.add(new SearchResult._(enclosingElement, resultKind, offset, | |
| 772 name.length, false, index.usedNameIsQualifiedFlags[i])); | |
| 773 } | |
| 774 } | |
| 775 | |
| 776 return results; | |
| 777 } | |
| 778 | |
| 779 /** | |
| 707 * Return the identifier of the [uri] in the [index] or `-1` if the [uri] is | 780 * Return the identifier of the [uri] in the [index] or `-1` if the [uri] is |
| 708 * not used in the [index]. | 781 * not used in the [index]. |
| 709 */ | 782 */ |
| 710 int getUriId(Uri uri) { | 783 int getUriId(Uri uri) { |
| 711 String str = uri.toString(); | 784 String str = uri.toString(); |
| 712 return getStringId(str); | 785 return getStringId(str); |
| 713 } | 786 } |
| 714 | 787 |
| 715 /** | 788 /** |
| 716 * Return the index of the first occurrence of the [value] in the [sortedList] , | 789 * Return the index of the first occurrence of the [value] in the [sortedList] , |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 } | 848 } |
| 776 | 849 |
| 777 void _addResult(AstNode node, SearchResultKind kind) { | 850 void _addResult(AstNode node, SearchResultKind kind) { |
| 778 bool isQualified = node.parent is Label; | 851 bool isQualified = node.parent is Label; |
| 779 Element enclosingElement = | 852 Element enclosingElement = |
| 780 _getEnclosingElement(enclosingUnitElement, node.offset); | 853 _getEnclosingElement(enclosingUnitElement, node.offset); |
| 781 results.add(new SearchResult._( | 854 results.add(new SearchResult._( |
| 782 enclosingElement, kind, node.offset, node.length, true, isQualified)); | 855 enclosingElement, kind, node.offset, node.length, true, isQualified)); |
| 783 } | 856 } |
| 784 } | 857 } |
| OLD | NEW |