简体   繁体   中英

How to get all possible callers of a method in Java - like call hierarchy

Say I have a method m in a class. I'm trying to find all the methods that call m in the whole project. Similar to eclipse's call hierarchy tool, except I need it to output a list/array of Methods. I need it statically so I dont think a stack trace works. Is there any way to implement this, maybe using reflection?

I attached link to an example of Eclipse's call hierarchy tool, finding all the methods that mention the method barking() from the class Dog. (Dog.hungry() and Cat.scratching() call barking()).

图片

The "standard" java reflection will probably not be of any help on this.

I would try using the open source Reflection library.

You can search for a method with via:

Set<Member> usages = reflections.getMethodUsages(Method.class)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM