2

I have cloned several Java project from a few git repositories and I would like to know what methods from a specific are being used and how often.

When I search online all I can find are questions about either how often a method gets called at runtime, or how many reference there are to unique methods but not how many reference to the same methods.

EDIT Using the search function in Eclipse isn't a possibility either because while it shows me where a certain method is used I need to search for over 400 methods in quite a few interfaces.

Seeseemelk
  • 136
  • 5
  • Get all your projects in a single workspace and use Eclipse reference feature: https://www.codetrails.com/blog/shortcuts-searching-eclipse/ – Nikhil Chilwant Feb 17 '18 at 07:13
  • Also look at https://stackoverflow.com/questions/5268998/find-methods-calls-in-eclipse-project – Nikhil Chilwant Feb 17 '18 at 07:15
  • That doesn't quite seem to do what I'd like. They just show you a certain method and where it's used and by what, but not how often a method is called in e.g. a single file. Also, I need to it for a little over 400 methods so that would be a little tedious. – Seeseemelk Feb 17 '18 at 07:23
  • Shell scripting is your friend. A bash script, a list of method names, and grep seems like the most straight forward set of tools to start with. – AnOccasionalCashew Feb 17 '18 at 08:20
  • Of course, then you will most likely have [two problems](https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/). – AnOccasionalCashew Feb 17 '18 at 08:22

1 Answers1

1

One way to do this is by first compiling the project to class files and then using javap to parse those class files. You can then use tools such as grep and sed to parse the output of javap.

find . -iname *.class -exec javap -c -p {} \; | grep "Method <method name, for instance: java/lang> | sed 's:.*// ::' | sort | uniq -c | sort -h

You will now have a list of methods and how often they are used in the project.

Seeseemelk
  • 136
  • 5