| 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:analysis_server/src/services/search/search_engine.dart'; | 7 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/src/dart/analysis/driver.dart'; | 9 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 10 import 'package:analyzer/src/dart/analysis/search.dart'; | 10 import 'package:analyzer/src/dart/analysis/search.dart'; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 await addSubtypes(type); | 35 await addSubtypes(type); |
| 36 return allSubtypes; | 36 return allSubtypes; |
| 37 } | 37 } |
| 38 | 38 |
| 39 @override | 39 @override |
| 40 Future<List<SearchMatch>> searchMemberDeclarations(String name) async { | 40 Future<List<SearchMatch>> searchMemberDeclarations(String name) async { |
| 41 // TODO(scheglov) implement | 41 List<SearchMatch> allDeclarations = []; |
| 42 return []; | 42 RegExp regExp = new RegExp('^$name\$'); |
| 43 for (AnalysisDriver driver in _drivers) { |
| 44 List<Element> elements = await driver.search.classMembers(regExp); |
| 45 allDeclarations.addAll(elements.map(_SearchMatch.forElement)); |
| 46 } |
| 47 return allDeclarations; |
| 43 } | 48 } |
| 44 | 49 |
| 45 @override | 50 @override |
| 46 Future<List<SearchMatch>> searchMemberReferences(String name) async { | 51 Future<List<SearchMatch>> searchMemberReferences(String name) async { |
| 47 // TODO(scheglov) implement | 52 // TODO(scheglov) implement |
| 48 return []; | 53 return []; |
| 49 } | 54 } |
| 50 | 55 |
| 51 @override | 56 @override |
| 52 Future<List<SearchMatch>> searchReferences(Element element) async { | 57 Future<List<SearchMatch>> searchReferences(Element element) async { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 List<SearchResult> results = await _searchDirectSubtypes(type); | 68 List<SearchResult> results = await _searchDirectSubtypes(type); |
| 64 return results.map(_SearchMatch.forSearchResult).toList(); | 69 return results.map(_SearchMatch.forSearchResult).toList(); |
| 65 } | 70 } |
| 66 | 71 |
| 67 @override | 72 @override |
| 68 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) async { | 73 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) async { |
| 69 List<SearchMatch> allDeclarations = []; | 74 List<SearchMatch> allDeclarations = []; |
| 70 RegExp regExp = new RegExp(pattern); | 75 RegExp regExp = new RegExp(pattern); |
| 71 for (AnalysisDriver driver in _drivers) { | 76 for (AnalysisDriver driver in _drivers) { |
| 72 List<Element> elements = await driver.search.topLevelElements(regExp); | 77 List<Element> elements = await driver.search.topLevelElements(regExp); |
| 73 for (Element element in elements) { | 78 allDeclarations.addAll(elements.map(_SearchMatch.forElement)); |
| 74 allDeclarations.add(new _SearchMatch( | |
| 75 element.source.fullName, | |
| 76 element.librarySource, | |
| 77 element.source, | |
| 78 element.library, | |
| 79 element, | |
| 80 true, | |
| 81 true, | |
| 82 MatchKind.DECLARATION, | |
| 83 new SourceRange(element.nameOffset, element.nameLength))); | |
| 84 } | |
| 85 } | 79 } |
| 86 return allDeclarations; | 80 return allDeclarations; |
| 87 } | 81 } |
| 88 | 82 |
| 89 Future<List<SearchResult>> _searchDirectSubtypes(ClassElement type) async { | 83 Future<List<SearchResult>> _searchDirectSubtypes(ClassElement type) async { |
| 90 List<SearchResult> allResults = []; | 84 List<SearchResult> allResults = []; |
| 91 for (AnalysisDriver driver in _drivers) { | 85 for (AnalysisDriver driver in _drivers) { |
| 92 List<SearchResult> results = await driver.search.subTypes(type); | 86 List<SearchResult> results = await driver.search.subTypes(type); |
| 93 allResults.addAll(results); | 87 allResults.addAll(results); |
| 94 } | 88 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 enclosingElement.librarySource, | 155 enclosingElement.librarySource, |
| 162 enclosingElement.source, | 156 enclosingElement.source, |
| 163 enclosingElement.library, | 157 enclosingElement.library, |
| 164 enclosingElement, | 158 enclosingElement, |
| 165 result.isResolved, | 159 result.isResolved, |
| 166 result.isQualified, | 160 result.isQualified, |
| 167 toMatchKind(result.kind), | 161 toMatchKind(result.kind), |
| 168 new SourceRange(result.offset, result.length)); | 162 new SourceRange(result.offset, result.length)); |
| 169 } | 163 } |
| 170 | 164 |
| 165 static _SearchMatch forElement(Element element) { |
| 166 return new _SearchMatch( |
| 167 element.source.fullName, |
| 168 element.librarySource, |
| 169 element.source, |
| 170 element.library, |
| 171 element, |
| 172 true, |
| 173 true, |
| 174 MatchKind.DECLARATION, |
| 175 new SourceRange(element.nameOffset, element.nameLength)); |
| 176 } |
| 177 |
| 171 static MatchKind toMatchKind(SearchResultKind kind) { | 178 static MatchKind toMatchKind(SearchResultKind kind) { |
| 172 if (kind == SearchResultKind.READ) { | 179 if (kind == SearchResultKind.READ) { |
| 173 return MatchKind.READ; | 180 return MatchKind.READ; |
| 174 } | 181 } |
| 175 if (kind == SearchResultKind.READ_WRITE) { | 182 if (kind == SearchResultKind.READ_WRITE) { |
| 176 return MatchKind.READ_WRITE; | 183 return MatchKind.READ_WRITE; |
| 177 } | 184 } |
| 178 if (kind == SearchResultKind.WRITE) { | 185 if (kind == SearchResultKind.WRITE) { |
| 179 return MatchKind.WRITE; | 186 return MatchKind.WRITE; |
| 180 } | 187 } |
| 181 if (kind == SearchResultKind.INVOCATION) { | 188 if (kind == SearchResultKind.INVOCATION) { |
| 182 return MatchKind.INVOCATION; | 189 return MatchKind.INVOCATION; |
| 183 } | 190 } |
| 184 return MatchKind.REFERENCE; | 191 return MatchKind.REFERENCE; |
| 185 } | 192 } |
| 186 } | 193 } |
| OLD | NEW |