-
Notifications
You must be signed in to change notification settings - Fork 125
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
Refactor containers to better reflect current Dart behavior #2770
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
This is essentially a continuation and mop up after #2206. The PR extracts a parent class,
InheritingContainer
, fromClass
forContainer
s that participate in inheritance. It also extracts a mixin,Constructable
, for containers that can have programmer referable constructors, a mixinTypeImplementing
for containers that can implement types and be implemented, and a mixinMixedInTypes
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.Mixin
s can implement types and participate in inheritance but are not constructable nor can they mix in mixins.Class
es 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.