Reputation: 414
This is an odd problem:
I need to debug code which uses complex value objects and, often, collections of them. But I'm only interested in certain member of the objects at a time. Conceptually, let's say I need to watch every SmallToe on every Person on a Bus.
(Given a Bus<Person>
which is an instance of class Bus extends ArrayList
) I would like to write this in debug watches:
for(int i=0; i<bus.size(); i++) {
bus.get(i).getLeg().getSmallToe().getDesc();
}
But this, of course, doesn't parse ('Unexpected tokens'). Are loops in watches even legal (or in Intellij custom java class renderers) and can this be done somehow? Is there any other way you'd go about this?
Alternatives, such as a) writing get(x).getLeg().getSmallToe().getDesc();
many times (separate watches) and b) having to expand a tree full of members and sub-members, which is 10-screens-long, are not very exciting.
Thanks.
Upvotes: 1
Views: 241
Reputation: 2664
Code fragments are not yet possible in watches, however there's no problems with implementing them one day. I've filed IDEA-178815, please vote.
In your case you can try using streams to fit it into a watch expression, something like:
bus.stream().map(p -> p.getLeg().getSmallToe().getDesc()).toArray()
However this could be slow to evaluate on every step...
Code fragments are available in renderers expressions, but then you'll need to replace the whole class children with your new, something like this:
Upvotes: 3