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

@PropertyNames/@FactoryProperties could be optional #42

Closed
drekbour opened this issue Apr 2, 2013 · 3 comments
Closed

@PropertyNames/@FactoryProperties could be optional #42

drekbour opened this issue Apr 2, 2013 · 3 comments
Labels
Milestone

Comments

@drekbour
Copy link
Contributor

drekbour commented Apr 2, 2013

If no explicit naming is present via annotation, implicit naming can be used. This should not be a compile warning (some devs are happy for property names to be part of the contract of the class). Perhaps it can be noted in the generated javadoc?.

  • Add implicit naming code to BuilderModelProducer for factory-methods which do have properties but do NOT have @FactoryProperties
  • Add JavaDoc to StringTemplate templates regarding implicit naming
  • Add JavaDoc to StringTemplate templates @linking to source method/constructor which is used by the builder
  • Add tests for implicit naming
  • Update documentation regarding implicit naming
@mkarneim
Copy link
Owner

mkarneim commented Apr 3, 2013

I am not sure if I see the purpose of implicit property names for factory-method parameters (respectively constructor parameters).
At least, if we don't use something like paranamer in PB.

For example, given the following pojo:

@GeneratePojoBuilder
class MyPojo {
  private String firstname;
  private String surname;
  public MyPojo( String firstname, String surname) {
    this.firstname = firstname;
    this.surname = surname;
  }
}

would create a PojoBuilder like this:

class MyPojoBuilder {
  // ...
  public MyPojoBuilder withArg1( String value) {
    // ...
  }
  public MyPojoBuilder withArg2( String value) {
    // ...
  }
  // ...
}

which makes no sense to me.
Probably I just didn't understand your point.

@drekbour
Copy link
Contributor Author

drekbour commented Apr 3, 2013

I'm talking about factory methods, changing from:

    @GeneratePojoBuilder
    @PropertyNames({ "firstname", "surname" })
    public static Contact createContact(String aFirstname, String aSurname) {
      Contact result = new Contact(aSurname, aFirstname);
      return result;
    }

to:

    @GeneratePojoBuilder
    public static Contact createContact(String firstname, String surname) {
      Contact result = new Contact(surname, firstname);
      return result;
    }

If the parameter names are already correct, why does the user need to list them out again (i.e. as per @ConstructorProperties, explicit name mappings are optional). PB should already have full view of these names as it operates on the source so Paranamer isn't required I think.

@mkarneim
Copy link
Owner

You are right.
The parameter names are accessible during compile time for the annotation processor. I didn't realize that.
So I think we should do this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants