Reputation: 15690
We have a set of classes that contain many "virtual fields" where the actual storage for each "field" is an array element with a non-obvious index, and the "field" is always accessed by getter/setter. When displaying an object of this kind, it would be nice to have "virtual fields" displayed that look like normal fields but use the getters/setters for access.
Detail formatters, AFAICT, don't really provide a way to do this.
If I could even just get read-only support (no setters) for this, it would help.
I'm hoping (probably vainly) for a solution whereby we could use some kind of config file or process or even maybe plugin to set this up for all of these classes.
Upvotes: 0
Views: 194
Reputation: 478
Logical Structures are what you need. So I have this class
public class Something {
public String[] fields;
public Something(final String[] fields) {
this.fields = fields;
}
public String first() {
return fields[0];
}
public String second() {
return fields[1];
}
}
Then you can go into Preference > Java > Debug > Logical structures and add your class and the fields with the corresponding getter methods like so
This will then result in the debug window looking like this
If it doesn't then make sure the Logical structure button is selected (the yellow arrow pointing to a tree structure)
Upvotes: 1
Reputation: 16392
The closest thing I can think of is to implement toString() such that the virtual fields' values are returned as part of the string in a readable format. This might not scale to lots of "virtual" fields, but it's a helpful debug technique (usually). When you select an object in the debugger its toString() result is displayed.
Upvotes: 0