toString() generator: format templates

Format templates are used by a simple mechanism that allows you to change format of generated method's output string: beginning, ending, separator, and so on. They look similar to JDT code templates but they don't actually affect the generated code directly (Code styles are used for that). There's a list of tokens that can be used in a template:

${object.className}inserts the class name as a simple String
${object.getClassName}inserts a call to this.getClass.getName()
${object.superToString}inserts a call to super.toString()
${object.hashCode}inserts a call to this.hashCode()
${object.identityHashCode}inserts a call to System.identityHashCode(this)
${member.name}inserts a member's name
${member.name()}inserts a member's name followed by parenthesis in case of methods
${member.value}inserts a member's value
${otherMembers}this token must stand between the separator and the ending string

For the template to work properly, the ${otherMemebers} token must be used exactly once in a template and cannot be followed by any member related token. Object realted tokens can be placed anywhere in the template, although if one is placed in a member related fragment (between the first member related token and the ${otherMemebers} token), it will be repeated for every member, which is probably not a sensible solution.

Template examples

The default template is a good example:

${class.name} [${member.name()}=${member.value}, ${otherMembers}]
The output string for this template looks like this:
FooClass[aFloat=1.0, aString=hello, anInt=10, anObject=null, aCharMethod()=a]

Here's a more sophisticated example:

${object.getClassName} (hashcode:${object.hashCode)
	members: ${member.name} = ${member.value}; ${otherMembers}
[super: ${object.superToString}]
It would result in an output similar to this:
FooClass (hashCode:232198409832)
	members: aFloat = 1.0; aString = hello; anInt = 10; anObject = null; aCharMethod = a
[super: SuperFooClass[aField=null]]

Related reference

Generate toString() dialog
toString() generator: code styles
toString() generator: listing content