Ever written a
toString()
method to ease debugging? I bet you have, as that is the primary reason for writing a
toString()
method in the first place. Ever worked with an external API that didn't have well thought-out
toString()
implementations? I bet you have - all too often the output looks something like this:
Eclipse has a feature called detail formatters, which essentially override the default behavior of using
toString()
to get the formatted information for an object in the variables view. To set up a detail formatter, go to
Window->Preferences->Java[+]->Debug[+]->Detail Formatters
and add a new detail formatter. For a class like this:
publicclass WidgerFurmuzzit {
private String name;
public WidgerFurmuzzit(String name) {
this.name = name;
}
publicstaticvoid main(String[] args) {
Object o = new WidgerFurmuzzit("Test, 123");
System.out.println(o);
}
}
Here is a valid example detail formatter:
Notice that the detail formatter has visibility to private members inside the object, which is a clear advantage over traditional
System.out.println()
techniques outside the debugger. Here is the final result of having the detail formatter enabled:
Detail formatters can be enabled and disabled during the execution of a program, so if you suddenly find a new object that you want to know more about during debugging without having to sift through all of the variable trees, just put a new detail formatter in and keep going.
R.J., once again a great tip. I run into this problem far too much and it's quite annoying. We wouldn't even need this if people actually wrote proper toString() methods, but in the meantime, this looks great!
This particularly useful for tool-generated code, like CORBA stubs -- even if you have the sources, you can't reasonably edit'em manually to insert a decent toString(), because the changes will be lost in the next re-generation of those sources.
Eclipse: Debugging with Detail Formatters
At 4:50 PM on Dec 16, 2004, R.J. Lorimer wrote:
Fresh Jobs for Developers Post a job opportunity
toString()method to ease debugging? I bet you have, as that is the primary reason for writing atoString()method in the first place. Ever worked with an external API that didn't have well thought-outtoString()implementations? I bet you have - all too often the output looks something like this:Eclipse has a feature called detail formatters, which essentially override the default behavior of using
toString()to get the formatted information for an object in the variables view. To set up a detail formatter, go toWindow->Preferences->Java[+]->Debug[+]->Detail Formattersand add a new detail formatter. For a class like this:public class WidgerFurmuzzit { private String name; public WidgerFurmuzzit(String name) { this.name = name; } public static void main(String[] args) { Object o = new WidgerFurmuzzit("Test, 123"); System.out.println(o); } }Here is a valid example detail formatter:
Notice that the detail formatter has visibility to private members inside the object, which is a clear advantage over traditional
System.out.println()techniques outside the debugger. Here is the final result of having the detail formatter enabled:Detail formatters can be enabled and disabled during the execution of a program, so if you suddenly find a new object that you want to know more about during debugging without having to sift through all of the variable trees, just put a new detail formatter in and keep going.
6 replies so far (
Post your own)
Re: Eclipse: Debugging with Detail Formatters
R.J., once again a great tip. I run into this problem far too much and it's quite annoying. We wouldn't even need this if people actually wrote proper toString() methods, but in the meantime, this looks great!Re: Eclipse: Debugging with Detail Formatters
This particularly useful for tool-generated code, like CORBA stubs -- even if you have the sources, you can't reasonably edit'em manually to insert a decent toString(), because the changes will be lost in the next re-generation of those sources.Re: Eclipse: Debugging with Detail Formatters
For some reason cannot view the screen shots for the Debugging with Detail Formatters. I get the following error message:Forbidden
You don't have permission to access /images/postings/rj/detail_formatters/1.gif on this server.
It would be great if its possible to get to see those screen shots.
Cheers,
Varun.
I cannot see the pictures...
I have Firefox and am unable to see the embedded pictures. Are the available elsewhere?Re: I cannot see the pictures...
such problem )phentermine no prescription
acyclovir
acyclovir
+ phentermine cod
+ phentermine cod +.
+ phentermine no prescription
+ phentermine no prescription
+ phentermine no prescription
+ cyclobenzaprine +.
+ cyclobenzaprine +.
+ cyclobenzaprine +.
+ butalbital
phentermineonline
altace online
mp3 downloads
mp3 downlowds
Re: I cannot see the pictures...
Me too, please fix these pics.It's very useful for me.
Thanks.
Java Software