I am working on source that has a lot of subclasses (call them A and B) implementing a common interface Visitor, with a method visitProgram. Is there any way to break when any of the subclasses hits this method (i.e. A.visitProgram or B.visitProgram)? Alternate language solutions would be fine, but I cannot rewrite the existing source.
I am working on source that has a lot of subclasses (call them A
Share
Since you’re debugging I assume you can add some new code and build the whole thing.
That said, you can use Aspect Oriented Programming (AOP) to get a pointcut that captures the execution of visitProgram, and in theory you can put your breakpoint in the pointcut. You can think of AOP as a technique to cut laterally through your program (as opposed to OOP which builds “vertical” structure).
In this instance, you want to perform something just before each time
visitProgram(of any instantiation of yourVisitorinterface) is run. This is a lateral cut, so AOP should fit your need.Basically, you’ll have a function in which you can set a breakpoint such that any time
visitProgramgets called your program will halt just before it executes.I’d recommend using Spring AOP, it’s pretty straight forward, just follow the manual for setup instructions. Your pointcut should look like this: