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 analyzer.src.dart.element.element; | 5 library analyzer.src.dart.element.element; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:math' show min; | 8 import 'dart:math' show min; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 17 matching lines...) Expand all Loading... |
28 import 'package:analyzer/src/generated/utilities_collection.dart'; | 28 import 'package:analyzer/src/generated/utilities_collection.dart'; |
29 import 'package:analyzer/src/generated/utilities_dart.dart'; | 29 import 'package:analyzer/src/generated/utilities_dart.dart'; |
30 import 'package:analyzer/src/generated/utilities_general.dart'; | 30 import 'package:analyzer/src/generated/utilities_general.dart'; |
31 import 'package:analyzer/src/summary/idl.dart'; | 31 import 'package:analyzer/src/summary/idl.dart'; |
32 import 'package:analyzer/src/task/dart.dart'; | 32 import 'package:analyzer/src/task/dart.dart'; |
33 | 33 |
34 /** | 34 /** |
35 * A concrete implementation of a [ClassElement]. | 35 * A concrete implementation of a [ClassElement]. |
36 */ | 36 */ |
37 abstract class AbstractClassElementImpl extends ElementImpl | 37 abstract class AbstractClassElementImpl extends ElementImpl |
38 with TypeParameterizedElementMixin | |
39 implements ClassElement { | 38 implements ClassElement { |
40 /** | 39 /** |
41 * A list containing all of the accessors (getters and setters) contained in | 40 * A list containing all of the accessors (getters and setters) contained in |
42 * this class. | 41 * this class. |
43 */ | 42 */ |
44 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST; | 43 List<PropertyAccessorElement> _accessors = PropertyAccessorElement.EMPTY_LIST; |
45 | 44 |
46 /** | 45 /** |
47 * A list containing all of the fields contained in this class. | 46 * A list containing all of the fields contained in this class. |
48 */ | 47 */ |
49 List<FieldElement> _fields = FieldElement.EMPTY_LIST; | 48 List<FieldElement> _fields = FieldElement.EMPTY_LIST; |
50 | 49 |
51 /** | 50 /** |
52 * The superclass of the class, or `null` if the class does not have an | |
53 * explicit superclass. | |
54 */ | |
55 @override | |
56 InterfaceType _supertype; | |
57 | |
58 /** | |
59 * The type defined by the class. | 51 * The type defined by the class. |
60 */ | 52 */ |
61 @override | 53 @override |
62 InterfaceType type; | 54 InterfaceType type; |
63 | 55 |
64 /** | 56 /** |
65 * Initialize a newly created class element to have the given [name] at the | 57 * Initialize a newly created class element to have the given [name] at the |
66 * given [offset] in the file that contains the declaration of this element. | 58 * given [offset] in the file that contains the declaration of this element. |
67 */ | 59 */ |
68 AbstractClassElementImpl(String name, int offset) : super(name, offset); | 60 AbstractClassElementImpl(String name, int offset) : super(name, offset); |
(...skipping 20 matching lines...) Expand all Loading... |
89 for (PropertyAccessorElement accessor in accessors) { | 81 for (PropertyAccessorElement accessor in accessors) { |
90 (accessor as PropertyAccessorElementImpl).enclosingElement = this; | 82 (accessor as PropertyAccessorElementImpl).enclosingElement = this; |
91 } | 83 } |
92 this._accessors = accessors; | 84 this._accessors = accessors; |
93 } | 85 } |
94 | 86 |
95 @override | 87 @override |
96 String get displayName => name; | 88 String get displayName => name; |
97 | 89 |
98 @override | 90 @override |
99 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; | |
100 | |
101 @override | |
102 List<FieldElement> get fields => _fields; | 91 List<FieldElement> get fields => _fields; |
103 | 92 |
104 /** | 93 /** |
105 * Set the fields contained in this class to the given [fields]. | 94 * Set the fields contained in this class to the given [fields]. |
106 */ | 95 */ |
107 void set fields(List<FieldElement> fields) { | 96 void set fields(List<FieldElement> fields) { |
108 for (FieldElement field in fields) { | 97 for (FieldElement field in fields) { |
109 (field as FieldElementImpl).enclosingElement = this; | 98 (field as FieldElementImpl).enclosingElement = this; |
110 } | 99 } |
111 this._fields = fields; | 100 this._fields = fields; |
112 } | 101 } |
113 | 102 |
114 @override | 103 @override |
115 bool get isEnum; | 104 bool get isEnum; |
116 | 105 |
117 @override | 106 @override |
118 ElementKind get kind => ElementKind.CLASS; | 107 ElementKind get kind => ElementKind.CLASS; |
119 | 108 |
120 /** | |
121 * Return resynthesized type parameter elements. | |
122 */ | |
123 List<TypeParameterElement> get resynthesizedTypeParameters { | |
124 return super.typeParameters; | |
125 } | |
126 | |
127 @override | |
128 TypeParameterizedElementMixin get typeParameterContext => this; | |
129 | |
130 @override | |
131 List<UnlinkedTypeParam> get unlinkedTypeParams => const <UnlinkedTypeParam>[]; | |
132 | |
133 @override | 109 @override |
134 accept(ElementVisitor visitor) => visitor.visitClassElement(this); | 110 accept(ElementVisitor visitor) => visitor.visitClassElement(this); |
135 | 111 |
136 @override | 112 @override |
137 NamedCompilationUnitMember computeNode() { | 113 NamedCompilationUnitMember computeNode() { |
138 if (isEnum) { | 114 if (isEnum) { |
139 return getNodeMatching((node) => node is EnumDeclaration); | 115 return getNodeMatching((node) => node is EnumDeclaration); |
140 } else { | 116 } else { |
141 return getNodeMatching( | 117 return getNodeMatching( |
142 (node) => node is ClassDeclaration || node is ClassTypeAlias); | 118 (node) => node is ClassDeclaration || node is ClassTypeAlias); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 /** | 414 /** |
439 * Initialize a newly created pair to have both the [staticElement] and the | 415 * Initialize a newly created pair to have both the [staticElement] and the |
440 * [propagatedElement]. | 416 * [propagatedElement]. |
441 */ | 417 */ |
442 AuxiliaryElements(this.staticElement, this.propagatedElement); | 418 AuxiliaryElements(this.staticElement, this.propagatedElement); |
443 } | 419 } |
444 | 420 |
445 /** | 421 /** |
446 * An [AbstractClassElementImpl] which is a class. | 422 * An [AbstractClassElementImpl] which is a class. |
447 */ | 423 */ |
448 class ClassElementImpl extends AbstractClassElementImpl { | 424 class ClassElementImpl extends AbstractClassElementImpl |
| 425 with TypeParameterizedElementMixin { |
449 /** | 426 /** |
450 * The unlinked representation of the class in the summary. | 427 * The unlinked representation of the class in the summary. |
451 */ | 428 */ |
452 final UnlinkedClass _unlinkedClass; | 429 final UnlinkedClass _unlinkedClass; |
453 | 430 |
454 /** | 431 /** |
455 * A list containing all of the type parameters defined for this class. | 432 * A list containing all of the type parameters defined for this class. |
456 */ | 433 */ |
457 List<TypeParameterElement> _typeParameters = TypeParameterElement.EMPTY_LIST; | 434 List<TypeParameterElement> _typeParameters = TypeParameterElement.EMPTY_LIST; |
458 | 435 |
459 /** | 436 /** |
| 437 * The superclass of the class, or `null` for [Object]. |
| 438 */ |
| 439 InterfaceType _supertype; |
| 440 |
| 441 /** |
460 * A list containing all of the mixins that are applied to the class being | 442 * A list containing all of the mixins that are applied to the class being |
461 * extended in order to derive the superclass of this class. | 443 * extended in order to derive the superclass of this class. |
462 */ | 444 */ |
463 List<InterfaceType> _mixins; | 445 List<InterfaceType> _mixins; |
464 | 446 |
465 /** | 447 /** |
466 * A list containing all of the interfaces that are implemented by this class. | 448 * A list containing all of the interfaces that are implemented by this class. |
467 */ | 449 */ |
468 List<InterfaceType> _interfaces; | 450 List<InterfaceType> _interfaces; |
469 | 451 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 assert(false); | 604 assert(false); |
623 return false; | 605 return false; |
624 } | 606 } |
625 nearestNonMixinClass = nearestNonMixinClass.supertype.element; | 607 nearestNonMixinClass = nearestNonMixinClass.supertype.element; |
626 } | 608 } |
627 } | 609 } |
628 return !nearestNonMixinClass.constructors.any(isSuperConstructorAccessible); | 610 return !nearestNonMixinClass.constructors.any(isSuperConstructorAccessible); |
629 } | 611 } |
630 | 612 |
631 @override | 613 @override |
| 614 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; |
| 615 |
| 616 @override |
632 bool get hasNonFinalField { | 617 bool get hasNonFinalField { |
633 List<ClassElement> classesToVisit = new List<ClassElement>(); | 618 List<ClassElement> classesToVisit = new List<ClassElement>(); |
634 HashSet<ClassElement> visitedClasses = new HashSet<ClassElement>(); | 619 HashSet<ClassElement> visitedClasses = new HashSet<ClassElement>(); |
635 classesToVisit.add(this); | 620 classesToVisit.add(this); |
636 while (!classesToVisit.isEmpty) { | 621 while (!classesToVisit.isEmpty) { |
637 ClassElement currentElement = classesToVisit.removeAt(0); | 622 ClassElement currentElement = classesToVisit.removeAt(0); |
638 if (visitedClasses.add(currentElement)) { | 623 if (visitedClasses.add(currentElement)) { |
639 // check fields | 624 // check fields |
640 for (FieldElement field in currentElement.fields) { | 625 for (FieldElement field in currentElement.fields) { |
641 if (!field.isFinal && | 626 if (!field.isFinal && |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 } | 826 } |
842 return _supertype; | 827 return _supertype; |
843 } | 828 } |
844 | 829 |
845 void set supertype(InterfaceType supertype) { | 830 void set supertype(InterfaceType supertype) { |
846 assert(_unlinkedClass == null); | 831 assert(_unlinkedClass == null); |
847 _supertype = supertype; | 832 _supertype = supertype; |
848 } | 833 } |
849 | 834 |
850 @override | 835 @override |
| 836 TypeParameterizedElementMixin get typeParameterContext => this; |
| 837 |
| 838 @override |
851 List<TypeParameterElement> get typeParameters { | 839 List<TypeParameterElement> get typeParameters { |
852 if (_unlinkedClass != null) { | 840 if (_unlinkedClass != null) { |
853 return resynthesizedTypeParameters; | 841 return super.typeParameters; |
854 } | 842 } |
855 return _typeParameters; | 843 return _typeParameters; |
856 } | 844 } |
857 | 845 |
858 /** | 846 /** |
859 * Set the type parameters defined for this class to the given | 847 * Set the type parameters defined for this class to the given |
860 * [typeParameters]. | 848 * [typeParameters]. |
861 */ | 849 */ |
862 void set typeParameters(List<TypeParameterElement> typeParameters) { | 850 void set typeParameters(List<TypeParameterElement> typeParameters) { |
863 assert(_unlinkedClass == null); | 851 assert(_unlinkedClass == null); |
(...skipping 7091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7955 | 7943 |
7956 @override | 7944 @override |
7957 void visitElement(Element element) { | 7945 void visitElement(Element element) { |
7958 int offset = element.nameOffset; | 7946 int offset = element.nameOffset; |
7959 if (offset != -1) { | 7947 if (offset != -1) { |
7960 map[offset] = element; | 7948 map[offset] = element; |
7961 } | 7949 } |
7962 super.visitElement(element); | 7950 super.visitElement(element); |
7963 } | 7951 } |
7964 } | 7952 } |
OLD | NEW |