Skip to content

Commit 40c470e

Browse files
authored
Display the known 'implementers' of an extension type (#3682)
Also, re-spell each instance of 'implementor' to 'implementer'
1 parent 5ea87b2 commit 40c470e

9 files changed

+115
-69
lines changed

lib/src/generator/templates.aot_renderers_for_html.dart

+25-7
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,12 @@ String renderClass(ClassTemplateData context0) {
322322
buffer.write('\n ');
323323
buffer.write(_renderClass_partial_mixed_in_types_7(context2));
324324
buffer.writeln();
325-
if (context2.hasPublicImplementors) {
325+
if (context2.hasPublicImplementers) {
326326
buffer.writeln();
327327
buffer.write('''
328328
<dt>Implementers</dt>
329329
<dd><ul class="comma-separated clazz-relationships">''');
330-
var context3 = context2.publicImplementorsSorted;
330+
var context3 = context2.publicImplementersSorted;
331331
for (var context4 in context3) {
332332
buffer.writeln();
333333
buffer.write('''
@@ -865,6 +865,24 @@ String renderExtensionType<T extends ExtensionType>(
865865
''');
866866
buffer.write(_renderExtensionType_partial_interfaces_5(context2));
867867
buffer.writeln();
868+
if (context2.hasPublicImplementers) {
869+
buffer.writeln();
870+
buffer.write('''
871+
<dt>Implementers</dt>
872+
<dd><ul class="comma-separated clazz-relationships">''');
873+
var context4 = context2.publicImplementersSorted;
874+
for (var context5 in context4) {
875+
buffer.writeln();
876+
buffer.write('''
877+
<li>''');
878+
buffer.write(context5.linkedName);
879+
buffer.write('''</li>''');
880+
}
881+
buffer.writeln();
882+
buffer.write('''
883+
</ul></dd>''');
884+
}
885+
buffer.writeln();
868886
buffer.write('''
869887
</dl>
870888
''');
@@ -883,10 +901,10 @@ String renderExtensionType<T extends ExtensionType>(
883901
<h2>Properties</h2>
884902
885903
<dl class="properties">''');
886-
var context4 = context2.publicInstanceFieldsSorted;
887-
for (var context5 in context4) {
904+
var context6 = context2.publicInstanceFieldsSorted;
905+
for (var context7 in context6) {
888906
buffer.write('\n ');
889-
buffer.write(_renderExtensionType_partial_property_8(context5));
907+
buffer.write(_renderExtensionType_partial_property_8(context7));
890908
}
891909
buffer.writeln();
892910
buffer.write('''
@@ -1528,13 +1546,13 @@ String renderMixin(MixinTemplateData context0) {
15281546
buffer.write('\n ');
15291547
buffer.write(_renderMixin_partial_interfaces_6(context2));
15301548
buffer.writeln();
1531-
if (context2.hasPublicImplementors) {
1549+
if (context2.hasPublicImplementers) {
15321550
buffer.writeln();
15331551
buffer.write('''
15341552
<dt>Mixin Applications</dt>
15351553
<dd>
15361554
<ul class="comma-separated mixin-relationships">''');
1537-
var context5 = context2.publicImplementorsSorted;
1555+
var context5 = context2.publicImplementersSorted;
15381556
for (var context6 in context5) {
15391557
buffer.writeln();
15401558
buffer.write('''

lib/src/generator/templates.runtime_renderers.dart

+11-11
Original file line numberDiff line numberDiff line change
@@ -15225,12 +15225,12 @@ class _Renderer_TypeImplementing extends RendererBase<TypeImplementing> {
1522515225
self.renderSimpleVariable(c, remainingNames, 'bool'),
1522615226
getBool: (CT_ c) => c.hasModifiers,
1522715227
),
15228-
'hasPublicImplementors': Property(
15229-
getValue: (CT_ c) => c.hasPublicImplementors,
15228+
'hasPublicImplementers': Property(
15229+
getValue: (CT_ c) => c.hasPublicImplementers,
1523015230
renderVariable: (CT_ c, Property<CT_> self,
1523115231
List<String> remainingNames) =>
1523215232
self.renderSimpleVariable(c, remainingNames, 'bool'),
15233-
getBool: (CT_ c) => c.hasPublicImplementors,
15233+
getBool: (CT_ c) => c.hasPublicImplementers,
1523415234
),
1523515235
'hasPublicInterfaces': Property(
1523615236
getValue: (CT_ c) => c.hasPublicInterfaces,
@@ -15265,28 +15265,28 @@ class _Renderer_TypeImplementing extends RendererBase<TypeImplementing> {
1526515265
parent: r));
1526615266
},
1526715267
),
15268-
'publicImplementors': Property(
15269-
getValue: (CT_ c) => c.publicImplementors,
15268+
'publicImplementers': Property(
15269+
getValue: (CT_ c) => c.publicImplementers,
1527015270
renderVariable: (CT_ c, Property<CT_> self,
1527115271
List<String> remainingNames) =>
1527215272
self.renderSimpleVariable(
1527315273
c, remainingNames, 'Iterable<InheritingContainer>'),
1527415274
renderIterable: (CT_ c, RendererBase<CT_> r,
1527515275
List<MustachioNode> ast, StringSink sink) {
15276-
return c.publicImplementors.map((e) =>
15276+
return c.publicImplementers.map((e) =>
1527715277
_render_InheritingContainer(e, ast, r.template, sink,
1527815278
parent: r));
1527915279
},
1528015280
),
15281-
'publicImplementorsSorted': Property(
15282-
getValue: (CT_ c) => c.publicImplementorsSorted,
15281+
'publicImplementersSorted': Property(
15282+
getValue: (CT_ c) => c.publicImplementersSorted,
1528315283
renderVariable: (CT_ c, Property<CT_> self,
1528415284
List<String> remainingNames) =>
1528515285
self.renderSimpleVariable(
1528615286
c, remainingNames, 'List<InheritingContainer>'),
1528715287
renderIterable: (CT_ c, RendererBase<CT_> r,
1528815288
List<MustachioNode> ast, StringSink sink) {
15289-
return c.publicImplementorsSorted.map((e) =>
15289+
return c.publicImplementersSorted.map((e) =>
1529015290
_render_InheritingContainer(e, ast, r.template, sink,
1529115291
parent: r));
1529215292
},
@@ -16846,7 +16846,7 @@ const _invisibleGetters = {
1684616846
'allConstructedModelElements',
1684716847
'allExtensionsAdded',
1684816848
'allHrefs',
16849-
'allImplementorsAdded',
16849+
'allImplementersAdded',
1685016850
'allInheritableElements',
1685116851
'allLibraries',
1685216852
'allLibrariesAdded',
@@ -16862,7 +16862,7 @@ const _invisibleGetters = {
1686216862
'hasEmbedderSdk',
1686316863
'hasFooterVersion',
1686416864
'hashCode',
16865-
'implementors',
16865+
'implementers',
1686616866
'inheritThrough',
1686716867
'inheritanceManager',
1686816868
'libraries',

lib/src/model/inheriting_container.dart

+21-21
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,14 @@ mixin TypeImplementing on InheritingContainer {
503503
getTypeFor(interface, library) as DefinedElementType
504504
];
505505

506-
late final List<InheritingContainer> publicImplementorsSorted =
507-
publicImplementors.toList(growable: false)..sort(byName);
506+
late final List<InheritingContainer> publicImplementersSorted =
507+
publicImplementers.toList(growable: false)..sort(byName);
508508

509509
@override
510510
bool get hasModifiers =>
511-
super.hasModifiers || hasPublicInterfaces || hasPublicImplementors;
511+
super.hasModifiers || hasPublicInterfaces || hasPublicImplementers;
512512

513-
bool get hasPublicImplementors => publicImplementors.isNotEmpty;
513+
bool get hasPublicImplementers => publicImplementers.isNotEmpty;
514514

515515
bool get hasPublicInterfaces => publicInterfaces.isNotEmpty;
516516

@@ -522,34 +522,34 @@ mixin TypeImplementing on InheritingContainer {
522522
interface.modelElement as InheritingContainer,
523523
];
524524

525-
/// All the "immediate" public implementors of this [TypeImplementing].
525+
/// All the "immediate" public implementers of this [TypeImplementing].
526526
///
527527
/// For a [Mixin], this is actually the mixin applications using the [Mixin].
528528
///
529-
/// If this [InheritingContainer] has a private implementor, then that is
530-
/// counted as a proxy for any public implementors of that private container.
531-
Iterable<InheritingContainer> get publicImplementors {
529+
/// If this [InheritingContainer] has a private implementer, then that is
530+
/// counted as a proxy for any public implementers of that private container.
531+
Iterable<InheritingContainer> get publicImplementers {
532532
var result = <InheritingContainer>{};
533533
var seen = <InheritingContainer>{};
534534

535-
// Recursively adds [implementor] if public, or the implementors of
536-
// [implementor] if not.
537-
void addToResult(InheritingContainer implementor) {
538-
if (seen.contains(implementor)) return;
539-
seen.add(implementor);
540-
if (implementor.isPublicAndPackageDocumented) {
541-
result.add(implementor);
535+
// Recursively adds [implementer] if public, or the implementers of
536+
// [implementer] if not.
537+
void addToResult(InheritingContainer implementer) {
538+
if (seen.contains(implementer)) return;
539+
seen.add(implementer);
540+
if (implementer.isPublicAndPackageDocumented) {
541+
result.add(implementer);
542542
} else {
543-
var implementors = packageGraph.implementors[implementor];
544-
if (implementors != null) {
545-
model_utils.findCanonicalFor(implementors).forEach(addToResult);
543+
var implementers = packageGraph.implementers[implementer];
544+
if (implementers != null) {
545+
model_utils.findCanonicalFor(implementers).forEach(addToResult);
546546
}
547547
}
548548
}
549549

550-
var immediateImplementors = packageGraph.implementors[this];
551-
if (immediateImplementors != null) {
552-
model_utils.findCanonicalFor(immediateImplementors).forEach(addToResult);
550+
var immediateImplementers = packageGraph.implementers[this];
551+
if (immediateImplementers != null) {
552+
model_utils.findCanonicalFor(immediateImplementers).forEach(addToResult);
553553
}
554554
return result;
555555
}

lib/src/model/package_graph.dart

+14-10
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class PackageGraph with CommentReferable, Nameable {
145145
package.warn(PackageWarning.noDocumentableLibrariesInPackage);
146146
}
147147
}
148-
allImplementorsAdded = true;
148+
allImplementersAdded = true;
149149
allExtensionsAdded = true;
150150

151151
// We should have found all special classes by now.
@@ -280,17 +280,17 @@ class PackageGraph with CommentReferable, Nameable {
280280

281281
ModelNode? getModelNodeFor(Element element) => _modelNodes[element];
282282

283-
/// It is safe to cache values derived from the [_implementors] table if this
283+
/// It is safe to cache values derived from the [_implementers] table if this
284284
/// is true.
285-
bool allImplementorsAdded = false;
285+
bool allImplementersAdded = false;
286286

287287
/// It is safe to cache values derived from the [_extensions] table if this
288288
/// is true.
289289
bool allExtensionsAdded = false;
290290

291-
Map<InheritingContainer, List<InheritingContainer>> get implementors {
292-
assert(allImplementorsAdded);
293-
return _implementors;
291+
Map<InheritingContainer, List<InheritingContainer>> get implementers {
292+
assert(allImplementersAdded);
293+
return _implementers;
294294
}
295295

296296
Iterable<Extension> get documentedExtensions =>
@@ -323,8 +323,12 @@ class PackageGraph with CommentReferable, Nameable {
323323
final Map<InheritableElementsKey, Set<ModelElement>> allInheritableElements =
324324
{};
325325

326-
/// A mapping of the list of classes which implement each class.
327-
final Map<InheritingContainer, List<InheritingContainer>> _implementors =
326+
/// A mapping of the list of classes, enums, mixins, and extension types which
327+
/// "implement" each class, mixin, and extension type.
328+
///
329+
/// For the purposes of the "Implementers" section in the output, this
330+
/// includes elements that "implement" or "extend" another element.
331+
final Map<InheritingContainer, List<InheritingContainer>> _implementers =
328332
LinkedHashMap<InheritingContainer, List<InheritingContainer>>(
329333
equals: (InheritingContainer a, InheritingContainer b) =>
330334
a.definingContainer == b.definingContainer,
@@ -575,7 +579,7 @@ class PackageGraph with CommentReferable, Nameable {
575579
}
576580

577581
void _addToImplementers(Iterable<InheritingContainer> containers) {
578-
assert(!allImplementorsAdded);
582+
assert(!allImplementersAdded);
579583

580584
// Private containers may not be included in documentation, but may still be
581585
// necessary links in the implementation chain. They are added here as they
@@ -589,7 +593,7 @@ class PackageGraph with CommentReferable, Nameable {
589593
}
590594
implemented = implemented.canonicalModelElement as InheritingContainer? ??
591595
implemented;
592-
var list = _implementors.putIfAbsent(implemented, () => []);
596+
var list = _implementers.putIfAbsent(implemented, () => []);
593597
// TODO(srawlins): This would be more efficient if we created a
594598
// SplayTreeSet keyed off of `.element`.
595599
if (!list.any((l) => l.element == implementer.element)) {

lib/templates/class.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
{{ >interfaces }}
2020
{{ >mixed_in_types }}
2121

22-
{{ #hasPublicImplementors }}
22+
{{ #hasPublicImplementers }}
2323
<dt>Implementers</dt>
2424
<dd><ul class="comma-separated clazz-relationships">
25-
{{ #publicImplementorsSorted }}
25+
{{ #publicImplementersSorted }}
2626
<li>{{{ linkedName }}}</li>
27-
{{ /publicImplementorsSorted }}
27+
{{ /publicImplementersSorted }}
2828
</ul></dd>
29-
{{ /hasPublicImplementors }}
29+
{{ /hasPublicImplementers }}
3030

3131
{{ #hasPotentiallyApplicableExtensions }}
3232
<dt>Available Extensions</dt>

lib/templates/extension_type.html

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
</ul>
2323
</dd>
2424
{{ >interfaces }}
25+
26+
{{ #hasPublicImplementers }}
27+
<dt>Implementers</dt>
28+
<dd><ul class="comma-separated clazz-relationships">
29+
{{ #publicImplementersSorted }}
30+
<li>{{{ linkedName }}}</li>
31+
{{ /publicImplementersSorted }}
32+
</ul></dd>
33+
{{ /hasPublicImplementers }}
2534
</dl>
2635
{{ >container_annotations }}
2736
</section>

lib/templates/mixin.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
{{ >super_chain }}
2828
{{ >interfaces }}
2929

30-
{{ #hasPublicImplementors }}
30+
{{ #hasPublicImplementers }}
3131
<dt>Mixin Applications</dt>
3232
<dd>
3333
<ul class="comma-separated mixin-relationships">
34-
{{ #publicImplementorsSorted }}
34+
{{ #publicImplementersSorted }}
3535
<li>{{{ linkedName }}}</li>
36-
{{ /publicImplementorsSorted }}
36+
{{ /publicImplementersSorted }}
3737
</ul>
3838
</dd>
39-
{{ /hasPublicImplementors }}
39+
{{ /hasPublicImplementers }}
4040

4141
{{ >annotations }}
4242
</dl>

0 commit comments

Comments
 (0)