CodeRush

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 Duplicates Found icon - CodeRush by DevExpress 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.

Duplicates Found hint - CodeRush by DevExpress

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

Duplicate Code window - CodeRush by DevExpress

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:

Duplicate Code Issue window - CodeRush by DevExpress

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 Duplicates Found sign - CodeRush by DevExpress 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.

Duplicate Code consolidation - CodeRush by DevExpress

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.

Duplicate Code Issue window - CodeRush by DevExpress

JavaScript Support Improvements

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

Renamed reference in a .js file - CodeRush by DevExpress

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

Renamed reference in a <script> tag - CodeRush by DevExpress

and within tags...

Renamed reference within a tag - CodeRush by DevExpress

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...

References window - CodeRush by DevExpress

and rename identifiers with the Rename refactoring.

Renaming JavaScript identifiers - CodeRush by DevExpress

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.

Confirm Changes window - CodeRush by DevExpress

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

Confirm Changes window toolbar - CodeRush by DevExpress

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...

JavaScript code issues - CodeRush by DevExpress

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.

    Merge Duplicate Local Declaration refactoring - CodeRush by DevExpress

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.

    Replace this Qualifier With Local Variable code provider - CodeRush by DevExpress

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

    Use Identity Operator code provider - CodeRush by DevExpress

MVC Support Improvements

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

Editor Templates navigation provider - CodeRush by DevExpress

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

Partial View navigation provider - CodeRush by DevExpress

The following refactorings are new:

  • Extract Editor Template
    Extracts the selected code to create a new editor template.

    Extract Editor Template refactoring - CodeRush by DevExpress

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

    Extract Partial View refactoring - CodeRush by DevExpress

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.

Renaming MVC action - CodeRush by DevExpress

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.

Renaming MVC controller - CodeRush by DevExpress

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

Using templates in Razor blocks - CodeRush by DevExpress

We have also included two Razor specific templates:

  • se
    Expands to a new Razor section.

    Section razor template - CodeRush by DevExpress

  • rs
    Expands to a RenderSection method call.

    Render Section razor template - CodeRush by DevExpress

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.

CodeRush Startup options - CodeRush by DevExpress

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.

    Grouping tests in Unit Test Runner window - CodeRush by DevExpress

  • 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.

    Test Duration information - CodeRush by DevExpress

  • 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.

    Refresh Tests button - CodeRush by DevExpress

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

    Highlighting the code line caused test failure - CodeRush by DevExpress

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

    Options for error line highlighting - CodeRush by DevExpress

  • 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.

    Unit Test Runner options - CodeRush by DevExpress

  • 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.

    Unit Test Runner window options - CodeRush by DevExpress

    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.

VSIX DXCore Plug-in template - CodeRush by DevExpress

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.

DXCore plug-in in Visual Studio Extension Manager - CodeRush by DevExpress

Quick Nav loading speed improvements

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

Quick Nav window update in CodeRush 11.1 and 11.2 - CodeRush by DevExpress

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.

String.Formatter window - CodeRush by DevExpress

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

New Code Cleanup rules - CodeRush by DevExpress

Specify rules applied during code cleanup via the Editor|Code Cleanup|Rules options page.

New code providers

  • Introduce Using Statement

    We have converted the Introduce Using Statement refactoring to a code provider. The new code provider has the same functionality as the corresponding refactoring had. It creates a new Using statement for an IDisposable variable, and removes a Dispose() call.

    Introduce Using Statement code provider - CodeRush by DevExpress

  • Format Item

    Calls the String Formatter dialog for the String.Format format item under caret.

    Format Item code provider - CodeRush by DevExpress
  • Implement IDisposable

    Implements the IDisposable interface in the current class.

    Implement IDisposable code provider - CodeRush by DevExpress
  • Dispose Fields

    Disposes IDisposable fields contained in the current IDisposable class.

    Dispose Fields code provider - CodeRush by DevExpress
  • Consolidate duplicate code to

    Extracts code from multiple locations into a single method, removing duplicate code from the solution.

    Consolidate Duplicate Code To code provider - CodeRush by DevExpress

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.

    Consolidate Conditional Blocks refactoring - CodeRush by DevExpress

  • 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.

    Reverse Boolean refactoring - CodeRush by DevExpress

    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.

Rename XAML namespace prefix - CodeRush by DevExpress

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.

1
2
3
4
5
6
7
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.