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 support for Nullable on Optional property builders #353

Closed

Conversation

octylFractal
Copy link
Contributor

@octylFractal octylFractal commented Jul 1, 2016

This allows an @Nullable annotation to exist on a Builder property setter for an Optional property, like so: Builder bar(@Nullable String bar);. It uses ofNullable/fromNullable to convert the value to the correct Optional instance. This PR also replaces the logic in the Builder property getters to use ofNullable/fromNullable instead of an if ($p == null) check. (Edit: This doesn't work with Optional primitives + wrapper classes.)

This solves my request here: #278 (comment), and #384.

@Enfernuz
Copy link

Any plans on merging this in the near future?

@eamonnmcmanus
Copy link
Member

I'm reworking other aspects of builders at the moment but I will look into this when I am done.

@octylFractal
Copy link
Contributor Author

I've just rebased onto the latest master, to resolve merge conflicts.

@octylFractal octylFractal force-pushed the feature/optional-from-nullable branch 4 times, most recently from d19bb33 to 6a9bfe5 Compare March 8, 2017 03:45
@octylFractal
Copy link
Contributor Author

It's been updated again to handle the latest changes.

@eamonnmcmanus
Copy link
Member

It looks as if there's still a test failure.

I'm hoping to cut AutoValue 1.4 soon, but I will look at this and #444 once that is done. Thanks for putting in the work to put them together!

@eamonnmcmanus
Copy link
Member

Meanwhile, can I ask that you add test code to AutoValueTest in this PR and the other one?

@octylFractal
Copy link
Contributor Author

Let me know if you would like any other test cases for this PR.

@octylFractal octylFractal force-pushed the feature/optional-from-nullable branch from 00e3251 to 365b1c7 Compare March 9, 2017 19:28
@PierreMage
Copy link

Is it planned to merge this PR in the near future?

@gmalmquist
Copy link

Any activity happening on this? Has this been superseded by something else?

@smac89
Copy link

smac89 commented May 3, 2018

I'm surprised this hasn't been merged yet. What is the delay (apart from the conflicts which keep getting fixed)?

@eonwhite
Copy link

eonwhite commented May 3, 2018

I'd also love to see this feature get merged. It's really my only complaint with AutoValue -- right now the workaround (creating two versions of every builder method where you want to allow passing null) is very tedious.

@octylFractal octylFractal force-pushed the feature/optional-from-nullable branch from 365b1c7 to 824568f Compare May 3, 2018 20:14
@octylFractal
Copy link
Contributor Author

I've just fixed up this PR to match master. I do have concerns over not having the static method AutoValueProcessor.nullableAnnotationIfInList, but I don't see a better place for it.

@octylFractal octylFractal force-pushed the feature/optional-from-nullable branch from 677a905 to 99438ae Compare May 3, 2018 20:19
@eamonnmcmanus
Copy link
Member

Sorry to have dropped the ball on this. I've put together a modified version of this change and am sending it out for internal review. Thanks, @kenzierocks!

@ronshapiro ronshapiro mentioned this pull request May 7, 2018
ronshapiro pushed a commit that referenced this pull request May 7, 2018
…th a @nullable parameter.

This is based on #353 by Kenzie Togami.

Closes #353.

RELNOTES:
  Allow an Optional property to be set in a builder through a method with a @nullable parameter.
  NOTE: As a side-effect of this change, a setter for a @nullable property must have its parameter also marked @nullable. Previously, if the @nullable was not a TYPE_USE @nullable, it was copied from the getter to the parameter of the generated setter implementation. For TYPE_USE @nullable it was already necessary to mark the setter parameter @nullable.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=195471227
ronshapiro pushed a commit that referenced this pull request May 8, 2018
…th a @nullable parameter.

This is based on #353 by Kenzie Togami.

Closes #353.

RELNOTES:
  Allow an Optional property to be set in a builder through a method with a @nullable parameter.
  NOTE: As a side-effect of this change, a setter for a @nullable property must have its parameter also marked @nullable. Previously, if the @nullable was not a TYPE_USE @nullable, it was copied from the getter to the parameter of the generated setter implementation. For TYPE_USE @nullable it was already necessary to mark the setter parameter @nullable.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=195471227
@octylFractal octylFractal deleted the feature/optional-from-nullable branch May 8, 2018 19:13
bestreviewsbookssoftware12 added a commit to bestreviewsbookssoftware12/auto that referenced this pull request Aug 24, 2024
…th a @nullable parameter.

This is based on google/auto#353 by Kenzie Togami.

Closes google/auto#353.

RELNOTES:
  Allow an Optional property to be set in a builder through a method with a @nullable parameter.
  NOTE: As a side-effect of this change, a setter for a @nullable property must have its parameter also marked @nullable. Previously, if the @nullable was not a TYPE_USE @nullable, it was copied from the getter to the parameter of the generated setter implementation. For TYPE_USE @nullable it was already necessary to mark the setter parameter @nullable.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=195471227
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants