| 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 library services.src.search.search_engine2; | 5 library services.src.search.search_engine2; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/correction/source_range.dart'; | 9 import 'package:analysis_server/src/services/correction/source_range.dart'; |
| 10 import 'package:analysis_server/src/services/index2/index2.dart'; | 10 import 'package:analysis_server/src/services/index2/index2.dart'; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 }).toList(); | 47 }).toList(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 @override | 50 @override |
| 51 Future<List<SearchMatch>> searchReferences(Element element) { | 51 Future<List<SearchMatch>> searchReferences(Element element) { |
| 52 ElementKind kind = element.kind; | 52 ElementKind kind = element.kind; |
| 53 if (kind == ElementKind.CLASS || | 53 if (kind == ElementKind.CLASS || |
| 54 kind == ElementKind.COMPILATION_UNIT || | 54 kind == ElementKind.COMPILATION_UNIT || |
| 55 kind == ElementKind.CONSTRUCTOR || | 55 kind == ElementKind.CONSTRUCTOR || |
| 56 kind == ElementKind.FUNCTION_TYPE_ALIAS || | 56 kind == ElementKind.FUNCTION_TYPE_ALIAS || |
| 57 kind == ElementKind.GETTER || | |
| 58 kind == ElementKind.SETTER) { | 57 kind == ElementKind.SETTER) { |
| 59 return _searchReferences(element); | 58 return _searchReferences(element); |
| 59 } else if (kind == ElementKind.GETTER) { |
| 60 return _searchReferences_Getter(element); |
| 60 } else if (kind == ElementKind.FIELD || | 61 } else if (kind == ElementKind.FIELD || |
| 61 kind == ElementKind.TOP_LEVEL_VARIABLE) { | 62 kind == ElementKind.TOP_LEVEL_VARIABLE) { |
| 62 return _searchReferences_Field(element); | 63 return _searchReferences_Field(element); |
| 63 } else if (kind == ElementKind.FUNCTION || kind == ElementKind.METHOD) { | 64 } else if (kind == ElementKind.FUNCTION || kind == ElementKind.METHOD) { |
| 64 if (element.enclosingElement is ExecutableElement) { | 65 if (element.enclosingElement is ExecutableElement) { |
| 65 return _searchReferences_Local(element, (n) => n is Block); | 66 return _searchReferences_Local(element, (n) => n is Block); |
| 66 } | 67 } |
| 67 return _searchReferences_Function(element); | 68 return _searchReferences_Function(element); |
| 68 } else if (kind == ElementKind.IMPORT) { | 69 } else if (kind == ElementKind.IMPORT) { |
| 69 return _searchReferences_Import(element); | 70 return _searchReferences_Import(element); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 element = (element as Member).baseElement; | 164 element = (element as Member).baseElement; |
| 164 } | 165 } |
| 165 List<SearchMatch> matches = <SearchMatch>[]; | 166 List<SearchMatch> matches = <SearchMatch>[]; |
| 166 await _addMatches(matches, element, IndexRelationKind.IS_REFERENCED_BY, | 167 await _addMatches(matches, element, IndexRelationKind.IS_REFERENCED_BY, |
| 167 MatchKind.REFERENCE); | 168 MatchKind.REFERENCE); |
| 168 await _addMatches(matches, element, IndexRelationKind.IS_INVOKED_BY, | 169 await _addMatches(matches, element, IndexRelationKind.IS_INVOKED_BY, |
| 169 MatchKind.INVOCATION); | 170 MatchKind.INVOCATION); |
| 170 return matches; | 171 return matches; |
| 171 } | 172 } |
| 172 | 173 |
| 174 Future<List<SearchMatch>> _searchReferences_Getter( |
| 175 PropertyAccessorElement getter) async { |
| 176 List<SearchMatch> matches = <SearchMatch>[]; |
| 177 await _addMatches(matches, getter, IndexRelationKind.IS_REFERENCED_BY, |
| 178 MatchKind.REFERENCE); |
| 179 await _addMatches( |
| 180 matches, getter, IndexRelationKind.IS_INVOKED_BY, MatchKind.INVOCATION); |
| 181 return matches; |
| 182 } |
| 183 |
| 173 Future<List<SearchMatch>> _searchReferences_Import( | 184 Future<List<SearchMatch>> _searchReferences_Import( |
| 174 ImportElement element) async { | 185 ImportElement element) async { |
| 175 List<SearchMatch> matches = <SearchMatch>[]; | 186 List<SearchMatch> matches = <SearchMatch>[]; |
| 176 LibraryElement libraryElement = element.library; | 187 LibraryElement libraryElement = element.library; |
| 177 Source librarySource = libraryElement.source; | 188 Source librarySource = libraryElement.source; |
| 178 AnalysisContext context = libraryElement.context; | 189 AnalysisContext context = libraryElement.context; |
| 179 for (CompilationUnitElement unitElement in libraryElement.units) { | 190 for (CompilationUnitElement unitElement in libraryElement.units) { |
| 180 Source unitSource = unitElement.source; | 191 Source unitSource = unitElement.source; |
| 181 CompilationUnit unit = | 192 CompilationUnit unit = |
| 182 context.resolveCompilationUnit2(unitSource, librarySource); | 193 context.resolveCompilationUnit2(unitSource, librarySource); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 _addMatch(node, kind); | 374 _addMatch(node, kind); |
| 364 } | 375 } |
| 365 } | 376 } |
| 366 | 377 |
| 367 void _addMatch(AstNode node, MatchKind kind) { | 378 void _addMatch(AstNode node, MatchKind kind) { |
| 368 bool isQualified = node is SimpleIdentifier && node.isQualified; | 379 bool isQualified = node is SimpleIdentifier && node.isQualified; |
| 369 matches.add(new SearchMatch(context, libraryUri, unitUri, kind, | 380 matches.add(new SearchMatch(context, libraryUri, unitUri, kind, |
| 370 rangeNode(node), true, isQualified)); | 381 rangeNode(node), true, isQualified)); |
| 371 } | 382 } |
| 372 } | 383 } |
| OLD | NEW |