| 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_core.dart'; | 9 import 'package:analysis_server/analysis/index_core.dart'; |
| 10 import 'package:analysis_server/src/services/correction/namespace.dart'; | 10 import 'package:analysis_server/src/services/correction/namespace.dart'; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 _recordOperatorReference(node.operator, node.bestElement); | 103 _recordOperatorReference(node.operator, node.bestElement); |
| 104 super.visitBinaryExpression(node); | 104 super.visitBinaryExpression(node); |
| 105 } | 105 } |
| 106 | 106 |
| 107 @override | 107 @override |
| 108 visitClassDeclaration(ClassDeclaration node) { | 108 visitClassDeclaration(ClassDeclaration node) { |
| 109 ClassElement element = node.element; | 109 ClassElement element = node.element; |
| 110 enterScope(element); | 110 enterScope(element); |
| 111 try { | 111 try { |
| 112 _recordTopLevelElementDefinition(element); | 112 _recordTopLevelElementDefinition(element); |
| 113 _recordHasAncestor(element); |
| 113 { | 114 { |
| 114 ExtendsClause extendsClause = node.extendsClause; | 115 ExtendsClause extendsClause = node.extendsClause; |
| 115 if (extendsClause != null) { | 116 if (extendsClause != null) { |
| 116 TypeName superclassNode = extendsClause.superclass; | 117 TypeName superclassNode = extendsClause.superclass; |
| 117 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); | 118 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); |
| 118 } else { | 119 } else { |
| 119 InterfaceType superType = element.supertype; | 120 InterfaceType superType = element.supertype; |
| 120 if (superType != null) { | 121 if (superType != null) { |
| 121 ClassElement objectElement = superType.element; | 122 ClassElement objectElement = superType.element; |
| 122 recordRelationshipElement( | 123 recordRelationshipElement( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 147 _exitScope(); | 148 _exitScope(); |
| 148 } | 149 } |
| 149 } | 150 } |
| 150 | 151 |
| 151 @override | 152 @override |
| 152 visitClassTypeAlias(ClassTypeAlias node) { | 153 visitClassTypeAlias(ClassTypeAlias node) { |
| 153 ClassElement element = node.element; | 154 ClassElement element = node.element; |
| 154 enterScope(element); | 155 enterScope(element); |
| 155 try { | 156 try { |
| 156 _recordTopLevelElementDefinition(element); | 157 _recordTopLevelElementDefinition(element); |
| 158 _recordHasAncestor(element); |
| 157 { | 159 { |
| 158 TypeName superclassNode = node.superclass; | 160 TypeName superclassNode = node.superclass; |
| 159 if (superclassNode != null) { | 161 if (superclassNode != null) { |
| 160 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); | 162 _recordSuperType(superclassNode, IndexConstants.IS_EXTENDED_BY); |
| 161 } | 163 } |
| 162 } | 164 } |
| 163 { | 165 { |
| 164 WithClause withClause = node.withClause; | 166 WithClause withClause = node.withClause; |
| 165 if (withClause != null) { | 167 if (withClause != null) { |
| 166 for (TypeName mixinNode in withClause.mixinTypes) { | 168 for (TypeName mixinNode in withClause.mixinTypes) { |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 if (target is SimpleIdentifier && | 640 if (target is SimpleIdentifier && |
| 639 target.staticElement is PrefixElement) { | 641 target.staticElement is PrefixElement) { |
| 640 return false; | 642 return false; |
| 641 } | 643 } |
| 642 return target != null; | 644 return target != null; |
| 643 } | 645 } |
| 644 } | 646 } |
| 645 return false; | 647 return false; |
| 646 } | 648 } |
| 647 | 649 |
| 650 void _recordHasAncestor(ClassElement element) { |
| 651 int offset = element.nameOffset; |
| 652 int length = element.name.length; |
| 653 LocationImpl location = _createLocationForOffset(offset, length); |
| 654 _recordHasAncestor0(location, element, false, <ClassElement>[]); |
| 655 } |
| 656 |
| 657 void _recordHasAncestor0(LocationImpl location, ClassElement element, |
| 658 bool includeThis, List<ClassElement> visitedElements) { |
| 659 if (element == null) { |
| 660 return; |
| 661 } |
| 662 if (visitedElements.contains(element)) { |
| 663 return; |
| 664 } |
| 665 visitedElements.add(element); |
| 666 if (includeThis) { |
| 667 recordRelationshipElement(element, IndexConstants.HAS_ANCESTOR, location); |
| 668 } |
| 669 { |
| 670 InterfaceType superType = element.supertype; |
| 671 if (superType != null) { |
| 672 _recordHasAncestor0(location, superType.element, true, visitedElements); |
| 673 } |
| 674 } |
| 675 for (InterfaceType mixinType in element.mixins) { |
| 676 _recordHasAncestor0(location, mixinType.element, true, visitedElements); |
| 677 } |
| 678 for (InterfaceType implementedType in element.interfaces) { |
| 679 _recordHasAncestor0( |
| 680 location, implementedType.element, true, visitedElements); |
| 681 } |
| 682 } |
| 683 |
| 648 /** | 684 /** |
| 649 * Records [ImportElement] reference if given [SimpleIdentifier] references so
me | 685 * Records [ImportElement] reference if given [SimpleIdentifier] references so
me |
| 650 * top-level element and not qualified with import prefix. | 686 * top-level element and not qualified with import prefix. |
| 651 */ | 687 */ |
| 652 void _recordImportElementReferenceWithoutPrefix(SimpleIdentifier node) { | 688 void _recordImportElementReferenceWithoutPrefix(SimpleIdentifier node) { |
| 653 if (_isIdentifierInImportCombinator(node)) { | 689 if (_isIdentifierInImportCombinator(node)) { |
| 654 return; | 690 return; |
| 655 } | 691 } |
| 656 if (_isIdentifierInPrefixedIdentifier(node)) { | 692 if (_isIdentifierInPrefixedIdentifier(node)) { |
| 657 return; | 693 return; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 } | 810 } |
| 775 | 811 |
| 776 /** | 812 /** |
| 777 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node
". | 813 * @return `true` if given "node" is part of [PrefixedIdentifier] "prefix.node
". |
| 778 */ | 814 */ |
| 779 static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { | 815 static bool _isIdentifierInPrefixedIdentifier(SimpleIdentifier node) { |
| 780 AstNode parent = node.parent; | 816 AstNode parent = node.parent; |
| 781 return parent is PrefixedIdentifier && parent.identifier == node; | 817 return parent is PrefixedIdentifier && parent.identifier == node; |
| 782 } | 818 } |
| 783 } | 819 } |
| OLD | NEW |