Skip to content

Simplify how inheritance is computed. #4079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 2 additions & 140 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2734,34 +2734,6 @@ class _Renderer_Class extends RendererBase<Class> {
);
},
),
'inheritanceChain': Property(
getValue: (CT_ c) => c.inheritanceChain,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(
c,
remainingNames,
'List<InheritingContainer>',
),

renderIterable:
(
CT_ c,
RendererBase<CT_> r,
List<MustachioNode> ast,
StringSink sink,
) {
return c.inheritanceChain.map(
(e) => _render_InheritingContainer(
e,
ast,
r.template,
sink,
parent: r,
),
);
},
),
'isAbstract': Property(
getValue: (CT_ c) => c.isAbstract,
renderVariable:
Expand Down Expand Up @@ -7213,34 +7185,6 @@ class _Renderer_Enum extends RendererBase<Enum> {
);
},
),
'inheritanceChain': Property(
getValue: (CT_ c) => c.inheritanceChain,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(
c,
remainingNames,
'List<InheritingContainer>',
),

renderIterable:
(
CT_ c,
RendererBase<CT_> r,
List<MustachioNode> ast,
StringSink sink,
) {
return c.inheritanceChain.map(
(e) => _render_InheritingContainer(
e,
ast,
r.template,
sink,
parent: r,
),
);
},
),
'isAbstract': Property(
getValue: (CT_ c) => c.isAbstract,
renderVariable:
Expand Down Expand Up @@ -8519,34 +8463,6 @@ class _Renderer_ExtensionType extends RendererBase<ExtensionType> {
);
},
),
'inheritanceChain': Property(
getValue: (CT_ c) => c.inheritanceChain,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(
c,
remainingNames,
'List<InheritingContainer>',
),

renderIterable:
(
CT_ c,
RendererBase<CT_> r,
List<MustachioNode> ast,
StringSink sink,
) {
return c.inheritanceChain.map(
(e) => _render_InheritingContainer(
e,
ast,
r.template,
sink,
parent: r,
),
);
},
),
'isAbstract': Property(
getValue: (CT_ c) => c.isAbstract,
renderVariable:
Expand Down Expand Up @@ -11894,34 +11810,6 @@ class _Renderer_InheritingContainer extends RendererBase<InheritingContainer> {

getBool: (CT_ c) => c.hasPublicSuperChainReversed,
),
'inheritanceChain': Property(
getValue: (CT_ c) => c.inheritanceChain,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(
c,
remainingNames,
'List<InheritingContainer>',
),

renderIterable:
(
CT_ c,
RendererBase<CT_> r,
List<MustachioNode> ast,
StringSink sink,
) {
return c.inheritanceChain.map(
(e) => _render_InheritingContainer(
e,
ast,
r.template,
sink,
parent: r,
),
);
},
),
'instanceFields': Property(
getValue: (CT_ c) => c.instanceFields,
renderVariable:
Expand Down Expand Up @@ -15922,34 +15810,6 @@ class _Renderer_Mixin extends RendererBase<Mixin> {

getBool: (CT_ c) => c.hasPublicSuperclassConstraints,
),
'inheritanceChain': Property(
getValue: (CT_ c) => c.inheritanceChain,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(
c,
remainingNames,
'List<InheritingContainer>',
),

renderIterable:
(
CT_ c,
RendererBase<CT_> r,
List<MustachioNode> ast,
StringSink sink,
) {
return c.inheritanceChain.map(
(e) => _render_InheritingContainer(
e,
ast,
r.template,
sink,
parent: r,
),
);
},
),
'isAbstract': Property(
getValue: (CT_ c) => c.isAbstract,
renderVariable:
Expand Down Expand Up @@ -25741,6 +25601,7 @@ const _invisibleGetters = {
'nonSynthetic2',
'runtimeType',
'session',
'sinceSdkVersion',
},
'EnumElement2': {
'constants2',
Expand Down Expand Up @@ -26192,6 +26053,7 @@ const _invisibleGetters = {
'baseElement',
'children',
'children2',
'constantInitializer',
'constantInitializer2',
'context',
'declaration',
Expand Down
21 changes: 1 addition & 20 deletions lib/src/model/class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import 'package:dartdoc/src/model/model.dart';
/// **instance**: As with [Container], but also includes inherited children.
/// **inherited**: Filtered getters giving only inherited children.
class Class extends InheritingContainer with Constructable, MixedInTypes {
@override

@override
final ClassElement2 element;

Expand All @@ -29,22 +27,6 @@ class Class extends InheritingContainer with Constructable, MixedInTypes {
String get sidebarPath =>
'${canonicalLibraryOrThrow.dirName}/$name-class-sidebar.html';

@override
late final List<InheritingContainer> inheritanceChain = [
this,

// Caching should make this recursion a little less painful.
for (var container in mixedInTypes.modelElements.reversed)
...container.inheritanceChain,

for (var container in superChain.modelElements)
...container.inheritanceChain,

// Interfaces need to come last, because classes in the superChain might
// implement them even when they aren't mentioned.
...interfaceElements.expandInheritanceChain,
];

Class(this.element, Library library, PackageGraph packageGraph)
: super(library, packageGraph) {
if (element.name3 == 'Object' &&
Expand Down Expand Up @@ -75,8 +57,7 @@ class Class extends InheritingContainer with Constructable, MixedInTypes {
bool get isFinal => element.isFinal && !element.isSealed;

@override
bool get isImplementableInterface =>
element.isInterface && !element.isSealed;
bool get isImplementableInterface => element.isInterface && !element.isSealed;

@override
bool get isMixinClass => element.isMixinClass;
Expand Down
10 changes: 0 additions & 10 deletions lib/src/model/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ class Enum extends InheritingContainer with Constructable, MixedInTypes {
...constructors,
];

@override
late final List<InheritingContainer> inheritanceChain = [
this,
for (var container in mixedInTypes.modelElements.reversed)
...container.inheritanceChain,
for (var container in superChain.modelElements)
...container.inheritanceChain,
...interfaceElements.expandInheritanceChain,
];

@override
// Prevent a collision with the library file.
String get fileName => name == 'index' ? '$name-enum.html' : '$name.html';
Expand Down
15 changes: 3 additions & 12 deletions lib/src/model/extension_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import 'package:dartdoc/src/model/model.dart';
import 'package:meta/meta.dart';

class ExtensionType extends InheritingContainer with Constructable {

@override
final ExtensionTypeElement2 element;
final ExtensionTypeElement2 element;

late final ElementType representationType =
getTypeFor(element.representation2.type, library);
Expand Down Expand Up @@ -45,13 +44,11 @@ class ExtensionType extends InheritingContainer with Constructable {
ContainerAccessor? getter, setter;
final fieldGetter = field.getter2;
if (fieldGetter != null) {
getter = ContainerAccessor(
fieldGetter, library, packageGraph, this);
getter = ContainerAccessor(fieldGetter, library, packageGraph, this);
}
final fieldSetter = field.setter2;
if (fieldSetter != null) {
setter = ContainerAccessor(
fieldSetter, library, packageGraph, this);
setter = ContainerAccessor(fieldSetter, library, packageGraph, this);
}
return getModelForPropertyInducingElement(field, library,
getter: getter, setter: setter) as Field;
Expand All @@ -63,12 +60,6 @@ class ExtensionType extends InheritingContainer with Constructable {
...constructors,
];

@override
late final List<InheritingContainer> inheritanceChain = [
this,
...interfaceElements.expandInheritanceChain,
];

@override
String get fileName => '$name-extension-type.html';

Expand Down
Loading
Loading