@@ -99,29 +99,28 @@ abstract class InheritingContainer extends Container {
99
99
...typeParameters,
100
100
];
101
101
102
+ @visibleForTesting
102
103
Iterable <Method > get inheritedMethods {
103
104
var methodNames = declaredMethods.map ((m) => m.element.name3).toSet ();
104
- var inheritedMethodElements = _inheritedElements
105
+ var inheritedMethodElements = element.inheritedMembers.values
105
106
.whereType <MethodElement2 >()
106
- .where ((e) =>
107
- ! e.isOperator &&
108
- e is ! PropertyAccessorElement2 &&
109
- ! methodNames.contains (e.name3))
110
- .toSet ();
107
+ .where ((e) => ! e.isOperator)
108
+ .where ((e) => ! methodNames.contains (e.name3));
111
109
112
110
return [
113
111
for (var e in inheritedMethodElements)
114
112
getModelFor (e, library, enclosingContainer: this ) as Method ,
115
113
];
116
114
}
117
115
116
+ @visibleForTesting
118
117
List <Operator > get inheritedOperators {
119
118
var operatorNames =
120
119
declaredOperators.map ((o) => o.element.lookupName).toSet ();
121
- var inheritedOperatorElements = _inheritedElements
120
+ var inheritedOperatorElements = element.inheritedMembers.values
122
121
.whereType <MethodElement2 >()
123
- .where ((e) => e.isOperator && ! operatorNames. contains (e.lookupName) )
124
- .toSet ( );
122
+ .where ((e) => e.isOperator)
123
+ .where ((e) => ! operatorNames. contains (e.name3) );
125
124
126
125
return [
127
126
for (var e in inheritedOperatorElements)
@@ -132,74 +131,10 @@ abstract class InheritingContainer extends Container {
132
131
late final DefinedElementType modelType =
133
132
getTypeFor (element.thisType, library) as DefinedElementType ;
134
133
135
- /// A list of the inherited executable elements, one element per inherited
136
- /// `Name` .
137
- ///
138
- /// In this list, elements that are "closer" in the inheritance chain to
139
- /// _this_ element are preferred over elements that are further away. In the
140
- /// case of ties, concrete inherited elements are prefered to non-concrete
141
- /// ones.
142
- late final List <ExecutableElement2 > _inheritedElements = () {
143
- if (element case ClassElement2 classElement
144
- when classElement.isDartCoreObject) {
145
- return const < ExecutableElement2 > [];
146
- }
147
-
148
- // The mapping of all of the inherited element names to their _concrete_
149
- // implementation element.
150
- var concreteInheritanceMap =
151
- packageGraph.inheritanceManager.getInheritedConcreteMap (element);
152
- // The mapping of all inherited element names to the nearest inherited
153
- // element that they resolve to.
154
- var inheritanceMap =
155
- packageGraph.inheritanceManager.getInheritedMap (element);
156
-
157
- var inheritanceChainElements =
158
- inheritanceChain.map ((c) => c.element).toList (growable: false );
159
-
160
- // A combined map of names to inherited _concrete_ Elements, and other
161
- // inherited Elements.
162
- var combinedMap = {
163
- for (var MapEntry (: key, : value) in concreteInheritanceMap.entries)
164
- key.name: value,
165
- };
166
- for (var MapEntry (key: name, value: inheritedElement)
167
- in inheritanceMap.entries) {
168
- var combinedMapElement = combinedMap[name.name];
169
- if (combinedMapElement == null ) {
170
- combinedMap[name.name] = inheritedElement;
171
- continue ;
172
- }
173
-
174
- // Elements in the inheritance chain starting from `this.element` up to,
175
- // but not including, `Object`.
176
- var enclosingElement =
177
- inheritedElement.enclosingElement2 as InterfaceElement2 ;
178
- assert (inheritanceChainElements.contains (enclosingElement) ||
179
- enclosingElement.isDartCoreObject);
180
-
181
- // If the concrete element from `getInheritedConcreteMap2` is farther in
182
- // the inheritance chain from this class than the (non-concrete) one
183
- // provided by `getInheritedMap2`, prefer the latter. This correctly
184
- // accounts for intermediate abstract classes that have method/field
185
- // implementations.
186
- var enclosingElementFromCombined =
187
- combinedMapElement.enclosingElement2 as InterfaceElement2 ;
188
- if (inheritanceChainElements.indexOf (enclosingElementFromCombined) <
189
- inheritanceChainElements.indexOf (enclosingElement)) {
190
- combinedMap[name.name] = inheritedElement;
191
- }
192
- }
193
-
194
- // Finally, return all of the elements ultimately collected in the combined
195
- // map.
196
- return combinedMap.values.toList (growable: false );
197
- }();
198
-
199
134
/// All fields defined on this container, _including inherited fields_.
200
- late List <Field > allFields = () {
135
+ late final List <Field > _allFields = () {
201
136
var inheritedAccessorElements = {
202
- ..._inheritedElements .whereType <PropertyAccessorElement2 >()
137
+ ...element.inheritedMembers.values .whereType <PropertyAccessorElement2 >()
203
138
};
204
139
205
140
// This structure keeps track of inherited accessors, allowing lookup
@@ -285,17 +220,15 @@ abstract class InheritingContainer extends Container {
285
220
List <ModelElement > get allModelElements => _allModelElements;
286
221
287
222
@override
288
- Iterable <Field > get constantFields => allFields .where ((f) => f.isConst);
223
+ Iterable <Field > get constantFields => _allFields .where ((f) => f.isConst);
289
224
290
225
@override
291
- Iterable <Field > get declaredFields => allFields .where ((f) => ! f.isInherited);
226
+ Iterable <Field > get declaredFields => _allFields .where ((f) => ! f.isInherited);
292
227
293
228
/// The [InheritingContainer] with the library in which [element] is defined.
294
229
InheritingContainer get definingContainer =>
295
230
getModelFor (element, library) as InheritingContainer ;
296
231
297
- @override
298
-
299
232
@override
300
233
InterfaceElement2 get element;
301
234
@@ -333,10 +266,10 @@ abstract class InheritingContainer extends Container {
333
266
List <InheritingContainer > get inheritanceChain;
334
267
335
268
@visibleForTesting
336
- Iterable <Field > get inheritedFields => allFields .where ((f) => f.isInherited);
269
+ Iterable <Field > get inheritedFields => _allFields .where ((f) => f.isInherited);
337
270
338
271
@override
339
- Iterable <Field > get instanceFields => allFields .where ((f) => ! f.isStatic);
272
+ Iterable <Field > get instanceFields => _allFields .where ((f) => ! f.isStatic);
340
273
341
274
@override
342
275
late final List <Field > availableInstanceFieldsSorted = [
@@ -371,8 +304,8 @@ abstract class InheritingContainer extends Container {
371
304
List <Method > get _extensionInstanceMethods => [
372
305
for (var extension in potentiallyApplicableExtensionsSorted)
373
306
for (var method in extension .instanceMethods)
374
- getModelFor (method.element, library,
375
- enclosingContainer : extension ) as Method ,
307
+ getModelFor (method.element, library, enclosingContainer : extension )
308
+ as Method ,
376
309
];
377
310
378
311
@override
@@ -677,11 +610,6 @@ mixin MixedInTypes on InheritingContainer {
677
610
mixedInTypes.wherePublic;
678
611
}
679
612
680
- extension on InterfaceElement2 {
681
- bool get isDartCoreObject =>
682
- name3 == 'Object' && library2.name3 == 'dart.core' ;
683
- }
684
-
685
613
extension DefinedElementTypeIterableExtension on Iterable <DefinedElementType > {
686
614
/// The [ModelElement] for each element.
687
615
List <InheritingContainer > get modelElements =>
0 commit comments