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
Why Do I Need to Repeat Template Arguments of My Base Class in Member Initalizer List
Check Xmm Register for All Zeroes
Check Keypress in C++ on Linux
In C++, Can a Class with a Const Data Member Not Have a Copy Assignment Operator
Using an Union (Encapsulated in a Struct) to Bypass Conversions for Neon Data Types
Symbol Not Found When Using Template Defined in a Library
Why Cast to a Pointer Then Dereference
Strange Behavior with Constexpr Static Member Variable
C++ When Should We Prefer to Use a Two Chained Static_Cast Over Reinterpret_Cast
Throwing the Fattest People Off of an Overloaded Airplane
G++ Linker: Force Static Linking If Static Library Exists
Cannot Open Shared Object File: No Such File or Directory
Does Std::Bind Work with Move-Only Types in General, and Std::Unique_Ptr in Particular