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 11 matching lines...) Expand all Loading... |
22 | 22 |
23 /** | 23 /** |
24 * Returns references to the [element]. | 24 * Returns references to the [element]. |
25 */ | 25 */ |
26 Future<List<SearchResult>> references(Element element) async { | 26 Future<List<SearchResult>> references(Element element) async { |
27 if (element == null) { | 27 if (element == null) { |
28 return const <SearchResult>[]; | 28 return const <SearchResult>[]; |
29 } | 29 } |
30 | 30 |
31 ElementKind kind = element.kind; | 31 ElementKind kind = element.kind; |
32 if (kind == ElementKind.LABEL || kind == ElementKind.LOCAL_VARIABLE) { | 32 if (kind == ElementKind.FUNCTION || kind == ElementKind.METHOD) { |
| 33 if (element.enclosingElement is ExecutableElement) { |
| 34 return _searchReferences_Local(element, (n) => n is Block); |
| 35 } |
| 36 // return _searchReferences_Function(element); |
| 37 } else if (kind == ElementKind.LABEL || kind == ElementKind.LOCAL_VARIABLE)
{ |
33 return _searchReferences_Local(element, (n) => n is Block); | 38 return _searchReferences_Local(element, (n) => n is Block); |
| 39 } else if (kind == ElementKind.TYPE_PARAMETER) { |
| 40 return _searchReferences_Local(element, (n) => n is ClassDeclaration); |
34 } | 41 } |
35 // TODO(scheglov) support other kinds | 42 // TODO(scheglov) support other kinds |
36 return const <SearchResult>[]; | 43 return const <SearchResult>[]; |
37 } | 44 } |
38 | 45 |
39 Future<List<SearchResult>> _searchReferences_Local( | 46 Future<List<SearchResult>> _searchReferences_Local( |
40 Element element, bool isRootNode(AstNode n)) async { | 47 Element element, bool isRootNode(AstNode n)) async { |
41 String path = element.source.fullName; | 48 String path = element.source.fullName; |
42 | 49 |
43 // Prepare the unit. | 50 // Prepare the unit. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 204 } |
198 | 205 |
199 void _addResult(AstNode node, SearchResultKind kind) { | 206 void _addResult(AstNode node, SearchResultKind kind) { |
200 bool isQualified = node.parent is Label; | 207 bool isQualified = node.parent is Label; |
201 var finder = new _ContainingElementFinder(node.offset); | 208 var finder = new _ContainingElementFinder(node.offset); |
202 enclosingUnitElement.accept(finder); | 209 enclosingUnitElement.accept(finder); |
203 results.add(new SearchResult._(element, finder.containingElement, kind, | 210 results.add(new SearchResult._(element, finder.containingElement, kind, |
204 node.offset, node.length, true, isQualified)); | 211 node.offset, node.length, true, isQualified)); |
205 } | 212 } |
206 } | 213 } |
OLD | NEW |