简体   繁体   中英

Method investigation in Eclipse - How to find out which classes call this particular method?

say I have Class1 that implements interface named Class1interface .

This interface is autowired via dependency injection and IoC into another class - name it Class2 . Class2 uses SOME of the methods provided by Class1interface .

Say we use Spring notation:

class Class2 {
   @Autowired 
   Class1interface;
   // methods calls of Class1interface and application logic
}

How can I find out which methods of Class1interface/Class1 are used in Class2 without scrolling through the screen? Or how can I check whether this particular Class1interface method is used in Class2?

I know dodgy explanation, but I tried my best.

Thank You,

ctrl + shift + G while the cursor is on a method will show references to that method. This won't get you a pretty report of class relationships, but you could look through the results of Class1.blah to see which methods in Class2 reference it.

If you mean at runtime, you'd have to use reflection to pull the list of methods.

Method[] list1 = Class1.class.getMethods();
Method[] list2 = Class2.class.getMethods();
//Your code to compare the lists here

If you mean dev environment, go with the answer by @digitaljoel

可能是将光标放在字段引用上时可以使用“ Ctrl + shift + U”,您应该能够看到该类中字段引用的用法。

  • If you click on the field, all references to it are highlighted automatically. You see them as small rectangles at the right side of the code; you can click them to get to the position where the field is used.
  • Search > Occurences in File > Identifier gives you a list of all access to the field.

This is not the exact solution, but might be of help:

Place the cursor over any field or method and press <Ctrl> + <Alt> + <H> , which will give you the call hierarchy. This still means that you have to check for each method in Class1 / Interface1

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