Generates a builder according to the GoF pattern for Java domain objects.
Features
- Generates a builder with custom name patterns
- Can generate staged builder
- Capable of regenerating the builder
- Compatible with most version of Eclipse
- Highly configurable, check the plugin's preferences page
- Capable of generate builder methods for visible fields in superclass
- Encourages and supports null-safe programming practices
- Open source (with very permissible MIT license)
Usage
To invoke the generation have a Java file active and press either the icon on the toolbar (the hammer) or Ctrl+Shift+B.
You can click the small arrow next to the main icon to generate a different builder type (like staged builder), if you usually generate a certain kind of builder, set the default builder in the preferences page.
You can set the preferences under: Window->Preferences->Java->Spark Builder Generator
Example result:
public class Clazz { private Integer firstField; private Long secondField; @Generated("SparkTools") private Clazz(Builder builder) { this.firstField = builder.firstField; this.secondField = builder.secondField; } /** * Creates builder to build {@link Clazz}. * @return created builder */ @Generated("SparkTools") public static Builder builder() { return new Builder(); } /** * Builder to build {@link Clazz}. */ @Generated("SparkTools") public static class Builder { private Integer firstField; private Long secondField; private Builder() { } /** * Builder method for firstField parameter. * @return builder */ @Nonnull public Builder withFirstField(@Nonnull Integer firstField) { this.firstField = firstField; return this; } /** * Builder method for secondField parameter. * @return builder */ @Nonnull public Builder withSecondField(@Nonnull Long secondField) { this.secondField = secondField; return this; } /** * Builder method of the builder. * @return built class */ @Nonnull public Clazz build() { return new Clazz(this); } } }
Release notes
0.0.5 Added handling for code style prefix and suffix, see Github issue 5
0.0.6 Added staged builder support., see Github issue 4 Staged builder allows you to verify that all of the mandatory fields are set at compile time.
0.0.7 Option to add visible fields from superclasses to the builder, see Github issue 7
0.0.8 Fixed regression bug that was introduced in 0.0.7. While collection visible fields from superclasses, under some Eclipse configurations IllegalArgumentException occurred during java.lang.Object parsing.
0.0.9 Added option to generate builder to selected class (in case of nested classes, or multiple classes in a single file), see Github issue 10 Improvements to previous Builder class removing logic
0.0.10 Added the option to select which fields are generated in the builder, see Github issue 8
Fixed a small bug that deleted the previous builder when pressing the cancel button on the staging builder generator dialog Added MIT license file to plugin's site.xml, so it will show up on installation
0.0.11 Initialize Optional value to Optional.empty() to follow nullsafe programming practices
Initialize Collections with empty collections via java.util.Collections class
Various bugfixes related to overriding previous builder
Logging improvement
0.0.12 Generate @param tag to the builder's "with" methods, see Github issue 28
0.0.13 Add fields from superclass' constructor to the builder, see Github issue 30
0.0.14 Add the ability to create a builder based on an already existing instance, see Github issue 33
Dialog UX update
0.0.15 Add builder fields for private fields in superclass that have setters, see Github issue 35
0.0.16 Generate Jackson deserialize annotations to the builder, see Github issue 37
0.0.17 Generate default constructor, see Github issue 39
0.0.18 Fixed dialog issue when combined with DevStyle Darkest Dark plugin Github issue 41
Also made dialogs more responsive
Updated icon
0.0.19 Fixed ClassCastException when Java file includes an enum as the first type. Github issue 44
Made builder not generate @JsonPOJOBuilder annotation when the default builder names are not overridden
0.0.20 Fixed regression issue introduced on older Eclipse version due to 0.0.19. Github issue 46
0.0.21 Option to generate public constructor for regular builder that includes mandatory fields. Github issue 49
0.0.22 Fixing incorrect field naming with underscore prefix. Github issue 53
0.0.23 Add option to keep custom methods in the builderclass, when the builder is regenerated, Github issue 57
0.0.24 Add option to initialize builder fields with default value from the class' field assignment. Github issue 60
0.0.25 Fix default value initialization based on superclass' field assignment. Github issue 62
0.0.26 Fix copy constructor when superclass field is not accessible from builder. Github issue 64
0.0.27 Add option to use jakarta.annotation package instead of the old javax.annotation. Github issue 66
0.0.28 Add support for record types. Github issue 69
0.0.29 Avoid extra constructor for records. Github issue 71
0.0.30 Update eclipse update site to Github
Troubleshooting installation failure
Here are some common reasons installation fails, and steps to resolve
Connection timeout
This is a temporary problem, while accessing the update site. The server most of the times will be available again in a couple of minutes.
- You may try the FTP download site (see below)
For any other failure please contact me in the comments or Github.
Installing from backup
In case HTTPS update site is unavailable, you can install jar file from Mediafire backup:
Latest backup (entire update site: www.mediafire.com/folder/ya4g0y69b24vu/plugins)
Locate the jar file, you wish to install (probably the latest), and copy it to your Eclipse's dropin folder.
Additional information:
For feature request, bug reports please use the GitHub page: https://github.com/helospark/SparkBuilderGenerator
Categories: Tools
Tags: Builder Pattern, builder, code generator, SparkTools, design pattern, staged builder, gof, fluent, Builder Generator, buildergenerator, clean code, pattern
Additional Details
Eclipse Versions: 2024-09 (4.33), 2024-06 (4.32), 2024-03 (4.31), 2023-12 (4.30), 2023-09 (4.29), 2023-06 (4.28), 2023-03 (4.27), 2022-12 (4.26), 2022-09 (4.25), 2022-06 (4.24), 2022-03 (4.23), 2021-12 (4.22), 2021-09 (4.21), 2021-06 (4.20), 2021-03 (4.19), 2020-12 (4.18), 2020-09 (4.17), 2020-06 (4.16), 2020-03 (4.15), 2019-12 (4.14), 2019-09 (4.13), 2019-06 (4.12), 2019-03 (4.11), 2018-12 (4.10), 2018-09 (4.9), Photon (4.8), Oxygen (4.7), Neon (4.6), Mars (4.5), Luna (4.4), Kepler (4.3), Juno (4.2, 3.8), Previous to Juno (<=4.1), 2024-12 (4.34)
Platform Support: Windows, Mac, Linux/GTK
Development Status: Production/Stable
Date Created: Sunday, October 23, 2016 - 07:09
License: MIT
Date Updated: Monday, October 7, 2024 - 12:33
Submitted by: Helo Spark
Date | Ranking | Installs | Clickthroughs |
---|---|---|---|
December 2024 | 160/560 | 37 | 1 |
November 2024 | 153/658 | 168 | 7 |
October 2024 | 124/663 | 231 | 8 |
September 2024 | 144/642 | 180 | 10 |
August 2024 | 133/641 | 186 | 14 |
July 2024 | 165/663 | 128 | 15 |
June 2024 | 139/681 | 208 | 16 |
May 2024 | 140/682 | 229 | 13 |
April 2024 | 137/687 | 240 | 16 |
March 2024 | 141/694 | 252 | 7 |
February 2024 | 354/687 | 26 | 10 |
January 2024 | 192/691 | 125 | 26 |
Unsuccessful Installs
Unsuccessful Installs in the last 7 Days: 2
Count | Error Message |
---|---|
2 | Cannot continue the operation. There is another install operation in progress. |
Reviews Add new review
Amazing Tool,
Submitted by Pier Luigi Ambrosini on Wed, 05/09/2018 - 11:40
Amazing Tool,
is possible to add an option to also generate jaxonannotation on top of @Generated ?
something like this:
@JsonDeserialize(builder=TestBean.Builder.class)
public class TestBean implements Serializable{
private String app;
private TestInneer inner;
@Generated("SparkTools")
private TestBean(Builder builder) {
this.app = builder.app;
this.inner = builder.inner;
}
public String getApp() {
return app;
}
public void setApp(String app) {
this.app = app;
}
public TestInneer getInner() {
return inner;
}
public void setInner(TestInneer inner) {
this.inner = inner;
}
/**
* Creates builder to build {@link TestBean}.
* @return created builder
*/
@Generated("SparkTools")
@JsonCreator
public static Builder builder() {
return new Builder();
}
/**
* Builder to build {@link TestBean}.
*/
@Generated("SparkTools")
@JsonPOJOBuilder(buildMethodName = "build", withPrefix = "")
public static final class Builder {
private String app;
private TestInneer inner;
private Builder() {
}
public Builder app(String app) {
this.app = app;
return this;
}
public Builder inner(TestInneer inner) {
this.inner = inner;
return this;
}
public TestBean build() {
return new TestBean(this);
}
}
Tanks !
Re: Amazing Tool,
Submitted by Helo Spark on Mon, 05/14/2018 - 11:26
In reply to Amazing Tool, by Pier Luigi Ambrosini
Hi Pier,
I have created an issue on GitHub:
https://github.com/helospark/SparkBuilderGenerator/issues/37
I'll take a look at it, when I have some free time.
Re: Amazing Tool,
Submitted by Helo Spark on Fri, 05/18/2018 - 15:25
In reply to Amazing Tool, by Pier Luigi Ambrosini
Hey Pier,
Jackson annotation support is released with version 0.0.16.
Note, that it is not enabled by default, enable it in the preferences with option "Add Jackson deserialize (@jsondeserialize, @jsonpojobuilder) annotation" to generate for all builders or enable dialog for regular builder generation and you can select "Add Jackson deserialize annotation" to generate the annotations casebycase basis.
Please update and try if everything is working as expected
Re: Re: Amazing Tool,
Submitted by Pier Luigi Ambrosini on Tue, 05/29/2018 - 05:16
In reply to Re: Amazing Tool, by Helo Spark
Work like a charm !!
Tanks!
Inheritance
Submitted by Martina Riehm on Thu, 12/14/2017 - 04:32
Works nice, except for inheritance: fields of inherited classes are ignored, thus the created code does not compile.
Re: Inheritance
Submitted by Helo Spark on Thu, 12/14/2017 - 13:03
In reply to Inheritance by Martina Riehm
Hi Martina,
Thanks for the feedback, could you please create an issue in the GitHub repository including a simple example and the expected builder? If you do I'll look into fixing it.
Github repo: https://github.com/helospark/SparkBuilderGenerator/issues
Re: Re: Inheritance
Submitted by Martina Riehm on Mon, 12/18/2017 - 10:55
In reply to Re: Inheritance by Helo Spark
I created issue 30.
Connection reset
Submitted by Hajdu Attila on Fri, 05/05/2017 - 05:47
I can not download plugin because you have a network issue :)
Unable to connect the
Submitted by Benx Shen on Wed, 04/05/2017 - 21:12
Unable to connect the installation site
Re: Unable to connect the
Submitted by Helo Spark on Thu, 04/06/2017 - 12:12
In reply to Unable to connect the by Benx Shen
It's working for me.
Can you access? ftp://helospark.com/eclipse_plugin/SparkBuilderGeneratorPlugin/
Could have been a temporary network outage.