-
Notifications
You must be signed in to change notification settings - Fork 564
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
Avoid using replicated default values for Lists when creating from builder or instance #8428
Avoid using replicated default values for Lists when creating from builder or instance #8428
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 actually has impact on semantics of the behavior. If you have a built value with a list containing duplicate entries (which is valid and expected), you will remove them (because of using something like addDistinctStrings(prototype.strings());
as in DualValuedDefaultValues
.
I am not in favor of this behavior. I think we can do distinct for the first instances of the default values themself (this is still not perfect), or we will need to add some concept of "dirty" flag for this kind of fields - i.e. the user has either called clear
, or set
on this field, it is customized. If we call from
on a non-customized field, we could just call clear
and set
for the values.
I think this deserves a bit of an analysis on the possible states of these fields, to find the right solution.
Noted. Good point. I have an idea for a fairly clean way to handle this differently. Work in progress. |
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 have commented in the PR, requesting changes so it does not get merged.
…ilder or instances Signed-off-by: Tim Quinn <[email protected]>
8a7528c
to
fd51901
Compare
I edited the PR description of how the PR changes the code. |
…values have been mutated
Description
Resolves #8324
When populating a new builder's
List
propertyXXX
from either a builder or an instance, the generatedfrom
code usedaddXXX
. But theList
for the property in the new builder had already been initialized with the default values so this code improperly added those default values again.The PR causes the builder to generate a newprotected
methodaddDistinctXXX
for eachList
property, and the generatedfrom
methods now invoke that method instead ofaddXXX
to avoid adding duplicate default values to the new builder.This PR enhances the code generator so it:
isXxxMutated
boolean for eachList
propertyxxx
.isXxxMutated
totrue
in the generatedaddXxx
andxxx
methods.from
methods so, before adding the corresponding values from the referenced instance or other builder, checks to see ifisXxxMutated
is true:from
merges the values in the current builder with those from the other object.from
overwrites the values in the current builder with those from the other object.Note: Further, the generator creates each
from(Builder)
method so that, ifthis
builder'sxxx
values have been mutated then the values from the other builder are added only if the other builder's values were also mutated. This prevents incorrectly adding defaulted values from the other builder to the mutated values inthis
builder.The same approach is not currently taken in generating the
from(Prototype)
method. That can be a later refinement if the need arises and would require addingisXxxMutated
to the generated implementation class and setting it based on the builder's value ofisXxxMutated
.The PR adds tests for
List
properties with single-valued defaults and dual-valued defaults.This PR touches some files also touched by Tomas's big PR but these changes are minor and should be easily reconciled.
Documentation
Bug fix - no doc impact.