Random musings from my awakening dementia...
05.17.2005  
Eclipse Detail Formatter
 

I've been a computer geek since a boy, and thoughts related to computers and software engineering get dropped here for the benefit of humanity and my own hubris.

© 2005, Howard Abrams



Except where otherwise noted, all original content is licensed under a Creative Commons License.
See details.

While debugging some code that traversed a DOM tree in my Java code, I noticed that the variable output wasn’t very helpful. It defaults to calling the variable object’s toString() method, which as we all know, is not always overridden in helpful ways.

To overcome this deficiency, Eclipse has a feature called “Detail Formatter” where for each class that you are debugging, you can specify how it should display. And since it executes that code snippet as if it was part of the class definition, you don’t have to worry about public vs. protected vs. private declarations.

Illustration of Eclipse's Detail Formatter output According to this nice overview, it is simple to enter the private variable or method that should be called in order to display when a variable of that particular class is displayed.

However, when traversing a DOM, I wanted a bit more information about each element I was visiting. Sure I could put either getNodeName() or getNodeValue(), but I wanted both.

You can. You simply put something like this in the dialog box:

return getNodeName() + " - " + getNodeValue();

The results are displayed as in the cut out picture on the right. Fab.