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

immutable: Add support for bean-style accessors #33

Closed
bhamiltoncx opened this issue Oct 28, 2014 · 3 comments
Closed

immutable: Add support for bean-style accessors #33

bhamiltoncx opened this issue Oct 28, 2014 · 3 comments
Milestone

Comments

@bhamiltoncx
Copy link
Contributor

Our code style currently depends on value types with accessors named "getFoo()" and builders with setters named "setFoo()".

I can emulate the getters in the generated types with @Value.Getters, but the top-level interface then isn't useful (it will be missing the getters).

I can't emulate the setters in generated builders as far as I can tell.

It'd be really nice if we could do something like:

@Value.Immutable
@Value.GettersAndSetters
public interface Type {
  int getFoo();
  String getBar();
}

which would generate an ImmutableType with getFoo() and getBar(), and an ImmutableType.Builder with setFoo() and setBar().

@elucash elucash added this to the 0.33 milestone Oct 28, 2014
@elucash
Copy link
Member

elucash commented Oct 29, 2014

Things to consider to implement apply set/get style:

  1. Style detection (probably what google/auto/value does) or special annotation
  2. Decide how to augment or disallow downstream processors that could be not ready for such notation

@elucash elucash changed the title Add support for bean-style accessors immutable: Add support for bean-style accessors Oct 29, 2014
@elucash elucash modified the milestones: 1.1, 0.33 Oct 30, 2014
@elucash
Copy link
Member

elucash commented Nov 2, 2014

I have the answers

  1. Style detection is out of favor. I think @AutoValue may try this because they don't have builders and so small in functionality, but not Immutables. Let's consider and example if we would implement bean style detection:
interface Val {
   boolean isVal();
}
...
ImmutableValue.builder()
    .val(true)
    .builder();

Well, now it's ok, auto-detection of style consider that as a bean-style. Then I add an non-mandatory accessor in non-bean style, which will disable bean-style detected previously

interface Val {
   boolean isVal();
   List<String> value();
}
...
ImmutableValue.builder()
    .isVal(true)  // Oops, setter API for `val` attribute just changed?
    .builder();

Maybe it's not a problem, but it's very awkward. I think that annotation should control style to make API more stable.

  1. Other processors will have to use common infrastructure to insert proper naming.

So now we will construct some infrastructure to handle naming, and let's have it flexible as hell...

@elucash
Copy link
Member

elucash commented Dec 21, 2014

Customization infrastructure now allows to tailor generated immutable types and builders to wide range of style and preferences

  • see @Value.Style
  • @BeanStyle.Accessors is example of style annotations - allows accessors to be detected from with 'get' and 'is' prefixes, so prefix will be stripped on builder and in toString.

@elucash elucash closed this as completed Dec 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants