Skip to content
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

Add flag to add concrete setters for optionals #94

Merged
merged 2 commits into from
Mar 21, 2022

Conversation

mads-b
Copy link
Contributor

@mads-b mads-b commented Mar 7, 2022

In my adventure to replace Immutables.org, I stumbled upon yet another nifty feature:

If you are setting an optional field, you are probably intending to set a concrete value.

So here is this PR that adds setters that take concrete values and wrap them in optional prior to insertion into the record.

@Randgalt Randgalt added this to the v33 milestone Mar 20, 2022
@Randgalt Randgalt added the question Further information is requested label Mar 20, 2022
@Randgalt
Copy link
Owner

Randgalt commented Mar 20, 2022

@mads-b, for completeness, please add a test Record that has Optional components but with addConcreteSettersForOptional not enabled. Basically, make sure all the permutations are tested.

@Randgalt Randgalt removed the question Further information is requested label Mar 21, 2022
@Randgalt
Copy link
Owner

@mads-b Looks good - please rebase with master

@Randgalt Randgalt added the question Further information is requested label Mar 21, 2022

static Optional<OptionalType> fromClassType(final ClassType component) {
if (isOptional(component)) {
if (!(component.typeName() instanceof ParameterizedTypeName)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can be:

if (!(component.typeName() instanceof ParameterizedTypeName parameterizedType))

@mads-b mads-b force-pushed the feature/concreteoptional branch from 0820224 to 50beec3 Compare March 21, 2022 09:05
@mads-b mads-b force-pushed the feature/concreteoptional branch from 50beec3 to 87a6ca3 Compare March 21, 2022 09:07
@Randgalt Randgalt merged commit efd1a6b into Randgalt:master Mar 21, 2022
@Randgalt Randgalt removed the question Further information is requested label Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants