Skip to content

Commit

Permalink
Deduplicate interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Aug 26, 2024
1 parent f7e8def commit 569aaa6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/src/model/inheriting_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,29 @@ abstract class InheritingContainer extends Container {
/// and so unlike other `public*` methods, is not a strict subset of
/// [directInterfaces] (the direct interfaces).
List<DefinedElementType> get publicInterfaces {
var interfaceElements = <InterfaceElement>{};
var interfaces = <DefinedElementType>[];

// Only interfaces with unique elements should be returned. Elements can
// implement an interface through multiple inheritance routes (e.g.
// `List<E>` implements `Iterable<E>` but also `_ListIterable<E>` which
// implements `EfficientLengthIterable<T>` which implements `Iterable<T>`),
// but there is no chance of type arguments differing, as that is illegal.
void addInterfaceIfUnique(DefinedElementType type) {
var firstPublicSuperElement = type.modelElement.element;
if (firstPublicSuperElement is InterfaceElement) {
if (interfaceElements.add(firstPublicSuperElement)) {
interfaces.add(type);
}
}
}

for (var interface in directInterfaces) {
var interfaceElement = interface.modelElement;

/// Do not recurse if we can find an element here.
if (interfaceElement.canonicalModelElement != null) {
interfaces.add(interface);
addInterfaceIfUnique(interface);
continue;
}
// Public types used to be unconditionally exposed here. However,
Expand All @@ -466,9 +482,9 @@ abstract class InheritingContainer extends Container {
}
var publicSuperChain = interfaceElement.superChain.wherePublic;
if (publicSuperChain.isNotEmpty) {
interfaces.add(publicSuperChain.first);
addInterfaceIfUnique(publicSuperChain.first);
}
interfaces.addAll(interfaceElement.publicInterfaces);
interfaceElement.publicInterfaces.forEach(addInterfaceIfUnique);
}
return interfaces;
}
Expand Down

0 comments on commit 569aaa6

Please sign in to comment.