i wish to find out where a specific method in a specific class is called from one of the classes visible to the classloader. that is, given a specific object instance analyse it, all methods it has and check if a specific method call exists in there anywhere. or alternatively if a specific class is created. is there any way to do this in a simple way? i would also like to be able to traverse from the given class a few levels further to referenced classes to check those as well.
using the reflection api i can get the list of methods, their annotations, etc. but not the methods called (or constructed). i tried looking at asm/bcel but the bytecode analysis is a bit too much for me. i pretty much gave up after building a visitor for the classes and their methods in asm and noting that i would probably need to check something like invokevirtual opcodes and their references to the constant pool and all sorts of morbid things like that.
basically what i am looking for is a way to mark specific spots in code and have another piece of code find those marked spots without having to execute everything. much like annotations but at the line of code level. any ideas?
You can't do this from within Java, and I don't know why you would want to do it at runtime anyway. Most IDEs will do it for you in the twinkling of an eye, well, a few eyes. If you must do it at runtime for some reason you would need a Java bytecode library, there are several around.