Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse plugin to find out unused methods in a class/package

I am looking out for an eclipse plug-in that could be used to detect unused methods or classes across a project. Does any one know a efficient good to use plug-in of that kind?

like image 465
Abhishek Avatar asked Oct 09 '09 04:10

Abhishek


People also ask

Where are unused methods in eclipse?

UCDetector (Unnecessary Code Detector) is a eclipse PlugIn tool to find unnecessary (dead) public java code. For example public classes, methods or fields which have no references.

Which tool can be used to identify dead code?

Tools like Eclipse, Findbugs and PMD can detect useless (or “unnecessary”) code on the micro-level by analyzing the AST (abstract syntax tree) [PMD]. Statically unreachable code: Code that is not statically referenced is a superset of “dead code”.

How do you find the dead code?

The quickest way to find dead code is to use a good IDE. Delete unused code and unneeded files. In the case of an unnecessary class, Inline Class or Collapse Hierarchy can be applied if a subclass or superclass is used. To remove unneeded parameters, use Remove Parameter.


2 Answers

  • Findbugs (which has an eclipse plugin) can show you "dead code" (through the CalledMethods detector)
  • UCDetector also provide that kind of feature

alt text

Of course, any of those tools can NOT deterministically find unused code (see the Halting Problem). Any code could eventually be called, through various means like Reflection.
But those static analysis tools can help.
For additional hints, a good test coverage is still required (dynamic analysis).

like image 132
VonC Avatar answered Oct 12 '22 09:10

VonC


Something like EclEmma (http://www.eclemma.org/) might be what you're looking for. It shows code coverage for packages, classes, methods and individual lines.

Some lines will never get 100% coverage (e.g. Enums) but it will give you a good idea about what's being used.

like image 31
BobBrez Avatar answered Oct 12 '22 10:10

BobBrez