Constants, Fluent Setters and Builder Generator - plugin detail
Adds three new code generators: constants, fluent setters and builder. Constants are useful when you access a class fields via reflection. Fluent setters are setters named like the field they set that return "this" so that they can be used one after the other in a way called "fluent interface". The builder adds an inner class named "Builder", a static method that creates the class and a private constructor to the bean.

Plugin owner: |
fillumina |
Website: |
https://github.com/fillumina/netbeans_builder_module |
Added: |
2014-06-14 |
License: |
CDDL |
Category: |
Code Generation |
Downloaded: |
3,160 times |
Rating: |
|
Plugin Log |
Show log
2014-07-02 16:55:15 | fillumina | Binary successfully saved 1404334514_com-fillumina-buildercreator.nbm, binary_id: 3047, version: 8.0 | 2014-07-02 16:55:14 | fillumina | Binary uploaded successfully - /space/pluginportal-v2/public/data/nbms/com-fillumina-buildercreator.nbm | 2014-07-02 16:55:14 | fillumina | Uploading new binary for version 8.0 | 2014-07-02 16:54:47 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-07-02 16:54:47 | fillumina | Plugin edit initiated | 2014-07-02 16:30:55 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-07-02 16:30:55 | fillumina | Plugin edit initiated | 2014-07-02 16:26:28 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-07-02 16:26:28 | fillumina | Plugin edit initiated | 2014-07-02 16:25:13 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-07-02 16:25:13 | fillumina | Plugin edit initiated | 2014-07-02 16:18:38 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-07-02 16:18:38 | fillumina | New full image added | 2014-07-02 16:18:38 | fillumina | New thumbnail image added | 2014-07-02 16:18:38 | fillumina | Plugin edit initiated | 2014-07-02 16:02:51 | fillumina | Binary successfully saved 1404331371_com-fillumina-buildercreator-2.nbm, binary_id: 3047, version: 8.0 | 2014-07-02 16:02:51 | fillumina | Binary uploaded successfully - /space/pluginportal-v2/public/data/nbms/com-fillumina-buildercreator-2.nbm | 2014-07-02 16:02:51 | fillumina | Uploading new binary for version 8.0 | 2014-06-21 12:18:03 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-06-21 12:18:03 | fillumina | New full image added | 2014-06-21 12:18:03 | fillumina | New thumbnail image added | 2014-06-21 12:18:03 | fillumina | Plugin edit initiated | 2014-06-17 05:05:27 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-06-17 05:05:27 | fillumina | New full image added | 2014-06-17 05:05:27 | fillumina | New thumbnail image added | 2014-06-17 05:05:27 | fillumina | Plugin edit initiated | 2014-06-16 11:02:02 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-06-16 11:02:01 | fillumina | Plugin edit initiated | 2014-06-16 10:52:59 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-06-16 10:52:59 | fillumina | New full image added | 2014-06-16 10:52:59 | fillumina | New thumbnail image added | 2014-06-16 10:52:59 | fillumina | Plugin edit initiated | 2014-06-16 10:38:06 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-06-16 10:38:06 | fillumina | Plugin edit initiated | 2014-06-16 10:25:57 | fillumina | Plugin edited, id:55184, pubid:55184 | 2014-06-16 10:25:57 | fillumina | New full image added | 2014-06-16 10:25:57 | fillumina | Plugin edit initiated | 2014-06-16 03:13:09 | jkovalsky | Plugin published | 2014-06-14 13:16:25 | fillumina | Plugin saved with .nbm/zip file; id: 55184 |
|
|
Versions available
|
Download size: 0.03 MB
|
Last Update: 2014-07-02
|
What's new in this version
Updated plugin info.
Verifications for NetBeans versions
Plugin is not subject to any verification
Introduction
Constants
Accessing fields via reflection is risky because string names cannot be
enforced to match the fields they refer to. To mitigate this problem an
automatic procedure can be used to auto-generate them.
The constants start with an underscore so to allow the automatic removal of
removed or changed fields. The underscore can also be useful to implicitly
specify that the constant refers to a field name.
public static final String _FIELD_NAME = "fieldName";
private int fieldName;
Fluent Setters
Fluent setters are field setters that return this and so can be appended one to another:
public NamedBean name(final String value) {
this.name = value;
return this;
}
The previous setter can be used like this:
NamedBean nb = new NamedBean().name("Some Name");
This methods allows for a better understanding of the class parameters and it's more usable than the telescopic constructors but it doesn't allow for immutable beans.
Builder
A builder is a separate class that allows to use a fluent interface to generate immutable beans.
This is an example of a builder as created by the plugin:
public class MyBean {
private static String pippo = "";
private final int a = 1;
private String name;
private final int age;
public static class Builder {
private String name;
private int age;
private Builder() {
}
public Builder name(final String value) {
this.name = value;
return this;
}
public Builder age(final int value) {
this.age = value;
return this;
}
public MyBean build() {
return new javaapplication1.MyBean(name, age);
}
}
public static MyBean.Builder builder() {
return new MyBean.Builder();
}
private MyBean(final String name, final int age) {
this.name = name;
this.age = age;
}
}
Note that the initialized final field is not considered in the builder. The generators can also be used while refactoring because they remove automatically the old artifacts and replace them with the new version.
|
[ You have to be logged in to be able to comment. ]
User Comments
Perfect!
I prefer this method. Randomly found this and its great! I'll be devastated if this were to stop working!
Posted by djc391 on Jun 17, 2014
|