Hi,
I have a JDE code gen wizard suggestion: generate a toString() method. I see
and use this type of toString() regularly, and maintaining it with a larger
than small quantity of instance variables is a pain. And Eclipse does not have
this!
Here is the general idea:
First, insert a constant "STRINGBUFFER_SIZE", if it does not exist:
/**
* Initial size of the <code>StringBuffer</code> for
* <code>toString()</code>.
*/
private static final int STRINGBUFFER_SIZE = 2000;
Next, insert the toString() template, if it does not exist:
/**
* [EMAIL PROTECTED]
*/
public String toString()
{
StringBuffer sb = new StringBuffer(STRINGBUFFER_SIZE);
return sb.toString();
}
Lastly, take all the instance variables in order and generate one line for each
using this template:
sb.append(" name=").append(name);
For example, an instance variable named "firstName" would look like this:
sb.append(" firstName=").append(firstName);
Note that the first append should have no leading spaces and the subsequent
ones do, e.g.
sb.append("firstName=").append(firstName);
sb.append(" middleName=").append(middleName);
sb.append(" lastName=").append(lastName);
The update strategy probably needs to compare the value in the string (e.g. "
lastName=") with the instance variable name vs the append value to see if it
already exists, because after generation, the developer could change the append
() (e.g. from ".append(someType)" to ".append(someType.getCode()"). Of course,
the string could get changed too, but it seems the best approach. Not sure of
a better strategy.
I think the feature should reorder the appends to match the instance variable
order too.
Potential configuration items are:
- field separation string: instead of two spaces, maybe someone wants a comma
and a space or other
- the name of the created constant (STRINGBUFFER_SIZE)
- the STRINGBUFFER_SIZE variable value (naturally it is easy to change after
genning, and would be appropriate to do for the class
Does anyone like this idea? I'm sure there are improvement ideas too... :-)