Bug 444580 - [lib] @Builder annotation
Summary: [lib] @Builder annotation
Status: NEW
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-19 07:10 EDT by Chathuranga Ranaweera CLA
Modified: 2014-09-22 09:09 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chathuranga Ranaweera CLA 2014-09-19 07:10:23 EDT
If there is an easygoing path to implement builder pattern code would be more valuable.

Eg : 

Like a @Accessors annotation, in one case we add a @Accessors annotation by default a public getter and a public setter method is made

@Accessors String name

Will compile to java code : 

    private String name;
     
    public String getName() {
    return this.name;
    }     
    public void setName(final String name) {
    this.name = name;
    }


In the same manner, if we have an easy way to generate builder pattern code as mentioned below 

Eg : 

@Builder class Person { 
String name 
}

Will compile to java code : 

public class Person {
	private String name;

	public static class Builder {
		 private String name;

		public Builder withName(String name) {
			this.name = name;
			return this;
		}

		 public Person build() {
			return new Person(this);
		}
	}

	private Person(Builder builder) {
		this.name = builder.name;
	}
}
Comment 1 Stefan Oehme CLA 2014-09-22 07:03:26 EDT
We left this out of 2.7, because there are quite some different flavors of builders, especially how/when required/optional/default parameters are handled. We did not have enough use cases in our own code to make a decision.
Comment 2 Chathuranga Ranaweera CLA 2014-09-22 07:43:48 EDT
In a coming build, can we make a basic builder without much option as mentioned above example.
Comment 3 Stefan Oehme CLA 2014-09-22 07:48:22 EDT
I don't think we will do that right now, since it has not been requested much. 

Also, remember that active annotations are easy to write. So if you just need a very basic @Builder, you will be done by the end of the day =)