GenerateToString is a action plugin for IDEA that is used to create or update java classes toString() method. The reason is valuebeans usually needs to dump their fieldvalues for debug purpose, and it's tedious to write the dump code for this. So this action plugin generates the code to dump all the fields in a simple manner.
In the code below we need to override the public toString method so the fields can be dumped:
After invoking the GenerateToString action the bean is now added with the following method
And if you change the fields you can run the action again and have it update the toString() method. In this situation where the toString() method already exists a dialog is displayed with choises to do:
- Update existing method
- Create a new toString() method, so you'll have duplicate methods
The plugin uses Velocity Template Language to generate the code, so it's very flexible if you want your toString to be a little different. The template can be changed from the settings at Options -> IDEA Settings -> GenerateToString.
You can find the plugin at the IntelliJ community site at: