| 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 29 matching lines...) Expand all Loading... |
| 40 List<Element> elements = <Element>[]; | 40 List<Element> elements = <Element>[]; |
| 41 | 41 |
| 42 void addElement(Element element) { | 42 void addElement(Element element) { |
| 43 if (!element.isSynthetic && element.displayName == name) { | 43 if (!element.isSynthetic && element.displayName == name) { |
| 44 elements.add(element); | 44 elements.add(element); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 List<String> files = await _driver.getFilesDefiningClassMemberName(name); | 48 List<String> files = await _driver.getFilesDefiningClassMemberName(name); |
| 49 for (String file in files) { | 49 for (String file in files) { |
| 50 CompilationUnitElement unitElement = await _driver.getUnitElement(file); | 50 UnitElementResult unitResult = await _driver.getUnitElement(file); |
| 51 if (unitElement != null) { | 51 if (unitResult != null) { |
| 52 for (ClassElement clazz in unitElement.types) { | 52 for (ClassElement clazz in unitResult.element.types) { |
| 53 clazz.accessors.forEach(addElement); | 53 clazz.accessors.forEach(addElement); |
| 54 clazz.fields.forEach(addElement); | 54 clazz.fields.forEach(addElement); |
| 55 clazz.methods.forEach(addElement); | 55 clazz.methods.forEach(addElement); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 return elements; | 59 return elements; |
| 60 } | 60 } |
| 61 | 61 |
| 62 /** | 62 /** |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 Future<List<Element>> topLevelElements(RegExp regExp) async { | 125 Future<List<Element>> topLevelElements(RegExp regExp) async { |
| 126 List<Element> elements = <Element>[]; | 126 List<Element> elements = <Element>[]; |
| 127 | 127 |
| 128 void addElement(Element element) { | 128 void addElement(Element element) { |
| 129 if (!element.isSynthetic && regExp.hasMatch(element.displayName)) { | 129 if (!element.isSynthetic && regExp.hasMatch(element.displayName)) { |
| 130 elements.add(element); | 130 elements.add(element); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 for (FileState file in _driver.fsState.knownFiles) { | 134 for (FileState file in _driver.fsState.knownFiles) { |
| 135 CompilationUnitElement unitElement = | 135 UnitElementResult unitResult = await _driver.getUnitElement(file.path); |
| 136 await _driver.getUnitElement(file.path); | 136 if (unitResult != null) { |
| 137 if (unitElement != null) { | 137 CompilationUnitElement unitElement = unitResult.element; |
| 138 unitElement.accessors.forEach(addElement); | 138 unitElement.accessors.forEach(addElement); |
| 139 unitElement.enums.forEach(addElement); | 139 unitElement.enums.forEach(addElement); |
| 140 unitElement.functions.forEach(addElement); | 140 unitElement.functions.forEach(addElement); |
| 141 unitElement.functionTypeAliases.forEach(addElement); | 141 unitElement.functionTypeAliases.forEach(addElement); |
| 142 unitElement.topLevelVariables.forEach(addElement); | 142 unitElement.topLevelVariables.forEach(addElement); |
| 143 unitElement.types.forEach(addElement); | 143 unitElement.types.forEach(addElement); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 return elements; | 146 return elements; |
| 147 } | 147 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 164 if (index != null) { | 164 if (index != null) { |
| 165 _IndexRequest request = new _IndexRequest(index); | 165 _IndexRequest request = new _IndexRequest(index); |
| 166 var fileResults = await request.getUnresolvedMemberReferences( | 166 var fileResults = await request.getUnresolvedMemberReferences( |
| 167 name, | 167 name, |
| 168 const { | 168 const { |
| 169 IndexRelationKind.IS_READ_BY: SearchResultKind.READ, | 169 IndexRelationKind.IS_READ_BY: SearchResultKind.READ, |
| 170 IndexRelationKind.IS_WRITTEN_BY: SearchResultKind.WRITE, | 170 IndexRelationKind.IS_WRITTEN_BY: SearchResultKind.WRITE, |
| 171 IndexRelationKind.IS_READ_WRITTEN_BY: SearchResultKind.READ_WRITE, | 171 IndexRelationKind.IS_READ_WRITTEN_BY: SearchResultKind.READ_WRITE, |
| 172 IndexRelationKind.IS_INVOKED_BY: SearchResultKind.INVOCATION | 172 IndexRelationKind.IS_INVOKED_BY: SearchResultKind.INVOCATION |
| 173 }, | 173 }, |
| 174 () => _driver.getUnitElement(file)); | 174 () => _getUnitElement(file)); |
| 175 results.addAll(fileResults); | 175 results.addAll(fileResults); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 return results; | 179 return results; |
| 180 } | 180 } |
| 181 | 181 |
| 182 Future<Null> _addResults(List<SearchResult> results, Element element, | 182 Future<Null> _addResults(List<SearchResult> results, Element element, |
| 183 Map<IndexRelationKind, SearchResultKind> relationToResultKind) async { | 183 Map<IndexRelationKind, SearchResultKind> relationToResultKind) async { |
| 184 // Prepare the element name. | 184 // Prepare the element name. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 Future<Null> _addResultsInFile( | 220 Future<Null> _addResultsInFile( |
| 221 List<SearchResult> results, | 221 List<SearchResult> results, |
| 222 Element element, | 222 Element element, |
| 223 Map<IndexRelationKind, SearchResultKind> relationToResultKind, | 223 Map<IndexRelationKind, SearchResultKind> relationToResultKind, |
| 224 String file) async { | 224 String file) async { |
| 225 AnalysisDriverUnitIndex index = await _driver.getIndex(file); | 225 AnalysisDriverUnitIndex index = await _driver.getIndex(file); |
| 226 if (index != null) { | 226 if (index != null) { |
| 227 _IndexRequest request = new _IndexRequest(index); | 227 _IndexRequest request = new _IndexRequest(index); |
| 228 int elementId = request.findElementId(element); | 228 int elementId = request.findElementId(element); |
| 229 if (elementId != -1) { | 229 if (elementId != -1) { |
| 230 List<SearchResult> fileResults = await request.getRelations(elementId, | 230 List<SearchResult> fileResults = await request.getRelations( |
| 231 relationToResultKind, () => _driver.getUnitElement(file)); | 231 elementId, relationToResultKind, () => _getUnitElement(file)); |
| 232 results.addAll(fileResults); | 232 results.addAll(fileResults); |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 Future<CompilationUnitElement> _getUnitElement(String file) async { |
| 238 UnitElementResult result = await _driver.getUnitElement(file); |
| 239 return result?.element; |
| 240 } |
| 241 |
| 237 Future<List<SearchResult>> _searchReferences(Element element) async { | 242 Future<List<SearchResult>> _searchReferences(Element element) async { |
| 238 List<SearchResult> results = <SearchResult>[]; | 243 List<SearchResult> results = <SearchResult>[]; |
| 239 await _addResults(results, element, | 244 await _addResults(results, element, |
| 240 const {IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.REFERENCE}); | 245 const {IndexRelationKind.IS_REFERENCED_BY: SearchResultKind.REFERENCE}); |
| 241 return results; | 246 return results; |
| 242 } | 247 } |
| 243 | 248 |
| 244 Future<List<SearchResult>> _searchReferences_CompilationUnit( | 249 Future<List<SearchResult>> _searchReferences_CompilationUnit( |
| 245 CompilationUnitElement element) async { | 250 CompilationUnitElement element) async { |
| 246 String path = element.source.fullName; | 251 String path = element.source.fullName; |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 } | 862 } |
| 858 | 863 |
| 859 void _addResult(AstNode node, SearchResultKind kind) { | 864 void _addResult(AstNode node, SearchResultKind kind) { |
| 860 bool isQualified = node.parent is Label; | 865 bool isQualified = node.parent is Label; |
| 861 Element enclosingElement = | 866 Element enclosingElement = |
| 862 _getEnclosingElement(enclosingUnitElement, node.offset); | 867 _getEnclosingElement(enclosingUnitElement, node.offset); |
| 863 results.add(new SearchResult._( | 868 results.add(new SearchResult._( |
| 864 enclosingElement, kind, node.offset, node.length, true, isQualified)); | 869 enclosingElement, kind, node.offset, node.length, true, isQualified)); |
| 865 } | 870 } |
| 866 } | 871 } |
| OLD | NEW |