- 3 minutes to read
The Duplicate Code tool window lists all duplicate code clusters found in the current solution. You can view duplicate code blocks, open them in the code editor, or consolidate them directly from the tool window.
Duplicate Code Window Toolbar
The toolbar allows you to start a search for duplicates, check consolidation availability, adjust the window elements appearance etc. It includes the following items:
|Analyzes the current solution for duplicate code.|
|Checks all found clusters for consolidation availability. If consolidation is available, the cluster icon becomes green, otherwise the icon remains gray.|
|Loads duplicate code analysis data from an .xml file.|
|Saves duplicate code analysis data to an .xml file.|
|Groups files containing duplicate code by project within a cluster.|
|Groups clusters by file.|
|Shows/hides additional information on each cluster. Note that this option affects only grouped clusters. If clusters are shown without grouping, the tool window always shows the additional information on each cluster.|
|Shows duplicate code preview fields one under another.|
|Shows duplicate code preview fields one beside another.|
|Shows/hides the duplicate code analysis log.|
|Synchronizes vertical scrollbars of all shown duplicate code preview fields.|
|Opens the Duplicate Code options page.|
Duplicate Code Clusters
A duplicate code cluster is a set of code sections that have similar structure and probably can be consolidated to a single method.
The found clusters are listed at the left part of the Duplicate Code tool window.
The square to the left of a cluster indicates whether CodeRush Classic can consolidate the cluster or not.
Gray square color may also mean that the consolidation availability has not been checked for this cluster. Place the mouse pointer over the Consolidate item of the context menu to check the consolidation availability for a certain cluster, or press the toolbar button to check the consolidation availability for all clusters.
The cluster list also allows you to view all files containing the code related to a cluster,
or group clusters by files.
Use the and toolbar buttons to specify the way CodeRush Classic shows the clusters.
CodeRush Classic allows you to easily process duplicate code directly from the tool window using the Clusters context menu described below.
Clusters Context Menu
The context menu called for a duplicate code cluster includes the following items:
|Copy||Copies the selected cluster information to the clipboard as text.|
|Consolidate||Opens the submenu allowing you to consolidate the selected cluster to the specified position. Note that the submenu items may appear after several seconds, because CodeRush Classic should check the selected cluster for consolidation availability.|
|Expand All||Expands all nodes of the Clusters tree list|
|Collapse All||Collapses all nodes of the Clusters tree list.|
|Import||Loads duplicate code analysis data from an .xml file.|
|Export||Saves the results to an .xml file.|
|Clear||Clears the duplicate code analysis results.|
|Reset State||Resets the duplicate code analysis engine.|
|Options||Opens the Duplicate Code option page.|
Duplicate Code Preview
The code sections related to the selected Clusters tree list item are shown on the right side of the Duplicate Code tool window.
CodeRush Classic visually shows the connections between all corresponding identifiers in the found duplicate blocks. Each identifier has the same color as all corresponding identifiers in all code blocks.