| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_engine; | 5 library services.src.search.search_engine; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/index/index.dart'; | 9 import 'package:analysis_server/src/services/index/index.dart'; |
| 10 import 'package:analysis_server/src/services/search/search_engine.dart'; | 10 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 @override | 57 @override |
| 58 Future<List<SearchMatch>> searchReferences(Element element) { | 58 Future<List<SearchMatch>> searchReferences(Element element) { |
| 59 if (element.kind == ElementKind.ANGULAR_COMPONENT || | 59 if (element.kind == ElementKind.ANGULAR_COMPONENT || |
| 60 element.kind == ElementKind.ANGULAR_CONTROLLER || | 60 element.kind == ElementKind.ANGULAR_CONTROLLER || |
| 61 element.kind == ElementKind.ANGULAR_FORMATTER || | 61 element.kind == ElementKind.ANGULAR_FORMATTER || |
| 62 element.kind == ElementKind.ANGULAR_PROPERTY || | 62 element.kind == ElementKind.ANGULAR_PROPERTY || |
| 63 element.kind == ElementKind.ANGULAR_SCOPE_PROPERTY || | 63 element.kind == ElementKind.ANGULAR_SCOPE_PROPERTY || |
| 64 element.kind == ElementKind.ANGULAR_SELECTOR) { | 64 element.kind == ElementKind.ANGULAR_SELECTOR) { |
| 65 return _searchReferences_Angular(element as AngularElement); | 65 return _searchReferences_Angular(element as AngularElement); |
| 66 } else if (element.kind == ElementKind.CLASS) { | 66 } else if (element.kind == ElementKind.CLASS) { |
| 67 return _searchReferences_Class(element as ClassElement); | 67 return _searchReferences(element); |
| 68 } else if (element.kind == ElementKind.COMPILATION_UNIT) { | 68 } else if (element.kind == ElementKind.COMPILATION_UNIT) { |
| 69 return _searchReferences_CompilationUnit( | 69 return _searchReferences(element); |
| 70 element as CompilationUnitElement); | |
| 71 } else if (element.kind == ElementKind.CONSTRUCTOR) { | 70 } else if (element.kind == ElementKind.CONSTRUCTOR) { |
| 72 return _searchReferences_Constructor(element as ConstructorElement); | 71 return _searchReferences_Constructor(element as ConstructorElement); |
| 73 } else if (element.kind == ElementKind.FIELD || | 72 } else if (element.kind == ElementKind.FIELD || |
| 74 element.kind == ElementKind.TOP_LEVEL_VARIABLE) { | 73 element.kind == ElementKind.TOP_LEVEL_VARIABLE) { |
| 75 return _searchReferences_Field(element as PropertyInducingElement); | 74 return _searchReferences_Field(element as PropertyInducingElement); |
| 76 } else if (element.kind == ElementKind.FUNCTION) { | 75 } else if (element.kind == ElementKind.FUNCTION) { |
| 77 return _searchReferences_Function(element as FunctionElement); | 76 return _searchReferences_Function(element as FunctionElement); |
| 78 } else if (element.kind == ElementKind.GETTER || | 77 } else if (element.kind == ElementKind.GETTER || |
| 79 element.kind == ElementKind.SETTER) { | 78 element.kind == ElementKind.SETTER) { |
| 80 return _searchReferences_PropertyAccessor( | 79 return _searchReferences(element); |
| 81 element as PropertyAccessorElement); | |
| 82 } else if (element.kind == ElementKind.IMPORT) { | 80 } else if (element.kind == ElementKind.IMPORT) { |
| 83 return _searchReferences_Import(element as ImportElement); | 81 return _searchReferences(element); |
| 84 } else if (element.kind == ElementKind.LABEL) { | 82 } else if (element.kind == ElementKind.LABEL) { |
| 85 return _searchReferences_Label(element as LabelElement); | 83 return _searchReferences(element); |
| 86 } else if (element.kind == ElementKind.LIBRARY) { | 84 } else if (element.kind == ElementKind.LIBRARY) { |
| 87 return _searchReferences_Library(element as LibraryElement); | 85 return _searchReferences(element); |
| 88 } else if (element.kind == ElementKind.LOCAL_VARIABLE) { | 86 } else if (element.kind == ElementKind.LOCAL_VARIABLE) { |
| 89 return _searchReferences_LocalVariable(element as LocalVariableElement); | 87 return _searchReferences_LocalVariable(element as LocalVariableElement); |
| 90 } else if (element.kind == ElementKind.METHOD) { | 88 } else if (element.kind == ElementKind.METHOD) { |
| 91 return _searchReferences_Method(element as MethodElement); | 89 return _searchReferences_Method(element as MethodElement); |
| 92 } else if (element.kind == ElementKind.PARAMETER) { | 90 } else if (element.kind == ElementKind.PARAMETER) { |
| 93 return _searchReferences_Parameter(element as ParameterElement); | 91 return _searchReferences_Parameter(element as ParameterElement); |
| 92 } else if (element.kind == ElementKind.PREFIX) { |
| 93 return _searchReferences(element); |
| 94 } else if (element.kind == ElementKind.FUNCTION_TYPE_ALIAS) { | 94 } else if (element.kind == ElementKind.FUNCTION_TYPE_ALIAS) { |
| 95 return _searchReferences_FunctionTypeAlias( | 95 return _searchReferences(element); |
| 96 element as FunctionTypeAliasElement); | |
| 97 } else if (element.kind == ElementKind.TYPE_PARAMETER) { | 96 } else if (element.kind == ElementKind.TYPE_PARAMETER) { |
| 98 return _searchReferences_TypeParameter(element as TypeParameterElement); | 97 return _searchReferences(element); |
| 99 } | 98 } |
| 100 return new Future.value(<SearchMatch>[]); | 99 return new Future.value(<SearchMatch>[]); |
| 101 } | 100 } |
| 102 | 101 |
| 103 @override | 102 @override |
| 104 Future<List<SearchMatch>> searchSubtypes(ClassElement type) { | 103 Future<List<SearchMatch>> searchSubtypes(ClassElement type) { |
| 105 _Requestor requestor = new _Requestor(_index); | 104 _Requestor requestor = new _Requestor(_index); |
| 106 requestor.add(type, IndexConstants.IS_EXTENDED_BY, MatchKind.REFERENCE); | 105 requestor.add(type, IndexConstants.IS_EXTENDED_BY, MatchKind.REFERENCE); |
| 107 requestor.add(type, IndexConstants.IS_MIXED_IN_BY, MatchKind.REFERENCE); | 106 requestor.add(type, IndexConstants.IS_MIXED_IN_BY, MatchKind.REFERENCE); |
| 108 requestor.add(type, IndexConstants.IS_IMPLEMENTED_BY, MatchKind.REFERENCE); | 107 requestor.add(type, IndexConstants.IS_IMPLEMENTED_BY, MatchKind.REFERENCE); |
| 109 return requestor.merge(); | 108 return requestor.merge(); |
| 110 } | 109 } |
| 111 | 110 |
| 112 @override | 111 @override |
| 113 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) { | 112 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) { |
| 114 UniverseElement universe = UniverseElement.INSTANCE; | 113 UniverseElement universe = UniverseElement.INSTANCE; |
| 115 _Requestor requestor = new _Requestor(_index); | 114 _Requestor requestor = new _Requestor(_index); |
| 116 requestor.add(universe, IndexConstants.DEFINES, MatchKind.DECLARATION); | 115 requestor.add(universe, IndexConstants.DEFINES, MatchKind.DECLARATION); |
| 117 RegExp regExp = new RegExp(pattern); | 116 RegExp regExp = new RegExp(pattern); |
| 118 return requestor.merge().then((List<SearchMatch> matches) { | 117 return requestor.merge().then((List<SearchMatch> matches) { |
| 119 return matches.where((SearchMatch match) { | 118 return matches.where((SearchMatch match) { |
| 120 String name = match.element.displayName; | 119 String name = match.element.displayName; |
| 121 return regExp.hasMatch(name); | 120 return regExp.hasMatch(name); |
| 122 }).toList(); | 121 }).toList(); |
| 123 }); | 122 }); |
| 124 } | 123 } |
| 125 | 124 |
| 125 Future<List<SearchMatch>> _searchReferences(Element element) { |
| 126 _Requestor requestor = new _Requestor(_index); |
| 127 requestor.add( |
| 128 element, |
| 129 IndexConstants.IS_REFERENCED_BY, |
| 130 MatchKind.REFERENCE); |
| 131 return requestor.merge(); |
| 132 } |
| 133 |
| 126 Future<List<SearchMatch>> _searchReferences_Angular(AngularElement element) { | 134 Future<List<SearchMatch>> _searchReferences_Angular(AngularElement element) { |
| 127 _Requestor requestor = new _Requestor(_index); | 135 _Requestor requestor = new _Requestor(_index); |
| 128 requestor.add( | 136 requestor.add( |
| 129 element, | 137 element, |
| 130 IndexConstants.ANGULAR_REFERENCE, | 138 IndexConstants.ANGULAR_REFERENCE, |
| 131 MatchKind.ANGULAR_REFERENCE); | 139 MatchKind.ANGULAR_REFERENCE); |
| 132 requestor.add( | 140 requestor.add( |
| 133 element, | 141 element, |
| 134 IndexConstants.ANGULAR_CLOSING_TAG_REFERENCE, | 142 IndexConstants.ANGULAR_CLOSING_TAG_REFERENCE, |
| 135 MatchKind.ANGULAR_CLOSING_TAG_REFERENCE); | 143 MatchKind.ANGULAR_CLOSING_TAG_REFERENCE); |
| 136 return requestor.merge(); | 144 return requestor.merge(); |
| 137 } | 145 } |
| 138 | 146 |
| 139 Future<List<SearchMatch>> _searchReferences_Class(ClassElement clazz) { | |
| 140 _Requestor requestor = new _Requestor(_index); | |
| 141 requestor.add(clazz, IndexConstants.IS_REFERENCED_BY, MatchKind.REFERENCE); | |
| 142 return requestor.merge(); | |
| 143 } | |
| 144 | |
| 145 Future<List<SearchMatch>> | |
| 146 _searchReferences_CompilationUnit(CompilationUnitElement unit) { | |
| 147 _Requestor requestor = new _Requestor(_index); | |
| 148 requestor.add(unit, IndexConstants.IS_REFERENCED_BY, MatchKind.REFERENCE); | |
| 149 return requestor.merge(); | |
| 150 } | |
| 151 | |
| 152 Future<List<SearchMatch>> | 147 Future<List<SearchMatch>> |
| 153 _searchReferences_Constructor(ConstructorElement constructor) { | 148 _searchReferences_Constructor(ConstructorElement constructor) { |
| 154 _Requestor requestor = new _Requestor(_index); | 149 _Requestor requestor = new _Requestor(_index); |
| 155 requestor.add( | 150 requestor.add( |
| 156 constructor, | 151 constructor, |
| 157 IndexConstants.NAME_IS_DEFINED_BY, | 152 IndexConstants.NAME_IS_DEFINED_BY, |
| 158 MatchKind.DECLARATION); | 153 MatchKind.DECLARATION); |
| 159 requestor.add( | 154 requestor.add( |
| 160 constructor, | 155 constructor, |
| 161 IndexConstants.IS_REFERENCED_BY, | 156 IndexConstants.IS_REFERENCED_BY, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 188 _Requestor requestor = new _Requestor(_index); | 183 _Requestor requestor = new _Requestor(_index); |
| 189 requestor.add( | 184 requestor.add( |
| 190 function, | 185 function, |
| 191 IndexConstants.IS_REFERENCED_BY, | 186 IndexConstants.IS_REFERENCED_BY, |
| 192 MatchKind.REFERENCE); | 187 MatchKind.REFERENCE); |
| 193 requestor.add(function, IndexConstants.IS_INVOKED_BY, MatchKind.INVOCATION); | 188 requestor.add(function, IndexConstants.IS_INVOKED_BY, MatchKind.INVOCATION); |
| 194 return requestor.merge(); | 189 return requestor.merge(); |
| 195 } | 190 } |
| 196 | 191 |
| 197 Future<List<SearchMatch>> | 192 Future<List<SearchMatch>> |
| 198 _searchReferences_FunctionTypeAlias(FunctionTypeAliasElement alias) { | |
| 199 _Requestor requestor = new _Requestor(_index); | |
| 200 requestor.add(alias, IndexConstants.IS_REFERENCED_BY, MatchKind.REFERENCE); | |
| 201 return requestor.merge(); | |
| 202 } | |
| 203 | |
| 204 Future<List<SearchMatch>> _searchReferences_Import(ImportElement imp) { | |
| 205 _Requestor requestor = new _Requestor(_index); | |
| 206 requestor.add(imp, IndexConstants.IS_REFERENCED_BY, MatchKind.REFERENCE); | |
| 207 return requestor.merge(); | |
| 208 } | |
| 209 | |
| 210 Future<List<SearchMatch>> _searchReferences_Label(LabelElement variable) { | |
| 211 _Requestor requestor = new _Requestor(_index); | |
| 212 requestor.add( | |
| 213 variable, | |
| 214 IndexConstants.IS_REFERENCED_BY, | |
| 215 MatchKind.REFERENCE); | |
| 216 return requestor.merge(); | |
| 217 } | |
| 218 | |
| 219 Future<List<SearchMatch>> _searchReferences_Library(LibraryElement library) { | |
| 220 _Requestor requestor = new _Requestor(_index); | |
| 221 requestor.add( | |
| 222 library, | |
| 223 IndexConstants.IS_REFERENCED_BY, | |
| 224 MatchKind.REFERENCE); | |
| 225 return requestor.merge(); | |
| 226 } | |
| 227 | |
| 228 Future<List<SearchMatch>> | |
| 229 _searchReferences_LocalVariable(LocalVariableElement variable) { | 193 _searchReferences_LocalVariable(LocalVariableElement variable) { |
| 230 _Requestor requestor = new _Requestor(_index); | 194 _Requestor requestor = new _Requestor(_index); |
| 231 requestor.add(variable, IndexConstants.IS_READ_BY, MatchKind.READ); | 195 requestor.add(variable, IndexConstants.IS_READ_BY, MatchKind.READ); |
| 232 requestor.add( | 196 requestor.add( |
| 233 variable, | 197 variable, |
| 234 IndexConstants.IS_READ_WRITTEN_BY, | 198 IndexConstants.IS_READ_WRITTEN_BY, |
| 235 MatchKind.READ_WRITE); | 199 MatchKind.READ_WRITE); |
| 236 requestor.add(variable, IndexConstants.IS_WRITTEN_BY, MatchKind.WRITE); | 200 requestor.add(variable, IndexConstants.IS_WRITTEN_BY, MatchKind.WRITE); |
| 237 requestor.add(variable, IndexConstants.IS_INVOKED_BY, MatchKind.INVOCATION); | 201 requestor.add(variable, IndexConstants.IS_INVOKED_BY, MatchKind.INVOCATION); |
| 238 return requestor.merge(); | 202 return requestor.merge(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 260 requestor.add( | 224 requestor.add( |
| 261 parameter, | 225 parameter, |
| 262 IndexConstants.IS_REFERENCED_BY, | 226 IndexConstants.IS_REFERENCED_BY, |
| 263 MatchKind.REFERENCE); | 227 MatchKind.REFERENCE); |
| 264 requestor.add( | 228 requestor.add( |
| 265 parameter, | 229 parameter, |
| 266 IndexConstants.IS_INVOKED_BY, | 230 IndexConstants.IS_INVOKED_BY, |
| 267 MatchKind.INVOCATION); | 231 MatchKind.INVOCATION); |
| 268 return requestor.merge(); | 232 return requestor.merge(); |
| 269 } | 233 } |
| 270 | |
| 271 Future<List<SearchMatch>> | |
| 272 _searchReferences_PropertyAccessor(PropertyAccessorElement accessor) { | |
| 273 _Requestor requestor = new _Requestor(_index); | |
| 274 requestor.add( | |
| 275 accessor, | |
| 276 IndexConstants.IS_REFERENCED_BY, | |
| 277 MatchKind.REFERENCE); | |
| 278 return requestor.merge(); | |
| 279 } | |
| 280 | |
| 281 Future<List<SearchMatch>> | |
| 282 _searchReferences_TypeParameter(TypeParameterElement typeParameter) { | |
| 283 _Requestor requestor = new _Requestor(_index); | |
| 284 requestor.add( | |
| 285 typeParameter, | |
| 286 IndexConstants.IS_REFERENCED_BY, | |
| 287 MatchKind.REFERENCE); | |
| 288 return requestor.merge(); | |
| 289 } | |
| 290 } | 234 } |
| 291 | 235 |
| 292 | 236 |
| 293 class _Requestor { | 237 class _Requestor { |
| 294 final List<Future<List<SearchMatch>>> futures = <Future<List<SearchMatch>>>[]; | 238 final List<Future<List<SearchMatch>>> futures = <Future<List<SearchMatch>>>[]; |
| 295 final Index index; | 239 final Index index; |
| 296 | 240 |
| 297 _Requestor(this.index); | 241 _Requestor(this.index); |
| 298 | 242 |
| 299 void add(Element element, Relationship relationship, MatchKind kind) { | 243 void add(Element element, Relationship relationship, MatchKind kind) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 313 }); | 257 }); |
| 314 futures.add(matchesFuture); | 258 futures.add(matchesFuture); |
| 315 } | 259 } |
| 316 | 260 |
| 317 Future<List<SearchMatch>> merge() { | 261 Future<List<SearchMatch>> merge() { |
| 318 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { | 262 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { |
| 319 return matchesList.expand((matches) => matches).toList(); | 263 return matchesList.expand((matches) => matches).toList(); |
| 320 }); | 264 }); |
| 321 } | 265 } |
| 322 } | 266 } |
| OLD | NEW |