Version History
v2011 vol 2
DDC - Duplicate Code Detection and Consolidation
Duplicate code can be problematic in solutions because:
- A bug could exist in each of the duplicate code blocks, making it harder to fix and increasing the chances that one of the bugs escapes correction and resurfaces on your customer’s machines after the corresponding bug is fixed.
- Duplicate code is less flexible and harder to extend.
- More code takes more time to read and understand, making it harder to bring new devs up to speed.
CodeRush finds duplicate code quickly (either in a low-priority background thread while you work, or in a high-priority foreground thread while you wait), and also lets you consolidate many forms of code duplication automatically.
The
icon at the bottom-right of the text editor indicates your solution contains two or more blocks of duplicate code that can be consolidated into a single block.

Click this icon to open the Duplicate Code tool window to see all duplicates found in the entire solution.


You can also start a search from the Duplicate Code tool window. Just click the Refresh icon in the upper left to refresh the results. The progress bar at the
top of the window reports on search progress.
When the search is finished CodeRush immediately displays the results. The list on the left shows all duplicates found.
Click an entry in this list to see the corresponding duplicate code shown on the right side of the tool window.
The Duplicate Code tool window can be used to explore the connections between the duplicate code detected. In addition to synchronized scrolling through the duplicate blocks,
you can hover the mouse over the identifiers and see corresponding identifiers highlighted synchronously in adjacent code windows.
To navigate to a particular block of code (and consolidate starting with that block), just double-click the window showing the code block of interest.
Hover the mouse over the duplicate code issue bar appearing to the left of the source code. This will bring up the Duplicate Code Issue window:

From this window, you can navigate among duplicates using the left and right duplicate code navigation buttons. You can also bring up the Duplicate Code tool window using the
button in the middle. Code consolidation can also be invoked, if available, by clicking the desired consolidation location. Duplicate code can be consolidated into the current class,
an existing helper class, a new helper class, or a new ancestor class. The locations available depend upon the location of the duplicate code. For example, if all the duplicate code is
in a single class, it can be consolidated into a single method in the same class.


You can also call the Duplicate Code Issue window hovering the mouse over the duplicate code issue bar appearing to the right of the source code.

JavaScript Support Improvements
We have greatly improved the JavaScript reference finding engine. CodeRush searches for references in .js files...

in <script> sections within .html files...

and within tags...

The improved references search engine allows us to extend other feature availability to JavaScript. For example, you can now navigate through references using the
Tab to Next Reference feature, or view them in the References tool window...


and rename identifiers with the Rename refactoring.

The JavaScript language structure does not always permit complete certainly when determining whether two elements are in fact references to the same identifier, or if they just have the same name.
To give you full control in such scenarios, we have implemented the Confirm Changes window for renaming JavaScript elements. This window appears when the Rename refactoring
is about to be applied and enables you to ensure that only the desired references will be renamed. You can omit a reference that should not be renamed by clearing the check from the appropriate item.

The toolbar of the Confirm Changes window includes the following items:

The Confirm Changes window can be used to preview and manage the references being changed by any cascading refactoring in C# or Visual Basic code as well.
To show this window when applying refactorings in languages other than JavaScript, check the "Show Confirm Changes window when confirmable changes exist" checkbox on the
Editor|Code Modification|Confirm Changes options page.
We have implemented new code issues...

and the following refactoring and code providers specially for JavaScript:
JavaScript Refactoring
- Merge Duplicate Local Declaration
Merges multiple identical local variable declarations into a single declaration.

JavaScript code providers
- Replace "this" qualifier with Local Variable
Replaces the suspicious use of the "this" qualifier in the inner function with a new local variable declared (and assigned) in the outer scope.

- Use Identity Operator
Replaces the "==" operator with the "===" operator and the "!=" operator with the "!==" operator;

MVC Support Improvements
With this release CodeRush includes improved MVC support. We have added the Editor Templates navigation provider

and extended the Partial View navigation provider functionality. Now it is available in MVC3 projects as well.

The following refactorings are new:
- Extract Editor Template
Extracts the selected code to create a new editor template.

- Extract Partial View
Extracts the selected code from an MVC view to a new partial view.

Renaming actions
If you rename an MVC action, CodeRush automatically renames the corresponding file, as well as the action and all its references, including those passed as arguments to ActionLink method calls.


Note, that to completely undo the renaming, undo needs to be applied twice. Once to undo the file rename, and a second time to undo the renamed references.
Renaming controllers
The MVC technology imposes constraints on naming MVC controller. The controller name must end with "Controller" (e.g. "HomeController"). When you call the Rename refactoring for an MVC
controller, it changes only the part of its name that ends before "Controller" to keep your code valid. The controller references passed as an argument to ActionLink method calls are also renamed.


We have extended templates availability. Now you can expand local level templates in Razor blocks.

We have also included two Razor specific templates:
- se
Expands to a new Razor section.

- rs
Expands to a RenderSection method call.

The Use Raw Assembly Load option
For plug-in developers we have added a new option to prevent plug-in assemblies from being locked by Visual Studio during development. Access the Use raw assembly load option via the
Core|Startup option page.

The Use raw assembly load option greatly simplifies plug-in development, because you can still use CodeRush when developing a plug-in, and you can
build and test your plug-ins without restarting Visual Studio. Just click the DevExpress|Reload main menu item after the plug-in is rebuilt to load its latest version.
If the option is enabled, use the DXCorePaths.Instance.GetPlugInsPath method instead of the Assembly.Location property to obtain the plug-in location,
because the latter returns an empty string.
Unit Test Runner improvements
With this release we have applied the following improvements to Unit Test Runner:
-
The Unit Test Runner tool window supports grouping test by Project, Category and Namespace, it can also show all tests in a single flat list.

-
The test tree displays the information of the duration of each test's execution now. The duration value appears to the right of each test in the tree after its execution completes.
Sorting by test duration is also available.

-
We have added the Refresh Tests button to the toolbar of the Unit Test Runner tool window. Simply click it to refresh the tests tree.

-
You can quickly find out what code line caused the test failure, because Unit Test Runner highlights the error line now.

You can adjust highlighting options via the Unit Testing|Test Runner options page.

-
You can force Unit Test Runner to execute tests in x64 mode if the current CPU configuration is set to AnyCPU. This option is enabled only if the current operating system is x64.
If at least one project CPU configuration is set to x86, the option is ignored.

We have added the "On test item double click" option to the Unit Testing|Test Runner Window. It enables you to specify the desired behavior when tests are
double clicked in the test runner.

The following choices are available:
- Execute test - executes the selected test.
- Show test code in editor - opens the selected test in the code editor.
Support for VS2010 VSIX DXCore plug-ins
We have added the VSIX Standard Plug-in template, that enables you to save your DXCore plug-ins as VSIX package.


The advantages of VSIX DXCore plug-ins is that they can be installed and uninstalled via Visual Studio Extension Manager. In addition, you can add them to the Visual Studio Gallery.


Quick Nav loading speed improvements
Quick Nav identifier searching now occurs in a separate thread, allowing you to immediately enter the search pattern.


String.Formatter Window
Having trouble remembering format specifiers for strings, numbers, and DateTime types? CodeRush 11.2 makes all of this easy with the String.Formatter window, which enables
visual selection of formatting options for the values you pass to the String.Format call.


Format specifiers are built automatically based on the type of the expression passed in. To bring up this window, just place the caret on the format item portion of the string (e.g., "{0}", "{1}", etc.),
and press the CodeRush key (Ctrl+` be default).
New Code Cleanup rules
We have added the following code cleanup rules:
- Make variable implicit
- Remove redundant "base" qualifier
- Remove redundant "this" qualifier

Specify rules applied during code cleanup via the Editor|Code Cleanup|Rules options page.
New code providers
New refactorings
We have extended CodeRush functionality by new refactorings:
- Consolidate Conditional Blocks
Consolidates a conditional statement containing two for-loops inside each of its if and else blocks into a single for-loop containing the conditional, with
the previous contents of the for-loops now moved into the if and else blocks of the conditional.


- Reverse Boolean
Reverses the logical meaning of a Boolean variable and appropriately inverts all references and assignments to the variable to ensure program behavior remains unchanged.
This refactoring is useful when you want to reverse the semantic meaning of a Boolean variable (for example, changing "notFound" to "found"), and can clean up hard-to-read
expressions (e.g., "!notFound" can become simply "found" in C#). After this refactoring completes the Boolean variable is highlighted for an easy rename, so you can give the
variable a new name that is the semantic opposite of the old name.

Step one of the renaming "_DataNotFound" to "_DataFound" - reversing the Boolean.
We have also extended the Rename refatoring functionality. You can now use it to rename XAML namespace prefixes.

New code issues
We have added new code issues:
Class should implement IDisposable
Highlights classes containing IDisposable fields if the class does not implement IDisposable.
Duplicate code
Highlights duplicate code blocks found in the solution.
Format item index too large
Highlights format items with indices greater then or equal to the number of arguments passed to String.Format.
Fields should be disposed
Highlights undisposed IDisposable fields contained in a class implementing IDisposable.
We have also implemented several JavaScript specific code issues:
Assignment to global variable
Highlights the assignment to an implicitly declared global variable.
Duplicate local declaration
Highlights duplicate local declarations.
Duplicate property declaration
Highlights duplicate property declarations.
Hides declaration from the outer scope
Highlights the declaration that hides the outer scope declaration with the same name.
Redundant use of "this" qualifier in the global context
Highlights the redundant "this" qualifier used in the global context. The qualifier can be removed.
Suspicious equal-to operator usage
Highlights suspicious usages of the "==" operator.
Suspicious unequal-to operator usage
Highlights suspicious usages of the "!=" operator.
Suspicious use of "this" qualifier
Highlights the suspicious use of the "this" qualifier inside an inner function, which may yield unexpected results.
Possibly unassigned variable usage
Highlights variables called before they are assigned.
Statement is not terminated
Highlight statements without semicolon at the end.
New contexts
- Editor|Code|InFormatItem
Satisfied if the caret is inside a format item (e.g. "{0}").
- Editor|Code|InPrimitive
Satisfied if the caret is inside a primitive expression.
- Editor|Code|InRazorSectionDeclaration
Satisfied if the caret is inside a razor section.
- Editor|Line|Char Right Is Whitespace
Satisfied if the character to the right of the editor caret is whitespace (e.g. space, tab, or line break).
- Editor|XML|InAttributeValue
Satisfied if the caret is inside an attribute value.
- Editor|XML|InOpenTag
Satisfied if the caret is inside an opening tag.
- File|HasExtension
Satisfied if the current file has the extension passed to the context as a parameter.
- File|IsRazor
Satisfied if the current file is a razor view page.
- Language|Java Script
Satisfied if a JavaScript file is active in the code editor.
- Project|TargetFrameworkIs
Satisfied if the current project has the framework version passed to the context as a parameter (e.g. "4.0").
- System|Confirm Changes UI is Active
Satisfied if the Confirm Changes window is active.
- System|Refactoring is Available
Satisfied if the refactoring passed to the context as a parameter is available at the current caret position.