Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // This code was auto-generated, is not intended to be edited, and is subject to | |
| 6 // significant change. Please see the README file for more information. | |
| 7 | |
| 8 library engine.search_engine; | |
| 9 | |
| 10 import 'dart:async'; | |
| 11 | |
| 12 import 'package:analyzer/src/generated/element.dart'; | |
| 13 import 'package:analyzer/src/generated/java_core.dart'; | |
| 14 import 'package:analyzer/src/generated/source.dart'; | |
| 15 | |
| 16 | |
| 17 /** | |
| 18 * A [Comparator] that can be used to sort the [SearchMatch]s based on the names | |
| 19 * of the matched elements. | |
| 20 */ | |
| 21 final Comparator<SearchMatch> SEARCH_MATCH_NAME_COMPARATOR = | |
| 22 (SearchMatch firstMatch, SearchMatch secondMatch) { | |
| 23 String firstName = firstMatch.element.displayName; | |
| 24 String secondName = secondMatch.element.displayName; | |
| 25 return firstName.compareTo(secondName); | |
| 26 }; | |
| 27 | |
| 28 | |
| 29 /** | |
| 30 * Instances of the enum [MatchKind] represent the kind of reference that was | |
| 31 * found when a match represents a reference to an element. | |
| 32 */ | |
| 33 class MatchKind extends Enum<MatchKind> { | |
| 34 /** | |
| 35 * A reference to an Angular element. | |
| 36 */ | |
| 37 static const MatchKind ANGULAR_REFERENCE = const MatchKind( | |
| 38 'ANGULAR_REFERENCE', 0); | |
| 39 | |
| 40 /** | |
| 41 * A reference to an Angular element. | |
| 42 */ | |
| 43 static const MatchKind ANGULAR_CLOSING_TAG_REFERENCE = const MatchKind( | |
| 44 'ANGULAR_CLOSING_TAG_REFERENCE', 1); | |
| 45 | |
| 46 /** | |
| 47 * A declaration of a class. | |
| 48 */ | |
| 49 static const MatchKind CLASS_DECLARATION = const MatchKind( | |
| 50 'CLASS_DECLARATION', 2); | |
| 51 | |
| 52 /** | |
| 53 * A declaration of a class alias. | |
| 54 */ | |
| 55 static const MatchKind CLASS_ALIAS_DECLARATION = const MatchKind( | |
| 56 'CLASS_ALIAS_DECLARATION', 3); | |
| 57 | |
| 58 /** | |
| 59 * A declaration of a constructor. | |
| 60 */ | |
| 61 static const MatchKind CONSTRUCTOR_DECLARATION = const MatchKind( | |
| 62 'CONSTRUCTOR_DECLARATION', 4); | |
| 63 | |
| 64 /** | |
| 65 * A reference to a constructor in which the constructor is being referenced. | |
| 66 */ | |
| 67 static const MatchKind CONSTRUCTOR_REFERENCE = const MatchKind( | |
| 68 'CONSTRUCTOR_REFERENCE', 5); | |
| 69 | |
| 70 /** | |
| 71 * A reference to a type in which the type was extended. | |
| 72 */ | |
| 73 static const MatchKind EXTENDS_REFERENCE = const MatchKind( | |
| 74 'EXTENDS_REFERENCE', 6); | |
| 75 | |
| 76 /** | |
| 77 * A reference to a field in which the field's value is being invoked. | |
| 78 */ | |
| 79 static const MatchKind FIELD_INVOCATION = const MatchKind('FIELD_INVOCATION', | |
| 80 7); | |
| 81 | |
| 82 /** | |
| 83 * A reference to a field (from field formal parameter). | |
| 84 */ | |
| 85 static const MatchKind FIELD_REFERENCE = const MatchKind('FIELD_REFERENCE', | |
| 86 8); | |
| 87 | |
| 88 /** | |
| 89 * A reference to a field in which the field's value is being read. | |
| 90 */ | |
| 91 static const MatchKind FIELD_READ = const MatchKind('FIELD_READ', 9); | |
| 92 | |
| 93 /** | |
| 94 * A reference to a field in which the field's value is being written. | |
| 95 */ | |
| 96 static const MatchKind FIELD_WRITE = const MatchKind('FIELD_WRITE', 10); | |
| 97 | |
| 98 /** | |
| 99 * A declaration of a function. | |
| 100 */ | |
| 101 static const MatchKind FUNCTION_DECLARATION = const MatchKind( | |
| 102 'FUNCTION_DECLARATION', 11); | |
| 103 | |
| 104 /** | |
| 105 * A reference to a function in which the function is being executed. | |
| 106 */ | |
| 107 static const MatchKind FUNCTION_EXECUTION = const MatchKind( | |
| 108 'FUNCTION_EXECUTION', 12); | |
| 109 | |
| 110 /** | |
| 111 * A reference to a function in which the function is being referenced. | |
| 112 */ | |
| 113 static const MatchKind FUNCTION_REFERENCE = const MatchKind( | |
| 114 'FUNCTION_REFERENCE', 13); | |
| 115 | |
| 116 /** | |
| 117 * A declaration of a function type. | |
| 118 */ | |
| 119 static const MatchKind FUNCTION_TYPE_DECLARATION = const MatchKind( | |
| 120 'FUNCTION_TYPE_DECLARATION', 14); | |
| 121 | |
| 122 /** | |
| 123 * A reference to a function type. | |
| 124 */ | |
| 125 static const MatchKind FUNCTION_TYPE_REFERENCE = const MatchKind( | |
| 126 'FUNCTION_TYPE_REFERENCE', 15); | |
| 127 | |
| 128 /** | |
| 129 * A reference to a type in which the type was implemented. | |
| 130 */ | |
| 131 static const MatchKind IMPLEMENTS_REFERENCE = const MatchKind( | |
| 132 'IMPLEMENTS_REFERENCE', 16); | |
| 133 | |
| 134 /** | |
| 135 * A reference to a [ImportElement]. | |
| 136 */ | |
| 137 static const MatchKind IMPORT_REFERENCE = const MatchKind('IMPORT_REFERENCE', | |
| 138 17); | |
| 139 | |
| 140 /** | |
| 141 * A reference to a class that is implementing a specified type. | |
| 142 */ | |
| 143 static const MatchKind INTERFACE_IMPLEMENTED = const MatchKind( | |
| 144 'INTERFACE_IMPLEMENTED', 18); | |
| 145 | |
| 146 /** | |
| 147 * A reference to a [LibraryElement]. | |
| 148 */ | |
| 149 static const MatchKind LIBRARY_REFERENCE = const MatchKind( | |
| 150 'LIBRARY_REFERENCE', 19); | |
| 151 | |
| 152 /** | |
| 153 * A reference to a method in which the method is being invoked. | |
| 154 */ | |
| 155 static const MatchKind METHOD_INVOCATION = const MatchKind( | |
| 156 'METHOD_INVOCATION', 20); | |
| 157 | |
| 158 /** | |
| 159 * A reference to a method in which the method is being referenced. | |
| 160 */ | |
| 161 static const MatchKind METHOD_REFERENCE = const MatchKind('METHOD_REFERENCE', | |
| 162 21); | |
| 163 | |
| 164 /** | |
| 165 * A declaration of a name. | |
| 166 */ | |
| 167 static const MatchKind NAME_DECLARATION = const MatchKind('NAME_DECLARATION', | |
| 168 22); | |
| 169 | |
| 170 /** | |
| 171 * A reference to a name, resolved. | |
| 172 */ | |
| 173 static const MatchKind NAME_REFERENCE_RESOLVED = const MatchKind( | |
| 174 'NAME_REFERENCE_RESOLVED', 23); | |
| 175 | |
| 176 /** | |
| 177 * An invocation of a name, resolved. | |
| 178 */ | |
| 179 static const MatchKind NAME_INVOCATION_RESOLVED = const MatchKind( | |
| 180 'NAME_INVOCATION_RESOLVED', 24); | |
| 181 | |
| 182 /** | |
| 183 * A reference to a name in which the name's value is being read. | |
| 184 */ | |
| 185 static const MatchKind NAME_READ_RESOLVED = const MatchKind( | |
| 186 'NAME_READ_RESOLVED', 25); | |
| 187 | |
| 188 /** | |
| 189 * A reference to a name in which the name's value is being read and written. | |
| 190 */ | |
| 191 static const MatchKind NAME_READ_WRITE_RESOLVED = const MatchKind( | |
| 192 'NAME_READ_WRITE_RESOLVED', 26); | |
| 193 | |
| 194 /** | |
| 195 * A reference to a name in which the name's value is being written. | |
| 196 */ | |
| 197 static const MatchKind NAME_WRITE_RESOLVED = const MatchKind( | |
| 198 'NAME_WRITE_RESOLVED', 27); | |
| 199 | |
| 200 /** | |
| 201 * An invocation of a name, unresolved. | |
| 202 */ | |
| 203 static const MatchKind NAME_INVOCATION_UNRESOLVED = const MatchKind( | |
| 204 'NAME_INVOCATION_UNRESOLVED', 28); | |
| 205 | |
| 206 /** | |
| 207 * A reference to a name in which the name's value is being read. | |
| 208 */ | |
| 209 static const MatchKind NAME_READ_UNRESOLVED = const MatchKind( | |
| 210 'NAME_READ_UNRESOLVED', 29); | |
| 211 | |
| 212 /** | |
| 213 * A reference to a name in which the name's value is being read and written. | |
| 214 */ | |
| 215 static const MatchKind NAME_READ_WRITE_UNRESOLVED = const MatchKind( | |
| 216 'NAME_READ_WRITE_UNRESOLVED', 30); | |
| 217 | |
| 218 /** | |
| 219 * A reference to a name in which the name's value is being written. | |
| 220 */ | |
| 221 static const MatchKind NAME_WRITE_UNRESOLVED = const MatchKind( | |
| 222 'NAME_WRITE_UNRESOLVED', 31); | |
| 223 | |
| 224 /** | |
| 225 * A reference to a name, unresolved. | |
| 226 */ | |
| 227 static const MatchKind NAME_REFERENCE_UNRESOLVED = const MatchKind( | |
| 228 'NAME_REFERENCE_UNRESOLVED', 32); | |
| 229 | |
| 230 /** | |
| 231 * A reference to a named parameter in invocation. | |
| 232 */ | |
| 233 static const MatchKind NAMED_PARAMETER_REFERENCE = const MatchKind( | |
| 234 'NAMED_PARAMETER_REFERENCE', 33); | |
| 235 | |
| 236 /** | |
| 237 * A reference to a property accessor. | |
| 238 */ | |
| 239 static const MatchKind PROPERTY_ACCESSOR_REFERENCE = const MatchKind( | |
| 240 'PROPERTY_ACCESSOR_REFERENCE', 34); | |
| 241 | |
| 242 /** | |
| 243 * A reference to a type. | |
| 244 */ | |
| 245 static const MatchKind TYPE_REFERENCE = const MatchKind('TYPE_REFERENCE', 35); | |
| 246 | |
| 247 /** | |
| 248 * A reference to a type parameter. | |
| 249 */ | |
| 250 static const MatchKind TYPE_PARAMETER_REFERENCE = const MatchKind( | |
| 251 'TYPE_PARAMETER_REFERENCE', 36); | |
| 252 | |
| 253 /** | |
| 254 * A reference to a [CompilationUnitElement]. | |
| 255 */ | |
| 256 static const MatchKind UNIT_REFERENCE = const MatchKind('UNIT_REFERENCE', 37); | |
| 257 | |
| 258 /** | |
| 259 * A declaration of a variable. | |
| 260 */ | |
| 261 static const MatchKind VARIABLE_DECLARATION = const MatchKind( | |
| 262 'VARIABLE_DECLARATION', 38); | |
| 263 | |
| 264 /** | |
| 265 * A reference to a variable in which the variable's value is being read. | |
| 266 */ | |
| 267 static const MatchKind VARIABLE_READ = const MatchKind('VARIABLE_READ', 39); | |
| 268 | |
| 269 /** | |
| 270 * A reference to a variable in which the variable's value is being both read | |
| 271 * and write. | |
| 272 */ | |
| 273 static const MatchKind VARIABLE_READ_WRITE = const MatchKind( | |
| 274 'VARIABLE_READ_WRITE', 40); | |
| 275 | |
| 276 /** | |
| 277 * A reference to a variable in which the variables's value is being written. | |
| 278 */ | |
| 279 static const MatchKind VARIABLE_WRITE = const MatchKind('VARIABLE_WRITE', 41); | |
| 280 | |
| 281 /** | |
| 282 * A reference to a type in which the type was mixed in. | |
| 283 */ | |
| 284 static const MatchKind WITH_REFERENCE = const MatchKind('WITH_REFERENCE', 42); | |
| 285 | |
| 286 static const List<MatchKind> values = const [ANGULAR_REFERENCE, | |
| 287 ANGULAR_CLOSING_TAG_REFERENCE, CLASS_DECLARATION, CLASS_ALIAS_DECLARATION, | |
| 288 CONSTRUCTOR_DECLARATION, CONSTRUCTOR_REFERENCE, EXTENDS_REFERENCE, | |
| 289 FIELD_INVOCATION, FIELD_REFERENCE, FIELD_READ, FIELD_WRITE, | |
| 290 FUNCTION_DECLARATION, FUNCTION_EXECUTION, FUNCTION_REFERENCE, | |
| 291 FUNCTION_TYPE_DECLARATION, FUNCTION_TYPE_REFERENCE, IMPLEMENTS_REFERENCE, | |
| 292 IMPORT_REFERENCE, INTERFACE_IMPLEMENTED, LIBRARY_REFERENCE, METHOD_INVOCAT ION, | |
| 293 METHOD_REFERENCE, NAME_DECLARATION, NAME_REFERENCE_RESOLVED, | |
| 294 NAME_INVOCATION_RESOLVED, NAME_READ_RESOLVED, NAME_READ_WRITE_RESOLVED, | |
| 295 NAME_WRITE_RESOLVED, NAME_INVOCATION_UNRESOLVED, NAME_READ_UNRESOLVED, | |
| 296 NAME_READ_WRITE_UNRESOLVED, NAME_WRITE_UNRESOLVED, NAME_REFERENCE_UNRESOLV ED, | |
| 297 NAMED_PARAMETER_REFERENCE, PROPERTY_ACCESSOR_REFERENCE, TYPE_REFERENCE, | |
| 298 TYPE_PARAMETER_REFERENCE, UNIT_REFERENCE, VARIABLE_DECLARATION, VARIABLE_R EAD, | |
| 299 VARIABLE_READ_WRITE, VARIABLE_WRITE, WITH_REFERENCE]; | |
| 300 | |
| 301 const MatchKind(String name, int ordinal) : super(name, ordinal); | |
| 302 } | |
| 303 | |
| 304 | |
| 305 /** | |
| 306 * The interface [SearchEngine] defines the behavior of objects that can be used | |
| 307 * to search for various pieces of information. | |
| 308 */ | |
| 309 abstract class SearchEngine { | |
| 310 // /** | |
| 311 // * Returns types assigned to the given field or top-level variable. | |
| 312 // * | |
| 313 // * [variable] - the field or top-level variable to find assigned types for. | |
| 314 // */ | |
| 315 // Future<Set<DartType>> searchAssignedTypes(PropertyInducingElement variable); | |
| 316 | |
| 317 /** | |
| 318 * Returns declarations of class members with the given name. | |
| 319 * | |
| 320 * [name] - the name being declared by the found matches. | |
| 321 */ | |
| 322 Future<List<SearchMatch>> searchMemberDeclarations(String name); | |
| 323 | |
| 324 /** | |
| 325 * Returns all resolved and unresolved qualified references to the class | |
| 326 * members with given [name]. | |
| 327 * | |
| 328 * [name] - the name being referenced by the found matches. | |
| 329 */ | |
| 330 Future<List<SearchMatch>> searchMemberReferences(String name); | |
| 331 | |
| 332 /** | |
| 333 * Returns references to the given [Element]. | |
| 334 * | |
| 335 * [element] - the [Element] being referenced by the found matches. | |
| 336 */ | |
| 337 Future<List<SearchMatch>> searchReferences(Element element); | |
| 338 | |
| 339 /** | |
| 340 * Returns subtypes of the given [type]. | |
| 341 * | |
| 342 * [type] - the [ClassElemnet] being subtyped by the found matches. | |
| 343 */ | |
| 344 Future<List<SearchMatch>> searchSubtypes(ClassElement type); | |
| 345 | |
| 346 /** | |
| 347 * Returns all the top-level declarations matching the given pattern. | |
| 348 * | |
| 349 * [pattern] the regular expression used to match the names of the | |
| 350 * declarations to be found. | |
| 351 */ | |
| 352 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern); | |
| 353 } | |
| 354 | |
| 355 /** | |
| 356 * Instances of the class [SearchMatch] represent a match found by | |
| 357 * [SearchEngine]. | |
| 358 */ | |
| 359 class SearchMatch { | |
| 360 /** | |
| 361 * The kind of the match. | |
| 362 */ | |
| 363 final MatchKind kind; | |
| 364 | |
| 365 /** | |
| 366 * The element containing the source range that was matched. | |
| 367 */ | |
| 368 final Element element; | |
| 369 | |
| 370 /** | |
| 371 * The source range that was matched. | |
| 372 */ | |
| 373 final SourceRange sourceRange; | |
| 374 | |
| 375 /** | |
| 376 * Is `true` if the match is a resolved reference to some [Element]. | |
| 377 */ | |
| 378 final bool isResolved; | |
| 379 | |
| 380 /** | |
| 381 * Is `true` if field or method access is done using qualifier. | |
| 382 */ | |
| 383 bool qualified = false; | |
| 384 | |
| 385 SearchMatch(this.kind, this.element, this.sourceRange, this.isResolved); | |
| 386 | |
| 387 @override | |
| 388 int get hashCode => JavaArrays.makeHashCode([element, sourceRange, kind]); | |
| 389 | |
| 390 @override | |
| 391 bool operator ==(Object obj) { | |
|
Brian Wilkerson
2014/07/03 18:58:13
nit: "obj" --> "object"
scheglov
2014/07/03 19:06:16
Done.
| |
| 392 if (obj is! SearchMatch) { | |
| 393 return false; | |
| 394 } | |
| 395 if (identical(obj, this)) { | |
| 396 return true; | |
| 397 } | |
| 398 SearchMatch o = obj as SearchMatch; | |
|
Brian Wilkerson
2014/07/03 18:58:13
nit: "o" --> "match"
| |
| 399 return kind == o.kind && isResolved == o.isResolved && qualified == | |
| 400 o.qualified && sourceRange == o.sourceRange && element == o.element; | |
| 401 } | |
| 402 | |
| 403 @override | |
| 404 String toString() { | |
| 405 StringBuffer buffer = new StringBuffer(); | |
| 406 buffer.write("SearchMatch(kind="); | |
| 407 buffer.write(kind); | |
| 408 buffer.write(", isResolved="); | |
| 409 buffer.write(isResolved); | |
| 410 buffer.write(", element="); | |
| 411 buffer.write(element.displayName); | |
| 412 buffer.write(", range="); | |
| 413 buffer.write(sourceRange); | |
| 414 buffer.write(", qualified="); | |
| 415 buffer.write(qualified); | |
| 416 buffer.write(")"); | |
| 417 return buffer.toString(); | |
| 418 } | |
| 419 } | |
| OLD | NEW |