| 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/token.dart'; | 6 import 'package:analyzer/dart/ast/token.dart'; |
| 7 import 'package:analyzer/dart/ast/visitor.dart'; | 7 import 'package:analyzer/dart/ast/visitor.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/dart/element/member.dart'; | 10 import 'package:analyzer/src/dart/element/member.dart'; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 visitClassTypeAlias(ClassTypeAlias node) { | 413 visitClassTypeAlias(ClassTypeAlias node) { |
| 414 recordIsAncestorOf(node.element); | 414 recordIsAncestorOf(node.element); |
| 415 super.visitClassTypeAlias(node); | 415 super.visitClassTypeAlias(node); |
| 416 } | 416 } |
| 417 | 417 |
| 418 @override | 418 @override |
| 419 visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | 419 visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 420 SimpleIdentifier fieldName = node.fieldName; | 420 SimpleIdentifier fieldName = node.fieldName; |
| 421 if (fieldName != null) { | 421 if (fieldName != null) { |
| 422 Element element = fieldName.staticElement; | 422 Element element = fieldName.staticElement; |
| 423 recordRelation( | 423 recordRelation(element, IndexRelationKind.IS_WRITTEN_BY, fieldName, true); |
| 424 element, IndexRelationKind.IS_REFERENCED_BY, fieldName, true); | |
| 425 } | 424 } |
| 426 node.expression?.accept(this); | 425 node.expression?.accept(this); |
| 427 } | 426 } |
| 428 | 427 |
| 429 @override | 428 @override |
| 430 visitConstructorName(ConstructorName node) { | 429 visitConstructorName(ConstructorName node) { |
| 431 ConstructorElement element = node.staticElement; | 430 ConstructorElement element = node.staticElement; |
| 432 element = _getActualConstructorElement(element); | 431 element = _getActualConstructorElement(element); |
| 433 // record relation | 432 // record relation |
| 434 if (node.name != null) { | 433 if (node.name != null) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 visitSimpleIdentifier(SimpleIdentifier node) { | 536 visitSimpleIdentifier(SimpleIdentifier node) { |
| 538 Element element = node.bestElement; | 537 Element element = node.bestElement; |
| 539 // name in declaration | 538 // name in declaration |
| 540 if (node.inDeclarationContext()) { | 539 if (node.inDeclarationContext()) { |
| 541 recordDefinedElement(element); | 540 recordDefinedElement(element); |
| 542 return; | 541 return; |
| 543 } | 542 } |
| 544 // record qualified unresolved name reference | 543 // record qualified unresolved name reference |
| 545 bool isQualified = _isQualified(node); | 544 bool isQualified = _isQualified(node); |
| 546 if (isQualified && element == null) { | 545 if (isQualified && element == null) { |
| 547 recordNameRelation(node, IndexRelationKind.IS_REFERENCED_BY); | 546 bool inGetterContext = node.inGetterContext(); |
| 547 bool inSetterContext = node.inSetterContext(); |
| 548 IndexRelationKind kind; |
| 549 if (inGetterContext && inSetterContext) { |
| 550 kind = IndexRelationKind.IS_READ_WRITTEN_BY; |
| 551 } else if (inGetterContext) { |
| 552 kind = IndexRelationKind.IS_READ_BY; |
| 553 } else { |
| 554 kind = IndexRelationKind.IS_WRITTEN_BY; |
| 555 } |
| 556 recordNameRelation(node, kind); |
| 548 } | 557 } |
| 549 // this.field parameter | 558 // this.field parameter |
| 550 if (element is FieldFormalParameterElement) { | 559 if (element is FieldFormalParameterElement) { |
| 551 recordRelation( | 560 AstNode parent = node.parent; |
| 552 element.field, IndexRelationKind.IS_REFERENCED_BY, node, true); | 561 IndexRelationKind kind = |
| 562 parent is FieldFormalParameter && parent.identifier == node |
| 563 ? IndexRelationKind.IS_WRITTEN_BY |
| 564 : IndexRelationKind.IS_REFERENCED_BY; |
| 565 recordRelation(element.field, kind, node, true); |
| 553 return; | 566 return; |
| 554 } | 567 } |
| 555 // ignore a local reference to a parameter | 568 // ignore a local reference to a parameter |
| 556 if (element is ParameterElement && node.parent is! Label) { | 569 if (element is ParameterElement && node.parent is! Label) { |
| 557 return; | 570 return; |
| 558 } | 571 } |
| 559 // record specific relations | 572 // record specific relations |
| 560 recordRelation( | 573 recordRelation( |
| 561 element, IndexRelationKind.IS_REFERENCED_BY, node, isQualified); | 574 element, IndexRelationKind.IS_REFERENCED_BY, node, isQualified); |
| 562 } | 575 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 usedNames: nameRelations.map((r) => r.nameInfo.id).toList(), | 769 usedNames: nameRelations.map((r) => r.nameInfo.id).toList(), |
| 757 usedNameKinds: nameRelations.map((r) => r.kind).toList(), | 770 usedNameKinds: nameRelations.map((r) => r.kind).toList(), |
| 758 usedNameOffsets: nameRelations.map((r) => r.offset).toList()); | 771 usedNameOffsets: nameRelations.map((r) => r.offset).toList()); |
| 759 } | 772 } |
| 760 | 773 |
| 761 void defineName(String name, IndexNameKind kind, int offset) { | 774 void defineName(String name, IndexNameKind kind, int offset) { |
| 762 _StringInfo nameInfo = pkg._getStringInfo(name); | 775 _StringInfo nameInfo = pkg._getStringInfo(name); |
| 763 definedNames.add(new _DefinedNameInfo(nameInfo, kind, offset)); | 776 definedNames.add(new _DefinedNameInfo(nameInfo, kind, offset)); |
| 764 } | 777 } |
| 765 } | 778 } |
| OLD | NEW |