| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * Search support for an [AnalysisDriver]. | 29 * Search support for an [AnalysisDriver]. |
| 30 */ | 30 */ |
| 31 class Search { | 31 class Search { |
| 32 final AnalysisDriver _driver; | 32 final AnalysisDriver _driver; |
| 33 | 33 |
| 34 Search(this._driver); | 34 Search(this._driver); |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Returns class members with names matching the given [regExp]. |
| 38 */ |
| 39 Future<List<Element>> classMembers(RegExp regExp) async { |
| 40 List<Element> elements = <Element>[]; |
| 41 |
| 42 void addElement(Element element) { |
| 43 if (!element.isSynthetic && regExp.hasMatch(element.displayName)) { |
| 44 elements.add(element); |
| 45 } |
| 46 } |
| 47 |
| 48 for (FileState file in _driver.fsState.knownFiles) { |
| 49 CompilationUnitElement unitElement = |
| 50 await _driver.getUnitElement(file.path); |
| 51 for (ClassElement clazz in unitElement.types) { |
| 52 clazz.accessors.forEach(addElement); |
| 53 clazz.fields.forEach(addElement); |
| 54 clazz.methods.forEach(addElement); |
| 55 } |
| 56 } |
| 57 return elements; |
| 58 } |
| 59 |
| 60 /** |
| 37 * Returns references to the [element]. | 61 * Returns references to the [element]. |
| 38 */ | 62 */ |
| 39 Future<List<SearchResult>> references(Element element) async { | 63 Future<List<SearchResult>> references(Element element) async { |
| 40 if (element == null) { | 64 if (element == null) { |
| 41 return const <SearchResult>[]; | 65 return const <SearchResult>[]; |
| 42 } | 66 } |
| 43 | 67 |
| 44 ElementKind kind = element.kind; | 68 ElementKind kind = element.kind; |
| 45 if (kind == ElementKind.CLASS || | 69 if (kind == ElementKind.CLASS || |
| 46 kind == ElementKind.CONSTRUCTOR || | 70 kind == ElementKind.CONSTRUCTOR || |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 } | 745 } |
| 722 | 746 |
| 723 void _addResult(AstNode node, SearchResultKind kind) { | 747 void _addResult(AstNode node, SearchResultKind kind) { |
| 724 bool isQualified = node.parent is Label; | 748 bool isQualified = node.parent is Label; |
| 725 Element enclosingElement = | 749 Element enclosingElement = |
| 726 _getEnclosingElement(enclosingUnitElement, node.offset); | 750 _getEnclosingElement(enclosingUnitElement, node.offset); |
| 727 results.add(new SearchResult._( | 751 results.add(new SearchResult._( |
| 728 enclosingElement, kind, node.offset, node.length, true, isQualified)); | 752 enclosingElement, kind, node.offset, node.length, true, isQualified)); |
| 729 } | 753 } |
| 730 } | 754 } |
| OLD | NEW |