Inline Parameter Refactoring in ReSharper 8

June 14th, 2013 by Dmitri Nesteruk

Recent ReSharper 8 EAP builds introduce a new refactoring for C# (VB.NET support is currently in the works) whereby we can refactor a parameter passed to a method to be replaced with actual value being passed in.

Before applying Inline Parameter refactoring

Invoking Inline Parameter refactoring on the argument 400 in the above screenshot causes the value parameter in the AddTen method to be removed, with all instances of its use replaced by the literal 400:

After applying Inline Parameter refactoring

The above is easy because the exact value to substitute is known. But that same refactoring can be invoked from the method parameter:

ReSharper 8 Inline Method Parameter

In this situation, the refactoring locates all the instances where the parameter is given a value. All you have to do is pick the instance that you want to use, and the parameter will be correspondingly inlined:

ReSharper 8 Inline Parameter Choose Usage Dialog

If the first usage from the above is chosen, the following changes will occur:

  • The original Solve method loses the last parameter, all its uses updated by the constant 16:

  • All methods that previously used this parameter no longer use it:
    ReSharper 8 inline parameter result

Finally, there are situations where a parameter that you wish to be inlined depends on local variables or other calculations the cannot be extracted. For example:

ReSharper 8 Inline Parameter Lambda Sample

Invoking Inline Parameter on the action parameter presents a dialog warning that while this is inlined, an additional parameter will be created:

ReSharper 8 Inline Parameter Choose Usage Replacement

Then, there is another dialog, which asks you if you want to include the new argument (in this case, work) in the method:

ReSharper 8 Inline Refactoring Inline Parameter Options Dialog

And, finally, the magic happens and the whole lambda gets transplanted into DoSomething(), with the usage updated appropriately:

ReSharper 8 Inline Parameter with Lambda End Result

This feature is already in the latest EAP, so if you want to see it today, you know what to do. Enjoy!

Architecture Tools in ReSharper 8

June 13th, 2013 by Dmitri Nesteruk

Like many people with very large Visual Studio projects, we in the ReSharper team wanted to get an overview of the 300+ project dependencies for ReSharper itself. Unfortunately, VS Ultimate gave us a representation that was rather difficult to interpret:

ReSharper 8 solution in VS Ultimate Architecture View

What we ended up doing is building our own tool for viewing project dependencies as well as comparing architectural snapshots as the solution continues to change and evolve.

Here’s how it works. First of all, with your solution open, go to ReSharper|Architecture|Build Architecture Graph:

Architecture Explorer Menu Item

ReSharper then goes through your solution and, without compiling anything, presents a dependency diagram of all the projects in the solution:

ReSharper Project Dependency Diagram

The great thing about the way R# does it is the fact that layout is calculated automatically to present an optimal illustration of dependencies between elements. ReSharper builds the dependency graph, and if the Show Code Metrics option is on (it is on by default) then reference analysis happens asynchronously — ReSharper analyzes the whole solution and indicates the strength of coupling between projects. This all happens on the background thread, so you can continue editing code, navigating etc. while ReSharper does its work.

There are two arrows linking the projects: black arrows show project references wheras grey arrows show unused references that can be safely removed without breaking the build.

The architecture diagram gets rendered for the scope you’ve selected in Solution Explorer: if you select just a folder with several projects, only those projects will be included. However, there is always a way to fine-tune which projects are represented by checking the appropriate boxes:

Architecture explorer view check boxes

Ticking each of the boxes shows or hides the appropriate elements on the diagram. This allows us to instantly update the representation of connections between different subsystems as soon as they are checked or unchecked in the list on the left.

The toolbar shown above has several options for how information is presented on the graph. First of all, there are several ways of grouping information:

Architecture view grouping options

The above options are None (meaning no grouping is done), Solution folders for grouping by solution folder, and File structure for groupings based on actual directory structure and the projects’ position therein.

The following toolbar buttons are also available:

  • Collapse Graph and Expand Graph buttons let you collapse or expand an area where a grouping is used. A collapsed group looks simply like this:
    Architecture view collapsed group
    As an alternative, one can simply double-click the + or - button on the group to expand or collapse it.

  • The Show/Hide Code Metrics button lets you show and hide metrics associated with the code. These metrics show used and unused references (black and grey arrows respectively) and also show the number of references from one project to another:
    Architecture view with metrics

    You can also select the indicator, right-click it and use Show Usages… to find out where these referencing calls actually occur.

  • Show Transitive References shows not only direct references but actually all transit references, so in addition to showing A → B → C, it will also show A → C on the diagram. This can lead to a very rich, circuit-like representation:
    Architecture view with transitive references

  • Save Architecture Graph lets you save the graph to a file.

  • Show Diff shows you a difference between two architecture graphs. In fact, you can also invoke this function (even without having a solution open) from the top-level menu:
    Open saved graph and diff menu

The ability to save architecture graphs to a file allows the user to look at the difference between the architectural layout of the solution as it continues to evolve. The following illustrates the changes that have been made to a solution:

Architecure tools diff illustration

The above is an illustration of the evolution in one of ReSharper’s subsystems. Red boxes indicate parts that have been removed, whereas dark green ones indicate new parts that have been added. The same color scheme is also applied to references.

Lastly, keep in mind that project-level menus which can be invoked in Solution Explorer can be invoked on Architecture View nodes in the same manner:

As always, we hope that you find this feature useful — it is already in the latest EAP, so if you want to see it today, you know what to do. Keep in mind that this is a very fresh tool that we’ve built, and one that we’ll be sure to augment with additional architecture-related features in future releases.

.NET Tools Team at NDC Oslo: 2 Workshops, 2 Talks and Booth

June 10th, 2013 by rdemmer

June 10 - 14, Hadi Hariri, Maarten Balliauw and Matt Ellis will be participating in NDC Oslo 2013; Norway’s largest conference dedicated to .NET and Agile development.

The guys will be leading a total of four workshops and talks in addition to staffing our booth. We invite you to come by and learn what’s new in the latest EAPs of ReSharper 8, dotTrace 5.5 and dotCover 2.5 and share your thoughts on these planned releases and other JetBrains tools.

JetBrains Technical Evangelists

Mark your calendar and join us for the following workshops and talks:

Continuous Integration and Delivery Workshop - Hadi Hariri and Paul Stack - June 10th

In this workshop we’re going to deal with the implementation details. We’ll see how to set up projects, distinguish types of tests, deal with triggering and branching, configure dependencies to improve maintainability, work with outputs, deal with failures, as well as manage and run deployment pipelines. This will be a workshop about putting the concepts into practice and seeing where things work, where they don’t. Learn more.

ReSharper Workshop - Hadi Hariri - June 11th

In this full day workshop, we’re going to refresh your knowledge about mainstream ReSharper functionality, and learn about many of the overlooked features of ReSharper. Beyond the simple navigation, we’ll learn how to effectively navigate legacy codebases using advanced navigation features, inspections, usage search, and value⁄call tracking. We’ll learn about using some of the less known yet very useful automatic refactorings that ReSharper offers. Learn more.

Brewing Beer with Windows Azure - Maarten Balliauw - June 12th, 16:20 - 17:20

Inspired by one of the Windows Azure gods (Wade Wegner), Maarten decided to order a homebrewing starter kit. Being a total cloud fanboy, he decided to hook those delicious creations to the cloud. Join Maarten and discover how you can connect a USB temperature sensor to Windows Azure to monitor brewing and fermentation temperatures. He’ll show you how to do distributed, social brewing in this fun yet practical session on an interesting use case for the cloud: beer.

Being an Anti-Social Geek is Harmful - Hadi Hariri - June 13th, 13:40 - 14:40

My 20+ years experience in software development has shown me one thing if not anything else: lack of good communication can kill a team, can kill a product and can kill a company. Having dealt with hundreds of developers, managed many teams and started my own company, I have seen how team moral can be killed when communication is hindered. I have seen how products can fail when customers are ignored. Developers need to learn how to be social. Learn more.

We look forward to meeting you in Oslo!

 

dotTrace 5.5 EAP: Introducing Subsystems

June 4th, 2013 by Daria.Dovzhikova

This happens to be a hot week for JetBrains .NET tools, as today we are opening the Early Access Progam for dotTrace 5.5 Performance. Please feel free to grab the latest build of our performance profiler. And here are the reasons why you should give it a try:

Subsystems

With version 5.5 we’re offering a new way to analyze snapshots in terms of Subsystems. Discover your code bottlenecks faster without digging deep into callstacks. With Subsystems view you get a quick overview of where a possible bottleneck may originate from:
dotTrace 5.5 Performance Subsystems
Note that you can customize this view to fit your needs by creating your own profiles and restyling the color scheme the way you like it. dotTrace 5.5 Performance comes with a built-in Default profile which gives you an example of how you can benefit from using Subsystems:

dotTrace 5.5 Performance Managing Subsystems options
Go to View | Options to see how it works and set up your own profile.

Bookmarks

We’ve also enabled you to add bookmarks to your snapshots so you could easily find and navigate between interesting pieces of a snapshot. Click Ctrl+K to create a bookmark, then you can use Ctrl+W shortcut to see and edit the full list of bookmarks from the current snapshot.

dotTrace 5.5 Performance Bookmarks editor

Other impovements

  • List of application’s Hot Spots is now shown right upon opening a snapshot in the updated Overview tab.
  • New Hot Spots algorithm accounting for system code.
  • dotTrace snapshot files (*.dtp) now occupy twice less disk space.
  • Integration with ReSharper 8 EAP.
  • Improved stability in incorrect metadata write/read.

Please note that current version of the EAP build doesn’t support working with snapshots created by previous versions of dotTrace, but this should be fixed by RTM.

You can start playing with dotTrace 5.5 Performance by downloading the latest nightly build from the Early Access Program Page today!

Please don’t foreget to let us know about any issues you might be facing via dotTrace issue tracker.

ReSharper Personal and Academic Licensing Changes

June 3rd, 2013 by Jura Gorohovsky

Last year, we asked for your input in order to decide whether to make a transition to upgrade subscription-based licensing for ReSharper. Upon reading through your feedback and undertaking internal research, we introduced a commercial license including 1-year upgrade subscription.

Further on we thought that it would be appropriate to do something similar for personal and academic licenses. What we did was just drop the traditional, per-major-version personal and academic licenses and replace them with licenses empowered with 1-year subscription. This is exactly how most of our products (such as PhpStorm, RubyMine, AppCode or WebStorm) are licensed: when buying a license, you can upgrade to any major and minor releases during 1 year.

Starting June 1, whenever you buy a new personal or academic license or upgrade your existing one, you get 1 year of free upgrades, effectively meaning that you receive the upcoming ReSharper 8 for free.

Unlike the commercial license that can be purchased both with or without 1-year upgrade subscription, personal and academic licenses default to the subscription model, and do so without price increase. As a result, if you’re a personal or academic customer, there’s no more pain of buying a license and finding out in several months that you need to pay again in order to get the latest update.

dotCover 2.5 EAP is Open: Now with Hot Spots View

June 3rd, 2013 by Daria.Dovzhikova

We are excited to announce dotCover 2.5 Early Access Program launch. Now you can download and play with dotCover 2.5 early builds.

    And here is a list of what’s new:

  • dotCover 2.5 integrates with the latest ReSharper 8 EAP build. So if you were quick to install it, we are glad to tell that now you can continue using this combination.
  • With dotCover 2.5 you get an ability to merge coverage snapshots with different filters applied.
  • In version 2.5 we finalized the Hot Spots view, that helps you identify the most risky methods in your solution, in terms of high cyclomatic complexity and low unit test coverage:
    Hot Spots view in dotCover 2.5

One more improvement that was not yet implemented but is being worked on in the scope of this update is memory consumption optimization. Stay tuned for more details when we’re done with this improvement.

Please download dotCover 2.5 EAP build, and let us know about any issues you might be facing via dotCover issue tracker.

ReSharper 8 EAP Build: JIT Edition

May 30th, 2013 by Hadi Hariri

Well it’s here. With only one day left for the previous EAP to expire, we’ve managed to get a new EAP build. All is fine. Download the latest EAP now. Let’s see what’s in store in this build.

Move Instance Method Refactoring

This frequently requested refactoring allows moving instance methods from one class to another. Take the sample class below:

Before applying Move Instance Method refactoring

We can see that the Print method uses an instance field. Invoking an Move Instance Method refactoring on this method results in ReSharper prompting us for the destination class we want to move the method to. However, in addition to moving the method, it also wraps the field, in this case with a property, and passes in the current class as an argument to the method, resulting in

After applying Move Instance Method refactoring

Note that when it comes to choosing destination classes, this refactoring only offers those that are members of the original class. It’s also worth pointing out that Move Instance Method currently only supports C# but we’re working to ensure VB.NET support in subsequent builds.

Inspecting XAML Grids

We’ve added several new code inspections and quick-fixes related to the usage of grids in XAML markup. Although present in one of the previous EAP’s we’ve now polished it up for the current release and ready to talk about it some more.

With ReSharper 8, there’s no way you can declare a control that sits in a non-existent grid row or column and get away with it:

ReSharper detects a usage of an undefined row

What we have here is a parent grid with two defined rows and a nested grid referencing a grid row that doesn’t exist. In addition to helping you actually spot the problem, ReSharper 8 includes a quick-fix that will insert all the missing row definitions if that’s the way you want to sort out the issue:

Quick-fix to add missing row definitions

It adds the missing definitions without moving the caret around, and you stay exactly where you had been before the fix was applied. If you’re working with a complex layout and you stand at a grid row property that’s several screens away from row definitions, that saves you quite a bit of navigating through your code.

There’s also a new inspection that fires up whenever a control within a grid doesn’t specify a row or column number, and suggests a fix. Note that this inspection isn’t fired for the first control in a grid since developers often deliberately leave columns and rows for the first controls unspecified.

Quick-fix to add a missing grid row property value

We’re not only adding code inspections and corresponding quick-fixes but standalone context actions as well. Specifically, there are new context actions to add or remove a row or column definition before or after the current definition, as well as one to remove the current row or column definition.

ReSharper can help if you want to add or remove a column definition

XAML Refactorings

We have added a whole bunch of refactoring and enhancements for XAML, including Extract Style Refactoring, collapsing empty tags, code cleanup, styling daemons, and more. We’ll be covering these in more detail in a separate blog post.

UI Enhancements, Bug Fixes and More

Some touch-ups have been applied to the ReSharper UI where most of the older controls are now replaced with WPF ones. We’ve also fixed numerous bug reported since the previous EAP (thanks everyone for these reports and keep them coming). Additionally, two somewhat annoying bugs have also been fixed with this release, related to MSBuild. The first one is Conditional References with MSBuild and the second has to do with ResolveAssemblyReferencesDependsOn build task.

We hope you enjoy this latest release of ReSharper 8 EAP and as always, welcome bug reports and feedback. Download the latest EAP now.

Coverage Filters in dotCover

May 29th, 2013 by Maarten.Balliauw

Using dotCover, we can run coverage analysis on our code. We can verify which portions of our project are covered by unit tests and which are not. However, there are times when we don’t want to perform analysis on our entire project and instead want to target certain areas. This can be because we want our coverage analysis to run faster or because we want to exclude third-party or obsolete assemblies or classes from the resulting report.

Let’s have a look at how we can setup coverage filters using Visual Studio. Since dotCover also comes with a console runner, we’ll have a look at setting up coverage filters there as well.

Filtering coverage in Visual Studio

In the screenshot below, we can see test and code coverage results after running all unit tests for the Nancy framework. Code coverage has been run for all projects we’ve been testing, but also for our unit test assemblies themselves!

clip_image002

We can filter the test assemblies out by using Coverage Filters. Using the dotCover | Edit Coverage Filters… menu or the keyboard shortcut Ctrl+Alt+K, Ctrl+Alt+F, we can manage Coverage Filters. By default, dotCover already filters out code marked with the System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute attribute, but let’s add an additional filter using the Add filter toolbar button.

clip_image004

In the Add Coverage Filter dialog, we can specify which code should be analyzed or excluded from analysis. We can configure this based on several rules:

  • Based on a filter string which can match assembly names, class names and method names. Using these, we have fine-grained filter capabilities available. Note that class names and method names can contain wildcards as well, which means we can filter out certain namespaces or filter out method names that start or end in a given pattern.
  • Based on an attribute. We can use existing attributes (e.g. ObsoleteAttribute) as well as our own attribute. For example, we can create a DontCoverThisAttribute and use it throughout our codebase and let dotCover exclude all code marked with this attribute.

Since we want to exclude test assemblies from coverage and all our test assemblies have a name ending in .Tests, we can specify a filter using a wildcard pattern, as you can see in the image below.

clip_image006

Filters can be defined in different scopes:

  • All solutions, applying filters to all solutions on our computer
  • Current solution, specifying the filter should only be applied on the current solution

After clicking Ok, our filter will be applied during our next code coverage analysis run. As you can see from the next image, code coverage analysis has not been run on our unit test assemblies.

clip_image008

Note that coverage filters only tell the dotCover engine to not analyze code which matches a filter rule, it does not exclude the assemblies from the coverage report. If we want to completely hide the test assemblies from the results, we can right-click the tests node and use the Exclude selected node context menu.

For additional information about using dotCover’s filters please check the web help.

Filtering coverage with the console runner

In the screenshot below, we can see an XML report of code coverage analysis running on a number of unit tests in the Nancy framework. Code coverage has been run for many assemblies, apparently even including the test assemblies themselves!

clip_image010

To filter out these test assemblies, we can specify filters in our coverage configuration file, coverage.xml. Just like we can do in Visual Studio, the configuration file supports adding various filters types:

  • Include specific assemblies, classes or methods by listing them as childs of the IncludeFilters element
  • Exclude specific assemblies, classes or methods by listing them as childs of the ExcludeFilters element
  • Exclude code marked with a given attribute, by listing them in the AttributeFilters element

Let’s add a filter which uses a wildcard pattern to exclude all assemblies with the word “Test” in their name from coverage analysis:

clip_image012

During our next coverage analysis run, the specified filter(s) will be applied. As a result, our XML report will no longer contain information about assemblies that were excluded using filters:

clip_image014

For additional information about configuring the console runner, please refer to web help. Additional filter examples can be found in the web help as well.

Creating plugins for dotPeek

May 15th, 2013 by Maarten.Balliauw

In a previous post, we’ve seen that dotPeek supports creating and loading plugins. The NuGet plugin for dotPeek is a good example to demonstrate how to get started creating plugins for dotPeek. Sources for this plugin are available on GitHub. But let’s create a plugin of our own!

Before we start: dotPeek does not have a formal SDK yet. However it shares a lot of commonalities with ReSharper. In fact: dotPeek is built on the same platform as ReSharper reusing the project model, PSI, navigation and so on. Which is good news: we can use the ReSharper SDK (see the downloads page) to create plugins for dotPeek. Another option is to start from a class library project and work with a small NuGet package I’ve created to help you get started.

Creating a new plugin

To create a plugin for dotPeek, we can make use of the instructions provided with the ReSharper SDK. This involves a lot of project modifications so we’ll take the easy way out: we can create a dotPeek plugin by installing a NuGet package.

Install-Package JetBrains.DotPeek.PluginDevelopment

In Visual Studio, we can start out with a new Class Library project, making use of .NET 3.5 or up. Next, we can install the JetBrains.DotPeek.PluginDevelopment NuGet package into the project. This NuGet package will convert the class library we have into a dotPeek plugin by adding assembly references and several attributes. Note that the NuGet package will target the latest version of dotPeek that is installed on your system (which also means we have to have a copy of dotPeek installed).

That’s everything we have to do: by running our project, dotPeek will launch with our fresh plugin loaded:

New plugin for dotPeek

Now let’s see where those menu items are coming from…

Menus, toolbars and handlers

Menu items, like the About menu we saw when loading our plugin in dotPeek, are triggered using handlers. The AboutActionHandler.cs file in our project is a sample handler implementation.

About action handler

There are some things to note here:

  • The ActionHandler attribute denotes the fact that this class is a handler with a specific name, “MyFirstDotPeekPlugin.AboutAction” in this case.
  • Handlers are added to menus and toolbars in the Actions.xml file, referencing the action name. More information on actions.xml can be found in the ReSharper plugin documentation. To make working with Actions.xml easier, the NuGet package also added an Actions.xsd containing the full XML schema we can use.
  • Handlers implement two methods of the IActionHandler interface:

    • Update – specifying whether the action is enabled or disabled.
    • Execute – the code which is executed once an action is being invoked.

    The following handler will be always available and can open a new command dialog when invoked:

    Command line tool window in dotPeek

    We can add it to a menu or toolbar by updating the actions.xml file:

    Actions.xml for plugins

    Distributing a plugin

    There comes a time when we want to make our plugin available to the public. Distributing a plugin is a simple process:

    • Distribute the assembly compiled from your project
    • Users can copy this assembly into %LOCALAPPDATA%\JetBrains\dotPeek\v<your target dotPeek version>\plugins

    Another option is to generate a simple installation batch file, check my NuPeek plugin’s GitHub repository for more information.

    Further reading

    In this blog post, we’ve only scratched the top of the surface. With plugins, a lot of things are possible: we can add menu items, toolbar buttons, tool windows, options panes and so on. In fact, many of the features shipped with dotPeek are in fact built as plugins. It is advised to consult the ReSharper Plugin Development Guide for additional information on developing dotPeek plugins.

    Meet dotTrace 5.3.2 Performance with CLR 4.5 support

    May 14th, 2013 by Daria.Dovzhikova

    Today we are happy to announce availability of a new maintenance release of our .NET performance profiler. Please feel free to download and try the latest dotTrace 5.3.2 Performance.

    Starting from this update dotTrace Performance supports the latest version of CLR. In case you have already updated CLR to version 4.5 or just plan to do it, we would recommend to use this version of the profiler.