Skip to content

Refactor containers to better reflect current Dart behavior #2770

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

Conversation

jcollins-g
Copy link
Contributor

@jcollins-g jcollins-g commented Sep 1, 2021

This is essentially a continuation and mop up after #2206. The PR extracts a parent class, InheritingContainer, from Class for Containers that participate in inheritance. It also extracts a mixin, Constructable, for containers that can have programmer referable constructors, a mixin TypeImplementing for containers that can implement types and be implemented, and a mixin MixedInTypes for containers that can mix-in mixins.

This is because:

Extensions are really a container that doesn't do any of these things and so needs a different common parent.
Enums participate in inheritance (e.g. toString()) but can not be implemented nor implement other things, nor can they be constructed.
Mixins can implement types and participate in inheritance but are not constructable nor can they mix in mixins.
Classes do all of these things including mixing in mixins.

This is a breaking change as it changes the templates to no longer allow trying to render Mixin constructors, you can no longer refer to the constructor of a Mixin in comment references, and some useless things the templates were doing are now deleted and can no longer be attempted in custom templates, either.

@google-cla google-cla bot added the cla: yes Google CLA check succeeded. label Sep 1, 2021
@jcollins-g jcollins-g requested a review from srawlins September 3, 2021 15:17
Copy link
Member

@srawlins srawlins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool! Lots of consolidation; less generated code too.

@@ -0,0 +1,617 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2021

import 'package:dartdoc/src/quiver.dart' as quiver;
import 'package:meta/meta.dart';

/// An mixin to build an [InheritingContainer] capable of being constructed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"A" mixin

.map((e) => ModelElement.from(e, library, packageGraph) as Constructor);

@override
bool get hasPublicConstructors => publicConstructors.isNotEmpty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that publicConstructors is not memoized, so this call may be expensive if made repeatedly. What's funny is that publicConstructorsSorted is memoized, so using that one instead of publicConstructors would be cheaper on successive calls... not sure if there is an AI here; maybe hasPublicConstructors is not called repeatedly...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm. all the has* calls tend to be used a fair bit, but generally only once or at most twice per object. This one is only used once; the calls that are part of hasModifiers are used twice. I think I will just punt on this as if I mess with this now I'll need to do it again with the NNBD pass as the implementation is different. But there may be some other nearby areas where we could gain from caching the lists in a smarter way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to cache constructors -- that is used in a few places, and will help.

DefinedElementType get supertype => _supertype;

@Deprecated('Field intended to be final; setter will be removed as early as '
'Dartdoc 1.0.0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps now is a good time to make final?


List<TypeParameter> _typeParameters;

// a stronger hash?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a TODO or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like leftovers from previous cut and paste refactoring adventures. removing

@jcollins-g jcollins-g merged commit 4e73d72 into dart-lang:master Sep 3, 2021
@jcollins-g jcollins-g deleted the inheriting-container-extraction branch September 3, 2021 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants