Skip to content

Commit ddf4a68

Browse files
bwilkersonCommit Queue
authored and
Commit Queue
committed
Add new element model members to InheritanceManager3
Change-Id: I08e8f9d956c514728ec27d0dc1f68a1d1f323850 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387062 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
1 parent 2cf6ba2 commit ddf4a68

File tree

3 files changed

+1651
-4
lines changed

3 files changed

+1651
-4
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4482,7 +4482,14 @@ mixin FragmentedFunctionTypedElementMixin<E extends ExecutableFragment>
44824482
// TODO(augmentations): This is wrong. The function type needs to be a merge
44834483
// of the function types of all of the fragments, but I don't know how to
44844484
// perform that merge.
4485-
FunctionType get type => (firstFragment as FunctionTypedElementImpl).type;
4485+
FunctionType get type {
4486+
if (firstFragment is ExecutableElementImpl) {
4487+
return (firstFragment as ExecutableElementImpl).type;
4488+
} else if (firstFragment is FunctionTypedElementImpl) {
4489+
return (firstFragment as FunctionTypedElementImpl).type;
4490+
}
4491+
throw UnimplementedError();
4492+
}
44864493
}
44874494

44884495
mixin FragmentedTypeParameterizedElementMixin<
@@ -9023,9 +9030,7 @@ class SetterElementImpl extends ExecutableElementImpl2
90239030
firstFragment.correspondingGetter2?.element as GetterElement?;
90249031

90259032
@override
9026-
String get displayName {
9027-
return name.substring(0, name.length - 1);
9028-
}
9033+
String get displayName => name.substring(0, name.length - 1);
90299034

90309035
@override
90319036
Element2? get enclosingElement2 => firstFragment.enclosingFragment?.element;

pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/element/element.dart';
6+
import 'package:analyzer/dart/element/element2.dart';
67
import 'package:analyzer/dart/element/type.dart';
78
import 'package:analyzer/src/dart/element/element.dart';
89
import 'package:analyzer/src/dart/element/extensions.dart';
910
import 'package:analyzer/src/dart/element/member.dart';
1011
import 'package:analyzer/src/dart/element/type_algebra.dart';
1112
import 'package:analyzer/src/dart/element/type_system.dart';
1213
import 'package:analyzer/src/utilities/extensions/collection.dart';
14+
import 'package:meta/meta.dart';
1315

1416
/// Failure because of there is no most specific signature in [candidates].
1517
class CandidatesConflict extends Conflict {
@@ -145,6 +147,40 @@ class InheritanceManager3 {
145147
return getInheritedMap2(element)[name];
146148
}
147149

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+
148184
/// Return signatures of all concrete members that the given [element] inherits
149185
/// from the superclasses and mixins.
150186
Map<Name, ExecutableElement> getInheritedConcreteMap2(
@@ -157,6 +193,20 @@ class InheritanceManager3 {
157193
return interface.superImplemented.last;
158194
}
159195

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+
160210
/// Return the mapping from names to most specific signatures of members
161211
/// inherited from the super-interfaces (superclasses, mixins, and
162212
/// interfaces). If there is no most specific signature for a name, the
@@ -211,6 +261,15 @@ class InheritanceManager3 {
211261
return result;
212262
}
213263

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+
214273
/// Return the result of [getMember2] with [type] substitution.
215274
ExecutableElement? getMember(
216275
InterfaceType type,
@@ -274,6 +333,75 @@ class InheritanceManager3 {
274333
return interface.map[name];
275334
}
276335

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+
277405
/// Return all members of mixins, superclasses, and interfaces that a member
278406
/// with the given [name], defined in the [element], would override; or `null`
279407
/// if no members would be overridden.
@@ -1114,6 +1242,20 @@ class Interface {
11141242
required this.conflicts,
11151243
});
11161244

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+
11171259
/// Return `true` if the [name] is implemented in the supertype.
11181260
bool isSuperImplemented(Name name) {
11191261
return superImplemented.last.containsKey(name);

0 commit comments

Comments
 (0)