| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } else if (kind == ElementKind.FUNCTION || kind == ElementKind.METHOD) { | 81 } else if (kind == ElementKind.FUNCTION || kind == ElementKind.METHOD) { |
| 82 if (element.enclosingElement is ExecutableElement) { | 82 if (element.enclosingElement is ExecutableElement) { |
| 83 return _searchReferences_Local(element, (n) => n is Block); | 83 return _searchReferences_Local(element, (n) => n is Block); |
| 84 } | 84 } |
| 85 return _searchReferences_Function(element); | 85 return _searchReferences_Function(element); |
| 86 } else if (kind == ElementKind.IMPORT) { | 86 } else if (kind == ElementKind.IMPORT) { |
| 87 return _searchReferences_Import(element); | 87 return _searchReferences_Import(element); |
| 88 } else if (kind == ElementKind.LABEL || | 88 } else if (kind == ElementKind.LABEL || |
| 89 kind == ElementKind.LOCAL_VARIABLE) { | 89 kind == ElementKind.LOCAL_VARIABLE) { |
| 90 return _searchReferences_Local(element, (n) => n is Block); | 90 return _searchReferences_Local(element, (n) => n is Block); |
| 91 } else if (kind == ElementKind.LIBRARY) { |
| 92 return _searchReferences_Library(element); |
| 91 } else if (kind == ElementKind.PARAMETER) { | 93 } else if (kind == ElementKind.PARAMETER) { |
| 92 return _searchReferences_Parameter(element); | 94 return _searchReferences_Parameter(element); |
| 93 } else if (kind == ElementKind.PREFIX) { | 95 } else if (kind == ElementKind.PREFIX) { |
| 94 return _searchReferences_Prefix(element); | 96 return _searchReferences_Prefix(element); |
| 95 } else if (kind == ElementKind.TYPE_PARAMETER) { | 97 } else if (kind == ElementKind.TYPE_PARAMETER) { |
| 96 return _searchReferences_Local( | 98 return _searchReferences_Local( |
| 97 element, (n) => n.parent is CompilationUnit); | 99 element, (n) => n.parent is CompilationUnit); |
| 98 } | 100 } |
| 99 return const <SearchResult>[]; | 101 return const <SearchResult>[]; |
| 100 } | 102 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 String unitPath = unitElement.source.fullName; | 289 String unitPath = unitElement.source.fullName; |
| 288 AnalysisResult unitAnalysisResult = await _driver.getResult(unitPath); | 290 AnalysisResult unitAnalysisResult = await _driver.getResult(unitPath); |
| 289 _ImportElementReferencesVisitor visitor = | 291 _ImportElementReferencesVisitor visitor = |
| 290 new _ImportElementReferencesVisitor(element, unitElement); | 292 new _ImportElementReferencesVisitor(element, unitElement); |
| 291 unitAnalysisResult.unit.accept(visitor); | 293 unitAnalysisResult.unit.accept(visitor); |
| 292 results.addAll(visitor.results); | 294 results.addAll(visitor.results); |
| 293 } | 295 } |
| 294 return results; | 296 return results; |
| 295 } | 297 } |
| 296 | 298 |
| 299 Future<List<SearchResult>> _searchReferences_Library( |
| 300 LibraryElement element) async { |
| 301 // Search only in drivers to which the library with the prefix was added. |
| 302 String path = element.source.fullName; |
| 303 if (!_driver.addedFiles.contains(path)) { |
| 304 return const <SearchResult>[]; |
| 305 } |
| 306 |
| 307 List<SearchResult> results = <SearchResult>[]; |
| 308 for (CompilationUnitElement unitElement in element.units) { |
| 309 String unitPath = unitElement.source.fullName; |
| 310 AnalysisResult unitAnalysisResult = await _driver.getResult(unitPath); |
| 311 CompilationUnit unit = unitAnalysisResult.unit; |
| 312 for (Directive directive in unit.directives) { |
| 313 if (directive is PartOfDirective && directive.element == element) { |
| 314 results.add(new SearchResult._( |
| 315 unit.element, |
| 316 SearchResultKind.REFERENCE, |
| 317 directive.libraryName.offset, |
| 318 directive.libraryName.length, |
| 319 true, |
| 320 false)); |
| 321 } |
| 322 } |
| 323 } |
| 324 return results; |
| 325 } |
| 326 |
| 297 Future<List<SearchResult>> _searchReferences_Local( | 327 Future<List<SearchResult>> _searchReferences_Local( |
| 298 Element element, bool isRootNode(AstNode n)) async { | 328 Element element, bool isRootNode(AstNode n)) async { |
| 299 String path = element.source.fullName; | 329 String path = element.source.fullName; |
| 300 if (!_driver.addedFiles.contains(path)) { | 330 if (!_driver.addedFiles.contains(path)) { |
| 301 return const <SearchResult>[]; | 331 return const <SearchResult>[]; |
| 302 } | 332 } |
| 303 | 333 |
| 304 // Prepare the unit. | 334 // Prepare the unit. |
| 305 AnalysisResult analysisResult = await _driver.getResult(path); | 335 AnalysisResult analysisResult = await _driver.getResult(path); |
| 306 CompilationUnit unit = analysisResult.unit; | 336 CompilationUnit unit = analysisResult.unit; |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 } | 775 } |
| 746 | 776 |
| 747 void _addResult(AstNode node, SearchResultKind kind) { | 777 void _addResult(AstNode node, SearchResultKind kind) { |
| 748 bool isQualified = node.parent is Label; | 778 bool isQualified = node.parent is Label; |
| 749 Element enclosingElement = | 779 Element enclosingElement = |
| 750 _getEnclosingElement(enclosingUnitElement, node.offset); | 780 _getEnclosingElement(enclosingUnitElement, node.offset); |
| 751 results.add(new SearchResult._( | 781 results.add(new SearchResult._( |
| 752 enclosingElement, kind, node.offset, node.length, true, isQualified)); | 782 enclosingElement, kind, node.offset, node.length, true, isQualified)); |
| 753 } | 783 } |
| 754 } | 784 } |
| OLD | NEW |