views:

16

answers:

2

In eclipse you can set custom "Detail Formatters" under Preferences -> Java -> Debug -> Detail Formatters to print objects in custom ways when debugging. I'd like to use a utility class to print an object using a formatter like:

return com.foo.Bar.xzyToString(this);

where xzyToString is a static method of Bar returning a String, but eclipse complains that it

'could not resolve type: com.foo.Bar.xzyToString'. Adding 'Bar' to the project build path doesn't allow the class to be found. How/where do I update the path eclipse uses to resolve names in Detail Formatters?

A: 

Just give the part after your return statement. E.g. for StringBuffer try:

toString() + " (" + length() + ")"
DerMike
+1  A: 

The detail formatter hooks into the Eclipse JDI framework and uses the classloader of the class currently being debugged. So, you can only use classes that your running application knows about.

Since you only need your utility class while debugging, you can add the class to the classpath of your launch configuration (or add it directly to your project). Unfortunately, I don't know a way of doing this automatically for all launches.

Andrew Eisenberg