How to Detect Code Duplication During Development

Is there a way to measure duplicate code?

Have a look Simian, you can use it for Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy source code and even plain text files.

Also, a similar question here.

Tools to detect duplicated code (Java)

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.

Find duplicated code in overridden method

Select the code in the visual studio editor. Right click-> Select Find matching clones in solution. Give it some time to process. It will tell you identical code in your solution.

Finding Duplicate Code by using Code Clone Detection . As noted in comments, this feature is available only in Ultimate and Premium versions of visual studio.

Resharper has something similar. Select the code, Right click-> Select Find similar code menu.

I need a tool to find duplicates or similar blocks of text in a singular text file or set of text files

A subset of your problem: Detecting duplicate code:

Try: PMD

Duplicate code can be hard to find, especially in a large project. But PMD's Copy/Paste Detector (CPD) can find it for you! CPD has been through three major incarnations:

  • First we wrote it using a variant of Michael Wise's Greedy String Tiling algorithm (our variant is described here)
  • Then it was completely rewritten by Brian Ewins using the Burrows-Wheeler transform
  • Finally, it was rewritten by Steve Hawkins to use the Karp-Rabin string matching algorithm.

...

Note that CPD works with Java, JSP, C, C++, Fortran and PHP code.



Related Topics



Leave a reply



Submit