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.index.index_contributor; | 5 library services.src.index.index_contributor; |
6 | 6 |
7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
8 | 8 |
9 import 'package:analysis_server/analysis/index/index_core.dart'; | 9 import 'package:analysis_server/analysis/index/index_core.dart'; |
10 import 'package:analysis_server/analysis/index/index_dart.dart'; | 10 import 'package:analysis_server/analysis/index/index_dart.dart'; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return new IndexableElement(element); | 120 return new IndexableElement(element); |
121 } | 121 } |
122 } | 122 } |
123 return null; | 123 return null; |
124 } | 124 } |
125 | 125 |
126 /** | 126 /** |
127 * Record the given relationship between the given [Element] and | 127 * Record the given relationship between the given [Element] and |
128 * [LocationImpl]. | 128 * [LocationImpl]. |
129 */ | 129 */ |
130 void recordRelationship( | 130 void recordRelationshipElement( |
131 Element element, RelationshipImpl relationship, LocationImpl location) { | 131 Element element, RelationshipImpl relationship, LocationImpl location) { |
132 if (element != null && location != null) { | 132 if (element != null && location != null) { |
133 _store.recordRelationship( | 133 _store.recordRelationship( |
134 new IndexableElement(element), relationship, location); | 134 new IndexableElement(element), relationship, location); |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
| 138 /** |
| 139 * Record the given relationship between the given [IndexableObject] and |
| 140 * [LocationImpl]. |
| 141 */ |
| 142 void recordRelationshipIndexable(IndexableObject indexable, |
| 143 RelationshipImpl relationship, LocationImpl location) { |
| 144 if (indexable != null && location != null) { |
| 145 _store.recordRelationship(indexable, relationship, location); |
| 146 } |
| 147 } |
| 148 |
138 @override | 149 @override |
139 visitAssignmentExpression(AssignmentExpression node) { | 150 visitAssignmentExpression(AssignmentExpression node) { |
140 _recordOperatorReference(node.operator, node.bestElement); | 151 _recordOperatorReference(node.operator, node.bestElement); |
141 super.visitAssignmentExpression(node); | 152 super.visitAssignmentExpression(node); |
142 } | 153 } |
143 | 154 |
144 @override | 155 @override |
145 visitBinaryExpression(BinaryExpression node) { | 156 visitBinaryExpression(BinaryExpression node) { |
146 _recordOperatorReference(node.operator, node.bestElement); | 157 _recordOperatorReference(node.operator, node.bestElement); |
147 super.visitBinaryExpression(node); | 158 super.visitBinaryExpression(node); |
148 } | 159 } |
149 | 160 |
150 @override | 161 @override |
151 visitClassDeclaration(ClassDeclaration node) { | 162 visitClassDeclaration(ClassDeclaration node) { |
152 ClassElement element = node.element; | 163 ClassElement element = node.element; |
153 enterScope(element); | 164 enterScope(element); |
154 try { | 165 try { |
155 _recordTopLevelElementDefinition(element); | 166 _recordTopLevelElementDefinition(element); |
156 { | 167 { |
157 ExtendsClause extendsClause = node.extendsClause; | 168 ExtendsClause extendsClause = node.extendsClause; |
158 if (extendsClause != null) { | 169 if (extendsClause != null) { |
159 TypeName superclassNode = extendsClause.superclass; | 170 TypeName superclassNode = extendsClause.superclass; |
160 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); | 171 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); |
161 } else { | 172 } else { |
162 InterfaceType superType = element.supertype; | 173 InterfaceType superType = element.supertype; |
163 if (superType != null) { | 174 if (superType != null) { |
164 ClassElement objectElement = superType.element; | 175 ClassElement objectElement = superType.element; |
165 recordRelationship(objectElement, IndexConstants.IS_EXTENDED_BY, | 176 recordRelationshipElement( |
| 177 objectElement, |
| 178 IndexConstants.IS_EXTENDED_BY, |
166 _createLocationForOffset(node.name.offset, 0)); | 179 _createLocationForOffset(node.name.offset, 0)); |
167 } | 180 } |
168 } | 181 } |
169 } | 182 } |
170 { | 183 { |
171 WithClause withClause = node.withClause; | 184 WithClause withClause = node.withClause; |
172 if (withClause != null) { | 185 if (withClause != null) { |
173 for (TypeName mixinNode in withClause.mixinTypes) { | 186 for (TypeName mixinNode in withClause.mixinTypes) { |
174 _recordSuperType(mixinNode, IndexConstants.IS_MIXED_IN_BY); | 187 _recordSuperType(mixinNode, IndexConstants.IS_MIXED_IN_BY); |
175 } | 188 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 260 } |
248 | 261 |
249 @override | 262 @override |
250 visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | 263 visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
251 SimpleIdentifier fieldName = node.fieldName; | 264 SimpleIdentifier fieldName = node.fieldName; |
252 Expression expression = node.expression; | 265 Expression expression = node.expression; |
253 // field reference is write here | 266 // field reference is write here |
254 if (fieldName != null) { | 267 if (fieldName != null) { |
255 Element element = fieldName.staticElement; | 268 Element element = fieldName.staticElement; |
256 LocationImpl location = _createLocationForNode(fieldName); | 269 LocationImpl location = _createLocationForNode(fieldName); |
257 recordRelationship(element, IndexConstants.IS_WRITTEN_BY, location); | 270 recordRelationshipElement( |
| 271 element, IndexConstants.IS_WRITTEN_BY, location); |
258 } | 272 } |
259 // index expression | 273 // index expression |
260 if (expression != null) { | 274 if (expression != null) { |
261 expression.accept(this); | 275 expression.accept(this); |
262 } | 276 } |
263 } | 277 } |
264 | 278 |
265 @override | 279 @override |
266 visitConstructorName(ConstructorName node) { | 280 visitConstructorName(ConstructorName node) { |
267 ConstructorElement element = node.staticElement; | 281 ConstructorElement element = node.staticElement; |
268 // in 'class B = A;' actually A constructors are invoked | 282 // in 'class B = A;' actually A constructors are invoked |
269 if (element != null && | 283 if (element != null && |
270 element.isSynthetic && | 284 element.isSynthetic && |
271 element.redirectedConstructor != null) { | 285 element.redirectedConstructor != null) { |
272 element = element.redirectedConstructor; | 286 element = element.redirectedConstructor; |
273 } | 287 } |
274 // prepare location | 288 // prepare location |
275 LocationImpl location; | 289 LocationImpl location; |
276 if (node.name != null) { | 290 if (node.name != null) { |
277 int start = node.period.offset; | 291 int start = node.period.offset; |
278 int end = node.name.end; | 292 int end = node.name.end; |
279 location = _createLocationForOffset(start, end - start); | 293 location = _createLocationForOffset(start, end - start); |
280 } else { | 294 } else { |
281 int start = node.type.end; | 295 int start = node.type.end; |
282 location = _createLocationForOffset(start, 0); | 296 location = _createLocationForOffset(start, 0); |
283 } | 297 } |
284 // record relationship | 298 // record relationship |
285 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 299 recordRelationshipElement( |
| 300 element, IndexConstants.IS_REFERENCED_BY, location); |
286 super.visitConstructorName(node); | 301 super.visitConstructorName(node); |
287 } | 302 } |
288 | 303 |
289 @override | 304 @override |
290 visitDeclaredIdentifier(DeclaredIdentifier node) { | 305 visitDeclaredIdentifier(DeclaredIdentifier node) { |
291 LocalVariableElement element = node.element; | 306 LocalVariableElement element = node.element; |
292 enterScope(element); | 307 enterScope(element); |
293 try { | 308 try { |
294 super.visitDeclaredIdentifier(node); | 309 super.visitDeclaredIdentifier(node); |
295 } finally { | 310 } finally { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 super.visitImportDirective(node); | 374 super.visitImportDirective(node); |
360 } | 375 } |
361 | 376 |
362 @override | 377 @override |
363 visitIndexExpression(IndexExpression node) { | 378 visitIndexExpression(IndexExpression node) { |
364 MethodElement element = node.bestElement; | 379 MethodElement element = node.bestElement; |
365 if (element is MethodElement) { | 380 if (element is MethodElement) { |
366 Token operator = node.leftBracket; | 381 Token operator = node.leftBracket; |
367 LocationImpl location = | 382 LocationImpl location = |
368 _createLocationForToken(operator, element != null); | 383 _createLocationForToken(operator, element != null); |
369 recordRelationship(element, IndexConstants.IS_INVOKED_BY, location); | 384 recordRelationshipElement( |
| 385 element, IndexConstants.IS_INVOKED_BY, location); |
370 } | 386 } |
371 super.visitIndexExpression(node); | 387 super.visitIndexExpression(node); |
372 } | 388 } |
373 | 389 |
374 @override | 390 @override |
375 visitMethodDeclaration(MethodDeclaration node) { | 391 visitMethodDeclaration(MethodDeclaration node) { |
376 ExecutableElement element = node.element; | 392 ExecutableElement element = node.element; |
377 enterScope(element); | 393 enterScope(element); |
378 try { | 394 try { |
379 super.visitMethodDeclaration(node); | 395 super.visitMethodDeclaration(node); |
380 } finally { | 396 } finally { |
381 _exitScope(); | 397 _exitScope(); |
382 } | 398 } |
383 } | 399 } |
384 | 400 |
385 @override | 401 @override |
386 visitMethodInvocation(MethodInvocation node) { | 402 visitMethodInvocation(MethodInvocation node) { |
387 SimpleIdentifier name = node.methodName; | 403 SimpleIdentifier name = node.methodName; |
388 LocationImpl location = _createLocationForNode(name); | 404 LocationImpl location = _createLocationForNode(name); |
| 405 // name invocation |
| 406 recordRelationshipIndexable( |
| 407 new IndexableName(name.name), IndexConstants.IS_INVOKED_BY, location); |
389 // element invocation | 408 // element invocation |
390 Element element = name.bestElement; | 409 Element element = name.bestElement; |
391 if (element is MethodElement || | 410 if (element is MethodElement || |
392 element is PropertyAccessorElement || | 411 element is PropertyAccessorElement || |
393 element is FunctionElement || | 412 element is FunctionElement || |
394 element is VariableElement) { | 413 element is VariableElement) { |
395 recordRelationship(element, IndexConstants.IS_INVOKED_BY, location); | 414 recordRelationshipElement( |
396 } | 415 element, IndexConstants.IS_INVOKED_BY, location); |
397 // name invocation | |
398 { | |
399 recordRelationship( | |
400 new NameElement(name.name), IndexConstants.IS_INVOKED_BY, location); | |
401 } | 416 } |
402 _recordImportElementReferenceWithoutPrefix(name); | 417 _recordImportElementReferenceWithoutPrefix(name); |
403 super.visitMethodInvocation(node); | 418 super.visitMethodInvocation(node); |
404 } | 419 } |
405 | 420 |
406 @override | 421 @override |
407 visitPartDirective(PartDirective node) { | 422 visitPartDirective(PartDirective node) { |
408 Element element = node.element; | 423 Element element = node.element; |
409 LocationImpl location = _createLocationForNode(node.uri); | 424 LocationImpl location = _createLocationForNode(node.uri); |
410 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 425 recordRelationshipElement( |
| 426 element, IndexConstants.IS_REFERENCED_BY, location); |
411 super.visitPartDirective(node); | 427 super.visitPartDirective(node); |
412 } | 428 } |
413 | 429 |
414 @override | 430 @override |
415 visitPartOfDirective(PartOfDirective node) { | 431 visitPartOfDirective(PartOfDirective node) { |
416 LocationImpl location = _createLocationForNode(node.libraryName); | 432 LocationImpl location = _createLocationForNode(node.libraryName); |
417 recordRelationship(node.element, IndexConstants.IS_REFERENCED_BY, location); | 433 recordRelationshipElement( |
| 434 node.element, IndexConstants.IS_REFERENCED_BY, location); |
418 } | 435 } |
419 | 436 |
420 @override | 437 @override |
421 visitPostfixExpression(PostfixExpression node) { | 438 visitPostfixExpression(PostfixExpression node) { |
422 _recordOperatorReference(node.operator, node.bestElement); | 439 _recordOperatorReference(node.operator, node.bestElement); |
423 super.visitPostfixExpression(node); | 440 super.visitPostfixExpression(node); |
424 } | 441 } |
425 | 442 |
426 @override | 443 @override |
427 visitPrefixExpression(PrefixExpression node) { | 444 visitPrefixExpression(PrefixExpression node) { |
428 _recordOperatorReference(node.operator, node.bestElement); | 445 _recordOperatorReference(node.operator, node.bestElement); |
429 super.visitPrefixExpression(node); | 446 super.visitPrefixExpression(node); |
430 } | 447 } |
431 | 448 |
432 @override | 449 @override |
433 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { | 450 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { |
434 ConstructorElement element = node.staticElement; | 451 ConstructorElement element = node.staticElement; |
435 LocationImpl location; | 452 LocationImpl location; |
436 if (node.constructorName != null) { | 453 if (node.constructorName != null) { |
437 int start = node.period.offset; | 454 int start = node.period.offset; |
438 int end = node.constructorName.end; | 455 int end = node.constructorName.end; |
439 location = _createLocationForOffset(start, end - start); | 456 location = _createLocationForOffset(start, end - start); |
440 } else { | 457 } else { |
441 int start = node.thisKeyword.end; | 458 int start = node.thisKeyword.end; |
442 location = _createLocationForOffset(start, 0); | 459 location = _createLocationForOffset(start, 0); |
443 } | 460 } |
444 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 461 recordRelationshipElement( |
| 462 element, IndexConstants.IS_REFERENCED_BY, location); |
445 super.visitRedirectingConstructorInvocation(node); | 463 super.visitRedirectingConstructorInvocation(node); |
446 } | 464 } |
447 | 465 |
448 @override | 466 @override |
449 visitSimpleIdentifier(SimpleIdentifier node) { | 467 visitSimpleIdentifier(SimpleIdentifier node) { |
450 NameElement nameElement = new NameElement(node.name); | 468 IndexableName indexableName = new IndexableName(node.name); |
451 LocationImpl location = _createLocationForNode(node); | 469 LocationImpl location = _createLocationForNode(node); |
452 if (location == null) { | 470 if (location == null) { |
453 return; | 471 return; |
454 } | 472 } |
455 // name in declaration | 473 // name in declaration |
456 if (node.inDeclarationContext()) { | 474 if (node.inDeclarationContext()) { |
457 recordRelationship( | 475 recordRelationshipIndexable( |
458 nameElement, IndexConstants.NAME_IS_DEFINED_BY, location); | 476 indexableName, IndexConstants.NAME_IS_DEFINED_BY, location); |
459 return; | 477 return; |
460 } | 478 } |
461 // prepare information | 479 // prepare information |
462 Element element = node.bestElement; | 480 Element element = node.bestElement; |
463 // stop if already handled | 481 // stop if already handled |
464 if (_isAlreadyHandledName(node)) { | 482 if (_isAlreadyHandledName(node)) { |
465 return; | 483 return; |
466 } | 484 } |
467 // record name read/write | 485 // record name read/write |
468 if (element != null && element.enclosingElement is ClassElement || | 486 if (element != null && element.enclosingElement is ClassElement || |
469 element == null && location.isQualified) { | 487 element == null && location.isQualified) { |
470 bool inGetterContext = node.inGetterContext(); | 488 bool inGetterContext = node.inGetterContext(); |
471 bool inSetterContext = node.inSetterContext(); | 489 bool inSetterContext = node.inSetterContext(); |
472 if (inGetterContext && inSetterContext) { | 490 if (inGetterContext && inSetterContext) { |
473 recordRelationship( | 491 recordRelationshipIndexable( |
474 nameElement, IndexConstants.IS_READ_WRITTEN_BY, location); | 492 indexableName, IndexConstants.IS_READ_WRITTEN_BY, location); |
475 } else if (inGetterContext) { | 493 } else if (inGetterContext) { |
476 recordRelationship(nameElement, IndexConstants.IS_READ_BY, location); | 494 recordRelationshipIndexable( |
| 495 indexableName, IndexConstants.IS_READ_BY, location); |
477 } else if (inSetterContext) { | 496 } else if (inSetterContext) { |
478 recordRelationship(nameElement, IndexConstants.IS_WRITTEN_BY, location); | 497 recordRelationshipIndexable( |
| 498 indexableName, IndexConstants.IS_WRITTEN_BY, location); |
479 } | 499 } |
480 } | 500 } |
481 // this.field parameter | 501 // this.field parameter |
482 if (element is FieldFormalParameterElement) { | 502 if (element is FieldFormalParameterElement) { |
483 RelationshipImpl relationship = peekElement().element == element | 503 RelationshipImpl relationship = peekElement().element == element |
484 ? IndexConstants.IS_WRITTEN_BY | 504 ? IndexConstants.IS_WRITTEN_BY |
485 : IndexConstants.IS_REFERENCED_BY; | 505 : IndexConstants.IS_REFERENCED_BY; |
486 recordRelationship(element.field, relationship, location); | 506 recordRelationshipElement(element.field, relationship, location); |
487 return; | 507 return; |
488 } | 508 } |
489 // record specific relations | 509 // record specific relations |
490 if (element is ClassElement || | 510 if (element is ClassElement || |
491 element is FunctionElement || | 511 element is FunctionElement || |
492 element is FunctionTypeAliasElement || | 512 element is FunctionTypeAliasElement || |
493 element is LabelElement || | 513 element is LabelElement || |
494 element is MethodElement || | 514 element is MethodElement || |
495 element is PropertyAccessorElement || | 515 element is PropertyAccessorElement || |
496 element is PropertyInducingElement || | 516 element is PropertyInducingElement || |
497 element is TypeParameterElement) { | 517 element is TypeParameterElement) { |
498 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 518 recordRelationshipElement( |
| 519 element, IndexConstants.IS_REFERENCED_BY, location); |
499 } else if (element is PrefixElement) { | 520 } else if (element is PrefixElement) { |
500 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 521 recordRelationshipElement( |
| 522 element, IndexConstants.IS_REFERENCED_BY, location); |
501 _recordImportElementReferenceWithPrefix(node); | 523 _recordImportElementReferenceWithPrefix(node); |
502 } else if (element is ParameterElement || element is LocalVariableElement) { | 524 } else if (element is ParameterElement || element is LocalVariableElement) { |
503 bool inGetterContext = node.inGetterContext(); | 525 bool inGetterContext = node.inGetterContext(); |
504 bool inSetterContext = node.inSetterContext(); | 526 bool inSetterContext = node.inSetterContext(); |
505 if (inGetterContext && inSetterContext) { | 527 if (inGetterContext && inSetterContext) { |
506 recordRelationship( | 528 recordRelationshipElement( |
507 element, IndexConstants.IS_READ_WRITTEN_BY, location); | 529 element, IndexConstants.IS_READ_WRITTEN_BY, location); |
508 } else if (inGetterContext) { | 530 } else if (inGetterContext) { |
509 recordRelationship(element, IndexConstants.IS_READ_BY, location); | 531 recordRelationshipElement(element, IndexConstants.IS_READ_BY, location); |
510 } else if (inSetterContext) { | 532 } else if (inSetterContext) { |
511 recordRelationship(element, IndexConstants.IS_WRITTEN_BY, location); | 533 recordRelationshipElement( |
| 534 element, IndexConstants.IS_WRITTEN_BY, location); |
512 } else { | 535 } else { |
513 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 536 recordRelationshipElement( |
| 537 element, IndexConstants.IS_REFERENCED_BY, location); |
514 } | 538 } |
515 } | 539 } |
516 _recordImportElementReferenceWithoutPrefix(node); | 540 _recordImportElementReferenceWithoutPrefix(node); |
517 super.visitSimpleIdentifier(node); | 541 super.visitSimpleIdentifier(node); |
518 } | 542 } |
519 | 543 |
520 @override | 544 @override |
521 visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 545 visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
522 ConstructorElement element = node.staticElement; | 546 ConstructorElement element = node.staticElement; |
523 LocationImpl location; | 547 LocationImpl location; |
524 if (node.constructorName != null) { | 548 if (node.constructorName != null) { |
525 int start = node.period.offset; | 549 int start = node.period.offset; |
526 int end = node.constructorName.end; | 550 int end = node.constructorName.end; |
527 location = _createLocationForOffset(start, end - start); | 551 location = _createLocationForOffset(start, end - start); |
528 } else { | 552 } else { |
529 int start = node.superKeyword.end; | 553 int start = node.superKeyword.end; |
530 location = _createLocationForOffset(start, 0); | 554 location = _createLocationForOffset(start, 0); |
531 } | 555 } |
532 recordRelationship(element, IndexConstants.IS_REFERENCED_BY, location); | 556 recordRelationshipElement( |
| 557 element, IndexConstants.IS_REFERENCED_BY, location); |
533 super.visitSuperConstructorInvocation(node); | 558 super.visitSuperConstructorInvocation(node); |
534 } | 559 } |
535 | 560 |
536 @override | 561 @override |
537 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 562 visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
538 VariableDeclarationList variables = node.variables; | 563 VariableDeclarationList variables = node.variables; |
539 for (VariableDeclaration variableDeclaration in variables.variables) { | 564 for (VariableDeclaration variableDeclaration in variables.variables) { |
540 Element element = variableDeclaration.element; | 565 Element element = variableDeclaration.element; |
541 _recordTopLevelElementDefinition(element); | 566 _recordTopLevelElementDefinition(element); |
542 } | 567 } |
(...skipping 12 matching lines...) Expand all Loading... |
555 } | 580 } |
556 | 581 |
557 @override | 582 @override |
558 visitVariableDeclaration(VariableDeclaration node) { | 583 visitVariableDeclaration(VariableDeclaration node) { |
559 VariableElement element = node.element; | 584 VariableElement element = node.element; |
560 // record declaration | 585 // record declaration |
561 { | 586 { |
562 SimpleIdentifier name = node.name; | 587 SimpleIdentifier name = node.name; |
563 LocationImpl location = _createLocationForNode(name); | 588 LocationImpl location = _createLocationForNode(name); |
564 location = _getLocationWithExpressionType(location, node.initializer); | 589 location = _getLocationWithExpressionType(location, node.initializer); |
565 recordRelationship(element, IndexConstants.NAME_IS_DEFINED_BY, location); | 590 recordRelationshipElement( |
| 591 element, IndexConstants.NAME_IS_DEFINED_BY, location); |
566 } | 592 } |
567 // visit | 593 // visit |
568 enterScope(element); | 594 enterScope(element); |
569 try { | 595 try { |
570 super.visitVariableDeclaration(node); | 596 super.visitVariableDeclaration(node); |
571 } finally { | 597 } finally { |
572 _exitScope(); | 598 _exitScope(); |
573 } | 599 } |
574 } | 600 } |
575 | 601 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 return; | 708 return; |
683 } | 709 } |
684 if (_isIdentifierInPrefixedIdentifier(node)) { | 710 if (_isIdentifierInPrefixedIdentifier(node)) { |
685 return; | 711 return; |
686 } | 712 } |
687 Element element = node.staticElement; | 713 Element element = node.staticElement; |
688 ImportElement importElement = internal_getImportElement( | 714 ImportElement importElement = internal_getImportElement( |
689 _libraryElement, null, element, _importElementsMap); | 715 _libraryElement, null, element, _importElementsMap); |
690 if (importElement != null) { | 716 if (importElement != null) { |
691 LocationImpl location = _createLocationForOffset(node.offset, 0); | 717 LocationImpl location = _createLocationForOffset(node.offset, 0); |
692 recordRelationship( | 718 recordRelationshipElement( |
693 importElement, IndexConstants.IS_REFERENCED_BY, location); | 719 importElement, IndexConstants.IS_REFERENCED_BY, location); |
694 } | 720 } |
695 } | 721 } |
696 | 722 |
697 /** | 723 /** |
698 * Records [ImportElement] that declares given prefix and imports library with
element used | 724 * Records [ImportElement] that declares given prefix and imports library with
element used |
699 * with given prefix node. | 725 * with given prefix node. |
700 */ | 726 */ |
701 void _recordImportElementReferenceWithPrefix(SimpleIdentifier prefixNode) { | 727 void _recordImportElementReferenceWithPrefix(SimpleIdentifier prefixNode) { |
702 ImportElementInfo info = internal_getImportElementInfo(prefixNode); | 728 ImportElementInfo info = internal_getImportElementInfo(prefixNode); |
703 if (info != null) { | 729 if (info != null) { |
704 int offset = prefixNode.offset; | 730 int offset = prefixNode.offset; |
705 int length = info.periodEnd - offset; | 731 int length = info.periodEnd - offset; |
706 LocationImpl location = _createLocationForOffset(offset, length); | 732 LocationImpl location = _createLocationForOffset(offset, length); |
707 recordRelationship( | 733 recordRelationshipElement( |
708 info.element, IndexConstants.IS_REFERENCED_BY, location); | 734 info.element, IndexConstants.IS_REFERENCED_BY, location); |
709 } | 735 } |
710 } | 736 } |
711 | 737 |
712 /** | 738 /** |
713 * Records reference to defining [CompilationUnitElement] of the given | 739 * Records reference to defining [CompilationUnitElement] of the given |
714 * [LibraryElement]. | 740 * [LibraryElement]. |
715 */ | 741 */ |
716 void _recordLibraryReference(UriBasedDirective node, LibraryElement library) { | 742 void _recordLibraryReference(UriBasedDirective node, LibraryElement library) { |
717 if (library != null) { | 743 if (library != null) { |
718 LocationImpl location = _createLocationForNode(node.uri); | 744 LocationImpl location = _createLocationForNode(node.uri); |
719 recordRelationship(library.definingCompilationUnit, | 745 recordRelationshipElement(library.definingCompilationUnit, |
720 IndexConstants.IS_REFERENCED_BY, location); | 746 IndexConstants.IS_REFERENCED_BY, location); |
721 } | 747 } |
722 } | 748 } |
723 | 749 |
724 /** | 750 /** |
725 * Record reference to the given operator [Element] and name. | 751 * Record reference to the given operator [Element] and name. |
726 */ | 752 */ |
727 void _recordOperatorReference(Token operator, Element element) { | 753 void _recordOperatorReference(Token operator, Element element) { |
728 // prepare location | 754 // prepare location |
729 LocationImpl location = _createLocationForToken(operator, element != null); | 755 LocationImpl location = _createLocationForToken(operator, element != null); |
730 // record name reference | 756 // record name reference |
731 { | 757 { |
732 String name = operator.lexeme; | 758 String name = operator.lexeme; |
733 if (name == "++") { | 759 if (name == "++") { |
734 name = "+"; | 760 name = "+"; |
735 } | 761 } |
736 if (name == "--") { | 762 if (name == "--") { |
737 name = "-"; | 763 name = "-"; |
738 } | 764 } |
739 if (StringUtilities.endsWithChar(name, 0x3D) && name != "==") { | 765 if (StringUtilities.endsWithChar(name, 0x3D) && name != "==") { |
740 name = name.substring(0, name.length - 1); | 766 name = name.substring(0, name.length - 1); |
741 } | 767 } |
742 Element nameElement = new NameElement(name); | 768 IndexableName indexableName = new IndexableName(name); |
743 recordRelationship(nameElement, IndexConstants.IS_INVOKED_BY, location); | 769 recordRelationshipIndexable( |
| 770 indexableName, IndexConstants.IS_INVOKED_BY, location); |
744 } | 771 } |
745 // record element reference | 772 // record element reference |
746 if (element != null) { | 773 if (element != null) { |
747 recordRelationship(element, IndexConstants.IS_INVOKED_BY, location); | 774 recordRelationshipElement( |
| 775 element, IndexConstants.IS_INVOKED_BY, location); |
748 } | 776 } |
749 } | 777 } |
750 | 778 |
751 /** | 779 /** |
752 * Records a relation between [superNode] and its [Element]. | 780 * Records a relation between [superNode] and its [Element]. |
753 */ | 781 */ |
754 void _recordSuperType(TypeName superNode, RelationshipImpl relationship) { | 782 void _recordSuperType(TypeName superNode, RelationshipImpl relationship) { |
755 if (superNode != null) { | 783 if (superNode != null) { |
756 Identifier superName = superNode.name; | 784 Identifier superName = superNode.name; |
757 if (superName != null) { | 785 if (superName != null) { |
758 Element superElement = superName.staticElement; | 786 Element superElement = superName.staticElement; |
759 recordRelationship( | 787 recordRelationshipElement( |
760 superElement, relationship, _createLocationForNode(superNode)); | 788 superElement, relationship, _createLocationForNode(superNode)); |
761 } | 789 } |
762 } | 790 } |
763 } | 791 } |
764 | 792 |
765 /** | 793 /** |
766 * Records the [Element] definition in the library and universe. | 794 * Records the [Element] definition in the library and universe. |
767 */ | 795 */ |
768 void _recordTopLevelElementDefinition(Element element) { | 796 void _recordTopLevelElementDefinition(Element element) { |
769 if (element != null) { | 797 if (element != null) { |
770 IndexableElement indexable = new IndexableElement(element); | 798 IndexableElement indexable = new IndexableElement(element); |
771 int offset = indexable.offset; | 799 int offset = indexable.offset; |
772 int length = indexable.length; | 800 int length = indexable.length; |
773 LocationImpl location = new LocationImpl(indexable, offset, length); | 801 LocationImpl location = new LocationImpl(indexable, offset, length); |
774 recordRelationship(_libraryElement, IndexConstants.DEFINES, location); | 802 recordRelationshipElement( |
| 803 _libraryElement, IndexConstants.DEFINES, location); |
775 _store.recordTopLevelDeclaration(element); | 804 _store.recordTopLevelDeclaration(element); |
776 } | 805 } |
777 } | 806 } |
778 | 807 |
779 /** | 808 /** |
780 * If the given expression has resolved type, returns the new location with th
is type. | 809 * If the given expression has resolved type, returns the new location with th
is type. |
781 * | 810 * |
782 * [location] - the base location | 811 * [location] - the base location |
783 * [expression] - the expression assigned at the given location | 812 * [expression] - the expression assigned at the given location |
784 */ | 813 */ |
(...skipping 14 matching lines...) Expand all Loading... |
799 } | 828 } |
800 | 829 |
801 /** | 830 /** |
802 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node
". | 831 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node
". |
803 */ | 832 */ |
804 static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { | 833 static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { |
805 AstNode parent = node.parent; | 834 AstNode parent = node.parent; |
806 return parent is PrefixedIdentifier && parent.identifier == node; | 835 return parent is PrefixedIdentifier && parent.identifier == node; |
807 } | 836 } |
808 } | 837 } |
OLD | NEW |