3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
5
import 'package:analyzer/dart/element/element.dart' ;
6
+ import 'package:analyzer/dart/element/element2.dart' ;
6
7
import 'package:analyzer/dart/element/type.dart' ;
7
8
import 'package:analyzer/src/dart/element/element.dart' ;
8
9
import 'package:analyzer/src/dart/element/extensions.dart' ;
9
10
import 'package:analyzer/src/dart/element/member.dart' ;
10
11
import 'package:analyzer/src/dart/element/type_algebra.dart' ;
11
12
import 'package:analyzer/src/dart/element/type_system.dart' ;
12
13
import 'package:analyzer/src/utilities/extensions/collection.dart' ;
14
+ import 'package:meta/meta.dart' ;
13
15
14
16
/// Failure because of there is no most specific signature in [candidates] .
15
17
class CandidatesConflict extends Conflict {
@@ -145,6 +147,40 @@ class InheritanceManager3 {
145
147
return getInheritedMap2 (element)[name];
146
148
}
147
149
150
+ /// Returns the result of [getInherited2] with [type] substitution.
151
+ // This is a replacement for `getInherited`.
152
+ @experimental
153
+ ExecutableElement2 ? getInherited3 (InterfaceType type, Name name) {
154
+ var element = getInherited (type, name);
155
+ return (element as ExecutableFragment ? )? .element;
156
+ }
157
+
158
+ /// Returns the most specific signature of the member with the given [name]
159
+ /// that [element] inherits from the mixins, superclasses, or interfaces.
160
+ ///
161
+ /// Returns `null` if no member is inherited because the member is not
162
+ /// declared at all, or because there is no the most specific signature.
163
+ ///
164
+ /// This is equivalent to `getInheritedMap(type)[name]` .
165
+ // This is a replacement for `getInherited2`.
166
+ @experimental
167
+ ExecutableElement2 ? getInherited4 (InterfaceElement2 element, Name name) {
168
+ var oldElement = getInheritedMap2 (
169
+ (element as AugmentedInterfaceElement ).declaration)[name];
170
+ return (oldElement as ExecutableFragment ? )? .element;
171
+ }
172
+
173
+ /// Returns signatures of all concrete members that the given [element]
174
+ /// inherits from the superclasses and mixins.
175
+ @experimental
176
+ Map <Name , ExecutableElement2 > getInheritedConcreteMap (
177
+ InterfaceElement2 element) {
178
+ var map = getInheritedConcreteMap2 (
179
+ (element as AugmentedInterfaceElement ).declaration);
180
+ return map.map ((name, element) =>
181
+ MapEntry (name, (element as ExecutableFragment ).element));
182
+ }
183
+
148
184
/// Return signatures of all concrete members that the given [element] inherits
149
185
/// from the superclasses and mixins.
150
186
Map <Name , ExecutableElement > getInheritedConcreteMap2 (
@@ -157,6 +193,20 @@ class InheritanceManager3 {
157
193
return interface .superImplemented.last;
158
194
}
159
195
196
+ /// Returns the mapping from names to most specific signatures of members
197
+ /// inherited from the super-interfaces (superclasses, mixins, and
198
+ /// interfaces).
199
+ ///
200
+ /// If there is no most specific signature for a name, the corresponding name
201
+ /// will not be included.
202
+ @experimental
203
+ Map <Name , ExecutableElement2 > getInheritedMap (InterfaceElement2 element) {
204
+ var map =
205
+ getInheritedMap2 ((element as AugmentedInterfaceElement ).declaration);
206
+ return map.map ((name, element) =>
207
+ MapEntry (name, (element as ExecutableFragment ).element));
208
+ }
209
+
160
210
/// Return the mapping from names to most specific signatures of members
161
211
/// inherited from the super-interfaces (superclasses, mixins, and
162
212
/// interfaces). If there is no most specific signature for a name, the
@@ -211,6 +261,15 @@ class InheritanceManager3 {
211
261
return result;
212
262
}
213
263
264
+ /// Returns the interface of the given [element] .
265
+ ///
266
+ /// The interface might include private members, not necessary accessible in
267
+ /// all libraries.
268
+ @experimental
269
+ Interface getInterface2 (InterfaceElement2 element) {
270
+ return getInterface ((element as AugmentedInterfaceElement ).declaration);
271
+ }
272
+
214
273
/// Return the result of [getMember2] with [type] substitution.
215
274
ExecutableElement ? getMember (
216
275
InterfaceType type,
@@ -274,6 +333,75 @@ class InheritanceManager3 {
274
333
return interface .map[name];
275
334
}
276
335
336
+ /// Returns the result of [getMember4] with [type] substitution.
337
+ // This is a replacement for `getMember`.
338
+ @experimental
339
+ ExecutableElement2 ? getMember3 (
340
+ InterfaceType type,
341
+ Name name, {
342
+ bool concrete = false ,
343
+ int forMixinIndex = - 1 ,
344
+ bool forSuper = false ,
345
+ }) {
346
+ var element = getMember (
347
+ type,
348
+ name,
349
+ concrete: concrete,
350
+ forMixinIndex: forMixinIndex,
351
+ forSuper: forSuper,
352
+ );
353
+ return (element as ExecutableFragment ? )? .element;
354
+ }
355
+
356
+ /// Returns the member with the given [name] .
357
+ ///
358
+ /// If [concrete] is `true` , the concrete implementation is returned, whether
359
+ /// from the given [element] or its superclass.
360
+ ///
361
+ /// If [forSuper] is `true` , then [concrete] is implied, and only concrete
362
+ /// members from the superclass are considered.
363
+ ///
364
+ /// If [forMixinIndex] is specified, only the nominal superclass, and the
365
+ /// given number of mixins after it are considered. For example for `1` in
366
+ /// `class C extends S with M1, M2, M3` , only `S` and `M1` are considered.
367
+ // This is a replacement for `getMember2`.
368
+ @experimental
369
+ ExecutableElement2 ? getMember4 (
370
+ InterfaceElement2 element,
371
+ Name name, {
372
+ bool concrete = false ,
373
+ int forMixinIndex = - 1 ,
374
+ bool forSuper = false ,
375
+ }) {
376
+ var oldElement = getMember2 (
377
+ (element as AugmentedInterfaceElement ).declaration,
378
+ name,
379
+ concrete: concrete,
380
+ forMixinIndex: forMixinIndex,
381
+ forSuper: forSuper,
382
+ );
383
+ return (oldElement as ExecutableFragment ? )? .element;
384
+ }
385
+
386
+ /// Returns all members of mixins, superclasses, and interfaces that a member
387
+ /// with the given [name] , defined in the [element] , would override.
388
+ ///
389
+ /// Returns `null` if no members would be overridden.
390
+ @experimental
391
+ List <ExecutableElement2 >? getOverridden (
392
+ InterfaceElement2 element, Name name) {
393
+ var elements = getOverridden2 (
394
+ (element as AugmentedInterfaceElement ).declaration,
395
+ name,
396
+ );
397
+ if (elements == null ) {
398
+ return null ;
399
+ }
400
+ return elements
401
+ .map ((fragment) => (fragment as ExecutableFragment ).element)
402
+ .toList ();
403
+ }
404
+
277
405
/// Return all members of mixins, superclasses, and interfaces that a member
278
406
/// with the given [name] , defined in the [element] , would override; or `null`
279
407
/// if no members would be overridden.
@@ -1114,6 +1242,20 @@ class Interface {
1114
1242
required this .conflicts,
1115
1243
});
1116
1244
1245
+ /// The map of declared names to their signatures.
1246
+ @experimental
1247
+ Map <Name , ExecutableElement2 > get declared2 {
1248
+ return declared.map ((name, element) =>
1249
+ MapEntry (name, (element as ExecutableFragment ).element));
1250
+ }
1251
+
1252
+ /// The map of names to their signature in the interface.
1253
+ @experimental
1254
+ Map <Name , ExecutableElement2 > get map2 {
1255
+ return map.map ((name, element) =>
1256
+ MapEntry (name, (element as ExecutableFragment ).element));
1257
+ }
1258
+
1117
1259
/// Return `true` if the [name] is implemented in the supertype.
1118
1260
bool isSuperImplemented (Name name) {
1119
1261
return superImplemented.last.containsKey (name);
0 commit comments