I have some collections that I would like to analyze in the Eclipse debugger. I am interested in a particular attribute of each element.
Let's take an example with a list of Person
s (each one with an address
attribute which in turn has a city
attribute). In the debugger I can either look at each element or look at list.get(i).address.city
.
Doing this for large structures is not really helpful. Is there the possibility to apply a function to a data structure, something similar to the map
function in Perl (in the debugger not in the code).
The input would be my list with the path I am interested in (Person.address.city), the output a list with just the selected elements (a list of cities with my example).
In Perl:
map { $_->{address}->{city} } @list
Edit
I am able to generate a String
with a Detail Formatter:
StringBuilder sb = new StringBuilder();
for (Person p : this) {
sb.append(p.address.city());
sb.append(", ");
}
return sb.toString();
This will format my list with just the elements I am interested in (as a String
).
Although it goes in the right direction it would be nice if I could return a new List
that I can analyze with the debugger.
I think, the Eclipse Debugger feature you are interested is called logical structures. You could define a logical structure in Eclipse preferences (Java/Debug/Logical structures), where you could write such an expression (hopefully), and then on the variables view you could replace the display of the list in the pop-up menu.
See this blog post for basic ideas: http://www.javalobby.org/forums/thread.jspa?threadID=16736&messageID=91823528
The Display View provides you with the ability to execute custom code at each breakpoint. Just read out your data structure at the breakpoint and print it out to the console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With