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

Implementing Consumer<Builder> fluent setters on model builders. #278

Merged
merged 1 commit into from
Nov 13, 2017

Conversation

kiiadi
Copy link
Contributor

@kiiadi kiiadi commented Nov 9, 2017

Description

Allows providing a Consumer<Builder> to complex fluent models setters to avoid having to create the appropriate builder yourself. As an example SES send message goes from:

client.sendEmail(SendEmailRequest.builder()
                                 .destination(Destination.builder()
                                                         .toAddresses("[email protected]")
                                                         .build())
                                 .message(Message.builder().body(Body.builder()
                                                                     .text(Content.builder().data("Crud").charset("UTF-8").build())
                                                                     .build())
                                                 .subject(Content.builder().data("Hello").build())
                                                 .build())
                                 .build());

to a:

client.sendEmail(SendEmailRequest.builder()
                                 .destination(d -> d.toAddresses("[email protected]"))
                                 .message(m -> m.body(b -> b.text(t -> t.data("Crud").charset("UTF-8")))
                                                .subject(s -> s.data("Hello")))
                                 .build());

Motivation and Context

Allows customers who dislike the verbose ComplexObject.builder().property("..").build() pattern to create object hierarchies with a shorter syntax.

Testing

New poet tests added.

return new StringBuilder()
.append(StringUtils.isNotBlank(documentation) ? documentation : DEFAULT_SETTER.replace("%s", name) + "\n")
.append(LF)
.append("This is a convenience which creates an instance of the {@link ")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just use string appending instead of the builder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could do - but this is how the other doc builders work...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@kiiadi kiiadi force-pushed the kiiadi/consumer-builders-on-models branch from 88e365b to 0ef37a2 Compare November 9, 2017 23:45
@kiiadi kiiadi mentioned this pull request Nov 9, 2017
@@ -385,6 +385,30 @@ public String getFluentSetterDocumentation() {
return docBuilder.toString();
}

public String getDefaultConsumerFluentSetterDocumentation() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we define this in Poet or here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like all the other documentation definitions are here...

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with this way, but I kinda like what Varun did in his pagination PR having a PaginationDocs.java file with the docs related to pagination

@kiiadi kiiadi force-pushed the kiiadi/consumer-builders-on-models branch from 0ef37a2 to 0725586 Compare November 10, 2017 01:38
Copy link
Contributor

@spfink spfink left a comment

Choose a reason for hiding this comment

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

Just the one minor comment on docs as far as the code goes.

If we have examples for this style, definitely need to figure out some formatting pattern for nested objects.

@@ -1064,6 +1065,21 @@ public String toString() {
Builder structWithNestedTimestampMember(StructWithTimestamp structWithNestedTimestampMember);

/**
* Sets the value of the StructWithNestedTimestampMember property for this object.
*
* This is a convenience which creates an instance of the {@link StructWithTimestamp.Builder} avoiding the need
Copy link
Contributor

Choose a reason for hiding this comment

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

Include something on how we will call build automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.append(getEnumDoc());
return docBuilder.toString();
return getSetterDocumentation()
+ LF
Copy link
Contributor

Choose a reason for hiding this comment

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

what does LF abbr stand for (saw the member declaration)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

line-feed

@kiiadi kiiadi force-pushed the kiiadi/consumer-builders-on-models branch from 0725586 to f7f0a91 Compare November 13, 2017 20:06
@kiiadi kiiadi force-pushed the kiiadi/consumer-builders-on-models branch from 73351c3 to 710b3af Compare November 13, 2017 22:42
@kiiadi kiiadi merged commit c56d647 into master Nov 13, 2017
@zoewangg zoewangg deleted the kiiadi/consumer-builders-on-models branch December 6, 2017 19:16
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.

4 participants