Not only is the JUtils ToString Generator plugin versatile and easy to use, it
can also be tweaked according to your needs.
For instance, if you don't want a space before and after the '=' sign while
generating
toString()
implementation, you can configure it so
by opening the JUtils ToString preference page. This can be found at
Window >> Preferences >> JUtils >> toString() in the Eclipse IDE.
Over there, under Method Body, you will find a template, similar to the sample shown
below. Here, ${attribute} represents a field in the Java Class.
- hide
public String toString()
{
final String TAB = " ";
String retValue = "";
retValue = "${class_name} ( "
+ super.toString() + TAB
+ "${attribute} = " + this.${attribute} + TAB
+ " )";
return retValue;
}
Now, all you have to do is change the following line
+ "${attribute} = " + this.${attribute} + TAB
// note the space padding around '=' sign
to this
+ "${attribute}=" + this.${attribute} + TAB
This way, you can perform numerous modifications. To enumerate some
more, you can change the TAB character to 8 spaces instead of the
default 4, separate the elements by a LF or CR character, comment out
certain parts of the implementation template. The possibilities are
infinite.
You can even change the JavaDoc according to your needs.
Lets say you want a
StringBuilder
implementation for your
toString()
. You can just select the mode in the ToString
preference page and click OK. Next time you generate
toString()
,
you will get a
StringBuilder
implementation. Please see the
Screenshots page.