When debugging Java code, Eclipse has a feature that allows it to find all instances of a given type (via context menu in the Variables window). Is there any way to filter these programatically? For instance, I want all instances of class FieldInstruction where
the_instance.getType().getName().equals("somestring")
Evaluates to true.
As I am trying to debug code that is already supposed to be enumerating all the instances, just creating my own code the walk the tree structure where the classes exist kind of defeats the purpose. I’d really like to be able to do this filtering through the Display or Expressions windows.
I ended up creating a rather hacky “InstanceRegistry” class. In the constructor of each class type I want to track, I put
This even takes care of “registering” the instance under all super classes and interfaces.
To iterate over the instances (can even be done in the Eclipse Display window):
The source code of class InstanceRegistry: