开发者

Tools to detect duplicated code (Java) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 8 years ago.

Improve this question

I am in a project where pre开发者_运维百科vious 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.


I use the following tools:

  • PMD/CPD (BSD-style License).
  • Checkstyle (LGPL License) - support was removed, see details.

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.


Most of the tools listed on the Wikipedia article on Duplicate Code Tools will detect duplicates in many different languages, including Java.


SonarQube can detect duplicated codes but does not give recommendation on eliminating them. It is free and - although with the default setup it can only detect lexically identical clones


Either Simian or PMD's CPD. The former supports a wider set of languages but is non free for commercial projects.


http://checkstyle.sourceforge.net/ has support for finding duplicates


See our SD Java CloneDR, a tool for detecting exact and near-miss duplicate code in large Java systems.

The CloneDR will find code clones in spite of whitespace changes, line breaks, comment insertions deletions, modification of constants or identifiers, and in a number of cases, even replacement of one statement by another or a block of statements.

It shows where each set of clones is found, each individual clone, an abstraction of the clones having their shared commonality and parameterization of the abstraction to show how each clone instance can be derived from the abstraction.

It finds 10-20% clones in most Java systems.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜