3

Is there an Eclipse plug-in, or some other tool or technique that would search an entire Java project (and/or the entire workspace) and reveal (in list/sortable format) the frequency-of-invocation of all public methods in the project? That is "what code is using what other code" the most?

I'm very familiar with the CTRL-SHIFT-G or CTRL-G usage; use it all the time. I'm also familiar with the Call Hierarchy view. The result that I'm looking for could be described like doing Search > References > Workspace (CTRL-SHIFT-G) on every method in every class in the workspace and tallying/counting the number of results each time, with final, sortable output like the example below.

The notion above is to get an idea of which classes/methods are getting most-used (not at run-time; in this question "used" != "executed"), in order to prioritize unit-testing on a very large project. I want to start using JUnit more (more than not-at-all, that is), and the idea of finding the most-used methods seemed like a good place to start.

For example, given three classes, ClassA, ClassB, and ClassC, I'd like a summary similar to this:

    Method                                       Number of calls
    ClassB.methodThatDoesSomethingMundane()                  134
    ClassC.methodThatDoesCoolStuff()                          78
    ClassC.methodThatDoesImportantThing()                     71
    ClassA.constructor()                                      63
    ClassB.aDifferentBoringMethod()                           37
    ClassA.getSomething()                                     19
    ... etc ... 
PattMauler
  • 400
  • 4
  • 22
  • 1
    Define *using*. Do you mean searching for that? Do you mean the code invokes a particular class / method most? What? – adarshr Feb 06 '12 at 15:44
  • I'd start with the most important, most brittle stuff. – Dave Newton Feb 06 '12 at 15:45
  • @PattMauler: *(not an answer hence the comment)*... I definitely remember "code coverage" tools doing exactly that. Now while the typical "code coverage" tool does only show if one "run" has been taking a path or not, I'm 99.9% percent confident I've seen code coverage tools also showing how often which methods were called. It's been a long time I haven't used code coverage tools that said... – TacticalCoder Feb 06 '12 at 16:34
  • Are there any code coverage or similarly-named tools that will do the method analysis without actually having to execute the code? The result that I'm looking for could be described like doing CTRL-SHIFT-G on every method in every class in the workspace and tallying/counting the number of results each time. – PattMauler Feb 07 '12 at 14:58
  • (I will edit the question to include this clarification) – PattMauler Feb 07 '12 at 15:06

2 Answers2

2

JArchitect, a commercial product, seems to have an interesting metrics module:

Method rank: MethodRank values are computed by applying the Google PageRank algorithm on the graph of methods' dependencies. A homothety of center 0.15 is applied to make it so that the average of MethodRank is 1.

Recommendations: Methods with high MethodRank should be more carefully tested because bugs in such methods will likely be more catastrophic.

I did not test it, but it worth a try.

But I don't think it will work if you use Java reflection.

Community
  • 1
  • 1
ndeverge
  • 21,378
  • 4
  • 56
  • 85
1

You could use a profiler (for example VisualVM, jvisualvm.exe in jdk/bin/ folder) for that.

bla
  • 11
  • 1