| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } else if (kind == ElementKind.FUNCTION || kind == ElementKind.METHOD) { | 53 } else if (kind == ElementKind.FUNCTION || kind == ElementKind.METHOD) { |
| 54 if (element.enclosingElement is ExecutableElement) { | 54 if (element.enclosingElement is ExecutableElement) { |
| 55 return _searchReferences_Local(element, (n) => n is Block); | 55 return _searchReferences_Local(element, (n) => n is Block); |
| 56 } | 56 } |
| 57 return _searchReferences_Function(element); | 57 return _searchReferences_Function(element); |
| 58 } else if (kind == ElementKind.LABEL || | 58 } else if (kind == ElementKind.LABEL || |
| 59 kind == ElementKind.LOCAL_VARIABLE) { | 59 kind == ElementKind.LOCAL_VARIABLE) { |
| 60 return _searchReferences_Local(element, (n) => n is Block); | 60 return _searchReferences_Local(element, (n) => n is Block); |
| 61 } else if (kind == ElementKind.PARAMETER) { | 61 } else if (kind == ElementKind.PARAMETER) { |
| 62 return _searchReferences_Parameter(element); | 62 return _searchReferences_Parameter(element); |
| 63 } else if (kind == ElementKind.PREFIX) { |
| 64 return _searchReferences_Prefix(element); |
| 63 } else if (kind == ElementKind.TYPE_PARAMETER) { | 65 } else if (kind == ElementKind.TYPE_PARAMETER) { |
| 64 return _searchReferences_Local( | 66 return _searchReferences_Local( |
| 65 element, (n) => n.parent is CompilationUnit); | 67 element, (n) => n.parent is CompilationUnit); |
| 66 } | 68 } |
| 67 // TODO(scheglov) support other kinds | 69 // TODO(scheglov) support other kinds |
| 68 return const <SearchResult>[]; | 70 return const <SearchResult>[]; |
| 69 } | 71 } |
| 70 | 72 |
| 71 Future<Null> _addResults(List<SearchResult> results, Element element, | 73 Future<Null> _addResults(List<SearchResult> results, Element element, |
| 72 Map<IndexRelationKind, SearchResultKind> relationToResultKind) async { | 74 Map<IndexRelationKind, SearchResultKind> relationToResultKind) async { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 Future<List<SearchResult>> _searchReferences_Parameter( | 191 Future<List<SearchResult>> _searchReferences_Parameter( |
| 190 ParameterElement parameter) async { | 192 ParameterElement parameter) async { |
| 191 List<SearchResult> results = <SearchResult>[]; | 193 List<SearchResult> results = <SearchResult>[]; |
| 192 results.addAll(await _searchReferences(parameter)); | 194 results.addAll(await _searchReferences(parameter)); |
| 193 results.addAll(await _searchReferences_Local(parameter, (AstNode node) { | 195 results.addAll(await _searchReferences_Local(parameter, (AstNode node) { |
| 194 AstNode parent = node.parent; | 196 AstNode parent = node.parent; |
| 195 return parent is ClassDeclaration || parent is CompilationUnit; | 197 return parent is ClassDeclaration || parent is CompilationUnit; |
| 196 })); | 198 })); |
| 197 return results; | 199 return results; |
| 198 } | 200 } |
| 201 |
| 202 Future<List<SearchResult>> _searchReferences_Prefix( |
| 203 PrefixElement element) async { |
| 204 List<SearchResult> results = <SearchResult>[]; |
| 205 LibraryElement libraryElement = element.library; |
| 206 for (CompilationUnitElement unitElement in libraryElement.units) { |
| 207 String unitPath = unitElement.source.fullName; |
| 208 AnalysisResult unitAnalysisResult = await _driver.getResult(unitPath); |
| 209 _LocalReferencesVisitor visitor = |
| 210 new _LocalReferencesVisitor(element, unitElement); |
| 211 unitAnalysisResult.unit.accept(visitor); |
| 212 results.addAll(visitor.results); |
| 213 } |
| 214 return results; |
| 215 } |
| 199 } | 216 } |
| 200 | 217 |
| 201 /** | 218 /** |
| 202 * A single search result. | 219 * A single search result. |
| 203 */ | 220 */ |
| 204 class SearchResult { | 221 class SearchResult { |
| 205 /** | 222 /** |
| 206 * The element that is used at this result. | 223 * The element that is used at this result. |
| 207 */ | 224 */ |
| 208 final Element element; | 225 final Element element; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 532 } |
| 516 | 533 |
| 517 void _addResult(AstNode node, SearchResultKind kind) { | 534 void _addResult(AstNode node, SearchResultKind kind) { |
| 518 bool isQualified = node.parent is Label; | 535 bool isQualified = node.parent is Label; |
| 519 Element enclosingElement = | 536 Element enclosingElement = |
| 520 _getEnclosingElement(enclosingUnitElement, node.offset); | 537 _getEnclosingElement(enclosingUnitElement, node.offset); |
| 521 results.add(new SearchResult._(element, enclosingElement, kind, node.offset, | 538 results.add(new SearchResult._(element, enclosingElement, kind, node.offset, |
| 522 node.length, true, isQualified)); | 539 node.length, true, isQualified)); |
| 523 } | 540 } |
| 524 } | 541 } |
| OLD | NEW |