Home > Code Analysis > Duplicate Detection using the Stand-alone Application

Duplicate Detection using the Stand-alone Application

December 20th, 2011

CodeRush ships two standalone programs that do not require the Visual Studio IDE to be running for duplicate code detection analysis:

  • Duplicate Code Analysis windows app
  • Duplicate Code Analysis console app

Both applications can be used outside of the IDE to find duplicate code inside a specified solution. These applications are located inside the Plug-ins folder of your IDE Tools installation. You can find the windows application in the Start menu as well:

CodeRush Duplicate Code App In the Start Menu

DDC windows app

This windows app is similar to the DDC Visual Studio tool window. The window has the same user interface and allows you to review duplicated code discovered in your solution. To start the stand-alone duplicate detection application, from the Windows Start menu select Developer Express v2011 vol 2 | IDETools | DuplicateCodeApp. Once the application is running, you can scan a solution by selecting File | Analyze Solution or by clicking the corresponding toolbar item.

Once the solution is opened, you will see a progress bar indicating the analysis progress:

CodeRush Duplicate Detection Analysis Checking Progress

You can toggle the Output view in the window, to see more detail on the operations performed and how much time they take.

The application contains several elements:

  • Main Menu
  • Tool bar
  • Clusters list
  • Code views
  • Output

Main Menu

  • File
    • Analyze Solution – shows the Open File dialog so you can select a solution to analyze. Once a file is selected, analysis begins immediately.
    • Import – opens previously saved duplicate code analysis data for review.
    • Export – saves duplicate code analysis data for further investigation.
    • Exit – closes the application.
  • View
    • Clear – clears the duplicate code analysis results in the clusters tree list and all source code views.
  • Tools
    • Options – opens the Options dialog, which allows you to specify the code analysis settings, such as an analysis level.

Tool bar

The tool bar contains all important tool buttons for the duplicate code detection analysis:




 CodeRush DDC Icon Run Analysis Analyze Solution Shows the Open File dialog allowing you to choose a solution file for analysis.
 CodeRush DDC Icon Open Results Data Import Loads previously saved duplicate code analysis data.
 CodeRush DDC Icon Save Results Data Export Saves the duplicate code analysis data for this solution.
 CodeRush DDC Icon Settings Options Shows the Options dialog with available duplicate code analysis settings.
 CodeRush DDC Icon Group By Projects Show Projects Displays projects in the cluster tree list and groups clusters within each project. Clusters that span across more than one project will appear multiple times in this view.
 CodeRush DDC Icon Group By Files Show Files Displays files in the cluster tree list and groups clusters within each file. Clusters that span across more than one file will appear multiple times in this view.
 CodeRush DDC Icon Horizontal Layout Horizontal layout Changes the code view layout, arranging duplicates horizontally.
 CodeRush DDC Icon Vertical Layout Vertical layout Changes the code view layout, arranging duplicates vertically.
 CodeRush DDC Icon Toggle Log Toggle log Toggles the visibility of the output window where analysis log messages are sent.

Clusters and code views

On the left, you can see the list of duplicate code clusters. This is the cluster tree list. A cluster represents two or more blocks of source code that are duplicated within a solution.

A cluster in the list has an ordering number the redundancy value. A redundancy is a measure of the amount of code that would be removed if all duplicates were consolidated. All clusters in the list are sorted by the redundancy value in descending order. Near the redundancy value, you can see how many duplicate code blocks are in a cluster and the count of classes these blocks reside in.

Selecting a cluster will reveal the corresponding duplicate code on the right. Each code view has a caption that shows a class name, a file name and a project where a duplicate code block is located, and a view of the source code for each duplicated code block.

Code views can be arranged horizontally or vertically – toggle the appropriate button on the toolbar to change the layout. In the horizontal layout, code views can be collapsed by clicking the [-] button:

CodeRush Duplicate Detection Analysis collapsed items

and expanded by clicking the [+] button. Inside a code view, a rectangle shows the code block that is duplicated.


This part of the window contains messages logged about the current analysis progress and operations performed and the time each operation takes:

CodeRush Duplicate Detection Analysis output

There are two versions of this application for different .NET Framework versions: 2.0 and 4.0.

Console app

The console application is used within a command-line window and provides no visual UI. You can specify different behavior by passing arguments in a command-line window. Here is the syntax:

DuplicateCodeConsole.exe solutionPath outputFile

where “solutionPath” is a path to the solution for duplicate code detection analysis and “outputFile” is a path to the output file that will contain the resulting analysis data. This file can be opened in either the stand-alone Windows application or in the Duplicate Code tool window.

After valid paths are provided, the application parses the solution and searches for the duplicate code, reporting progress:

Parsing solution... Done in 55,2813345781978 sec. Searching for duplicate code... Generating characteristic vectors... Generated 9050 vectors in 0,0395699571568842 sec Removing empty clusters ... Done in 0,000371098271236394 sec Found 20 clusters Done in 0,785516491288943 sec

After the analysis is done, the resulting analysis data is saved to the file you specified in the command line in an XML format. You can open this analysis data in the Duplicate Code Windows application or in Duplicate Code tool window inside Visual Studio.

There are also two versions of this application for different .NET Framework versions: 2.0 and 4.0.

Want to learn more?

Products: CodeRush Pro
Versions: 11.2 and up
VS IDEs: any
Updated: Dec/20/2011
ID: C150

Similar Posts: