Remove unnecessary Builder classes #3664
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Big ball of yarn that grew and grew.
The main idea is to remove a bunch of classes, whose necessity I never understood:
ElementTypeBuilder
(andImpl
),ModelElementBuilder
(andImpl
),ModelObjectBuilder
,ModelBuilder
, andModelBuilderInterface
. These might have had more of a purpose when we could output to HTML or Markdown, but their complexity is now unwarranted.The purpose they served is this: In order to fetch a ModelElement or ElementType from from the package graph, you always needed an instance of... the package graph. Putting a
*Builder*
in a class you're working in gave you a way to instantiate (or fetch from the package graph) a ModelElement or ElementType.But, lo and behold, we can declare that a
Nameable
must have aPackageGraph
, and then write little utility functions to fetch these things. Much simpler. Here are the other changes needed to facilitate this:I renamed the various factory constructors. I generally changed the word 'from' to 'for', because often the value that the factory constructor returns is a cached instance. It feels weird to me to say
ModelElement.from
some Element, when you know that you already have the instance, and you're just fetching it, using the Element as a key. In that case, I think 'for' is more appropriate.ModelElement._from
-->ModelElement.for_
ModelElement._fromElement
-->ModelElement.forElement
ModelElement._fromPropertyInducingElement
-->ModelElement.forPropertyInducingElement
ElementType._from
-->ElementType.for_
Nameable
, or aNameable
supertype... I think not worth it.Make Nameable a proper mixin. 👍
Move
_resolveMultiplyInheritedElement
to be an extension method, to the bottom of the library.I believe this may also open up nicer refactorings where some
late final
ElementType
fields do not need to be late. It might not be a hole in one, but once we're only relying onpackageGraph
, we may be able to assign some more instance fields at construction-time.Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.