| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 @override | 37 @override |
| 38 Future<List<SearchMatch>> searchMemberDeclarations(String pattern) { | 38 Future<List<SearchMatch>> searchMemberDeclarations(String pattern) { |
| 39 return _searchDefinedNames(pattern, IndexNameKind.classMember); | 39 return _searchDefinedNames(pattern, IndexNameKind.classMember); |
| 40 } | 40 } |
| 41 | 41 |
| 42 @override | 42 @override |
| 43 Future<List<SearchMatch>> searchMemberReferences(String name) async { | 43 Future<List<SearchMatch>> searchMemberReferences(String name) async { |
| 44 List<Location> locations = await _index.getUnresolvedMemberReferences(name); | 44 List<Location> locations = await _index.getUnresolvedMemberReferences(name); |
| 45 return locations.map((location) { | 45 return locations.map((location) { |
| 46 return _newMatchForLocation(location, MatchKind.REFERENCE); | 46 return _newMatchForLocation(location, null); |
| 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 || |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 _addMatches(List<SearchMatch> matches, Element element, | 103 _addMatches(List<SearchMatch> matches, Element element, |
| 104 IndexRelationKind relationKind, MatchKind kind) async { | 104 IndexRelationKind relationKind, MatchKind kind) async { |
| 105 List<Location> locations = await _index.getRelations(element, relationKind); | 105 List<Location> locations = await _index.getRelations(element, relationKind); |
| 106 for (Location location in locations) { | 106 for (Location location in locations) { |
| 107 SearchMatch match = _newMatchForLocation(location, kind); | 107 SearchMatch match = _newMatchForLocation(location, kind); |
| 108 matches.add(match); | 108 matches.add(match); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 SearchMatch _newMatchForLocation(Location location, MatchKind kind) => | 112 SearchMatch _newMatchForLocation(Location location, MatchKind kind) { |
| 113 new SearchMatch( | 113 if (kind == null) { |
| 114 location.context, | 114 IndexRelationKind relationKind = location.kind; |
| 115 location.libraryUri, | 115 if (relationKind == IndexRelationKind.IS_INVOKED_BY) { |
| 116 location.unitUri, | 116 kind = MatchKind.INVOCATION; |
| 117 kind, | 117 } else if (relationKind == IndexRelationKind.IS_REFERENCED_BY) { |
| 118 new SourceRange(location.offset, location.length), | 118 kind = MatchKind.REFERENCE; |
| 119 true, | 119 } else if (relationKind == IndexRelationKind.IS_READ_BY) { |
| 120 location.isQualified); | 120 kind = MatchKind.READ; |
| 121 } else if (relationKind == IndexRelationKind.IS_READ_WRITTEN_BY) { |
| 122 kind = MatchKind.READ_WRITE; |
| 123 } else if (relationKind == IndexRelationKind.IS_WRITTEN_BY) { |
| 124 kind = MatchKind.WRITE; |
| 125 } else { |
| 126 throw new ArgumentError('Unsupported relation kind $relationKind'); |
| 127 } |
| 128 } |
| 129 return new SearchMatch( |
| 130 location.context, |
| 131 location.libraryUri, |
| 132 location.unitUri, |
| 133 kind, |
| 134 new SourceRange(location.offset, location.length), |
| 135 location.isResolved, |
| 136 location.isQualified); |
| 137 } |
| 121 | 138 |
| 122 Future<List<SearchMatch>> _searchDefinedNames( | 139 Future<List<SearchMatch>> _searchDefinedNames( |
| 123 String pattern, IndexNameKind nameKind) async { | 140 String pattern, IndexNameKind nameKind) async { |
| 124 RegExp regExp = new RegExp(pattern); | 141 RegExp regExp = new RegExp(pattern); |
| 125 List<Location> locations = await _index.getDefinedNames(regExp, nameKind); | 142 List<Location> locations = await _index.getDefinedNames(regExp, nameKind); |
| 126 return locations.map((location) { | 143 return locations.map((location) { |
| 127 return _newMatchForLocation(location, MatchKind.DECLARATION); | 144 return _newMatchForLocation(location, MatchKind.DECLARATION); |
| 128 }).toList(); | 145 }).toList(); |
| 129 } | 146 } |
| 130 | 147 |
| 131 Future<List<SearchMatch>> _searchReferences(Element element) async { | 148 Future<List<SearchMatch>> _searchReferences(Element element) async { |
| 132 List<SearchMatch> matches = <SearchMatch>[]; | 149 List<SearchMatch> matches = <SearchMatch>[]; |
| 133 await _addMatches(matches, element, IndexRelationKind.IS_REFERENCED_BY, | 150 await _addMatches(matches, element, IndexRelationKind.IS_REFERENCED_BY, |
| 134 MatchKind.REFERENCE); | 151 MatchKind.REFERENCE); |
| 135 return matches; | 152 return matches; |
| 136 } | 153 } |
| 137 | 154 |
| 138 Future<List<SearchMatch>> _searchReferences_Field( | 155 Future<List<SearchMatch>> _searchReferences_Field( |
| 139 PropertyInducingElement field) async { | 156 PropertyInducingElement field) async { |
| 140 List<SearchMatch> matches = <SearchMatch>[]; | 157 List<SearchMatch> matches = <SearchMatch>[]; |
| 141 PropertyAccessorElement getter = field.getter; | 158 PropertyAccessorElement getter = field.getter; |
| 142 PropertyAccessorElement setter = field.setter; | 159 PropertyAccessorElement setter = field.setter; |
| 143 // field itself | 160 // field itself |
| 144 if (!field.isSynthetic) { | 161 if (!field.isSynthetic) { |
| 162 await _addMatches( |
| 163 matches, field, IndexRelationKind.IS_WRITTEN_BY, MatchKind.WRITE); |
| 145 await _addMatches(matches, field, IndexRelationKind.IS_REFERENCED_BY, | 164 await _addMatches(matches, field, IndexRelationKind.IS_REFERENCED_BY, |
| 146 MatchKind.REFERENCE); | 165 MatchKind.REFERENCE); |
| 147 } | 166 } |
| 148 // getter | 167 // getter |
| 149 if (getter != null) { | 168 if (getter != null) { |
| 150 await _addMatches( | 169 await _addMatches( |
| 151 matches, getter, IndexRelationKind.IS_REFERENCED_BY, MatchKind.READ); | 170 matches, getter, IndexRelationKind.IS_REFERENCED_BY, MatchKind.READ); |
| 152 await _addMatches(matches, getter, IndexRelationKind.IS_INVOKED_BY, | 171 await _addMatches(matches, getter, IndexRelationKind.IS_INVOKED_BY, |
| 153 MatchKind.INVOCATION); | 172 MatchKind.INVOCATION); |
| 154 } | 173 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 _addMatch(node, kind); | 401 _addMatch(node, kind); |
| 383 } | 402 } |
| 384 } | 403 } |
| 385 | 404 |
| 386 void _addMatch(AstNode node, MatchKind kind) { | 405 void _addMatch(AstNode node, MatchKind kind) { |
| 387 bool isQualified = node is SimpleIdentifier && node.isQualified; | 406 bool isQualified = node is SimpleIdentifier && node.isQualified; |
| 388 matches.add(new SearchMatch(context, libraryUri, unitUri, kind, | 407 matches.add(new SearchMatch(context, libraryUri, unitUri, kind, |
| 389 rangeNode(node), true, isQualified)); | 408 rangeNode(node), true, isQualified)); |
| 390 } | 409 } |
| 391 } | 410 } |
| OLD | NEW |