Duplicate Detection using the Stand-alone Application
- 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:
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:
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
- 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.
- Clear – clears the duplicate code analysis results in the clusters tree list and all source code views.
- Options – opens the Options dialog, which allows you to specify the code analysis settings, such as an analysis level.
The tool bar contains all important tool buttons for the duplicate code detection analysis:
|Analyze Solution||Shows the Open File dialog allowing you to choose a solution file for analysis.|
|Import||Loads previously saved duplicate code analysis data.|
|Export||Saves the duplicate code analysis data for this solution.|
|Options||Shows the Options dialog with available duplicate code analysis settings.|
|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.|
|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.|
|Horizontal layout||Changes the code view layout, arranging duplicates horizontally.|
|Vertical layout||Changes the code view layout, arranging duplicates vertically.|
|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:
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:
There are two versions of this application for different .NET Framework versions: 2.0 and 4.0.
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?
- Duplicate Detection and Consolidation Overview
- Duplicate Real-time detection in Visual Studio
- Duplicate Detection Visual Studio tool window
- Duplicate Consolidation inside Visual Studio
- Duplicate Detection analysis options
- Duplicate Detection in CodeRush versus Code Clone Analysis in Visual Studio 2011