Tools to detect duplicated code (Java)

Rosdi Kasim picture Rosdi Kasim · Jun 21, 2010 · Viewed 28.9k times · Source

I am in a project where previous programmers have been copy-pasting codes all over the place. These codes are actually identical (or very similar) and they could have been refactored into one.

I have spent countless hours refactoring these codes manually but I think there must be a better way. Some are very trivial static methods that could have been moved into an ancestor class (but instead was copy pasted all over by previous junior programmers).

Is there a code analysis tool that can detect this and provide reports/recommendations? I prefer free/open source tool if possible.

Answer

uthark picture uthark · Jun 21, 2010

I use the following tools:

Both tools have code duplication detection support. But both of them lack the ability to advise you how to refactor your code.

JetBrains IntelliJ IDEA Ultimate has good static code analysis with code duplication support, but it is not free.