Archive for the ‘ReSharper’ Category

ReSharper Search and Replace with Pattern

Monday, August 9th, 2010

Endlich bin ich dazu gekommen, das ReSharper Feature Search and Replace with Pattern auszuprobieren.

Die Herausforderung

Es nervt mich, wenn ich über älteren Code stolpere, in dem ich noch mit Assert.AreEqual gearbeitet habe. Aktuell verwende ich lieber Assert.That, weil das für mich besser lesbar ist. Also habe ich nach einer Möglichkeit gesucht, die eine in die andere Variante zu ändern. Auf Knopfdruck versteht sich.

Die Lösung

Mit ReSharper ist die Lösung ganz einfach. Man legt sich ein entsprechendes Replace Pattern an:

  • Find: Assert.AreEqual($expected$, $actual$);
  • Replace: Assert.That($actual$, Is.EqualTo($expected$));

Die beiden Platzhalter $expected$ und $actual$ werden als Parameter definiert. Editieren kann man das Pattern über die Menüfunktion ReSharper | Find | Search with pattern…

Edit Highlighting Pattern

Das coolste an diesem Feature: man kann dem Pattern eine Pattern severity zuordnen, z.B. “Show as warning”. ReSharper weist dann in Quellcodedateien auf gefundene Instanzen des Patterns hin und bietet einen Quickfix an. So wird durch einen einfachen Druck auf Alt-Enter eine Assertion im “alten Stil” aktualisiert.

Verzeichnis- und Namespacestruktur

Thursday, November 20th, 2008

Bislang bin ich in Projekten leider etwas leichtfertig mit den Namespaces umgegangen. Ob der Namespace einer Klasse zur Verzeichnisstruktur in der die Datei liegt passte oder nicht war mir manchmal “egal”.

Ob man nun ein Freund vieler Projekte innerhalb einer Solution ist oder seine Projekte hauptsächlich durch die Verzeichnishierarchie strukturiert ist nebensächlich. Eine Verzeichnisstruktur ist in jedem Fall notwendig, andernfalls verliert man den Überblick. Und wenn man die Verzeichnisstruktur gleichzeitig als Namespacestruktur verwendet hat man sozusagen zwei Fliegen mit einer Klappe erwischt.

ReSharper bietet die Möglichkeit auf Namespaces die nicht zur Verzeichnisstruktur passen hinzuweisen.

20.14

Wenn man die Inspection Severity für diese Analyse auf Error einstellt werden alle fehlerhaften Namespaces in die globale Fehler Analyse aufgenommen.

20.15

So kann man mit Alt-F12 (Next Error in Solution) bequem von Fehler zu Fehler springen und die Namespaces korrigieren.

Die Inspection Severity kann man über ReSharper | Options… | Inspection Severity | Code Structure Analysis einstellen.

20.11

Alternativ betätigt man auf einem fehlerhaften Namespace die Tastenkombination Alt-Enter und wählt aus dem Popupmenü den Punkt Inspection Options

20.12

…und wählt dann die gewünschte Severity.

20.13

Aus dem selben Popup Menü kann man den Punkt Move to Namespace… auswählen um den Namespace an die Verzeichnisstruktur anzupassen. Dabei werden alle Referenzen ebenfalls korrigiert.

Technorati-Tags:

File Upload zu Google Code

Saturday, June 14th, 2008

Wenn man bei http://code.google.com ein neues Projekt anlegt und dann sofort versucht eine Datei in den Download Bereich hoch zu laden gibt’s die lapidare Fehlermeldung dass man keine Berechtigung dazu hätte und man solle sich an den Administrator des Projektes wenden.

Abhilfe: neu anmelden. Da muss man erst mal drauf kommen…

Es ging übrigens um das ReSharper NHibernate Plugin welches jetzt als Open Source zur Verfügung steht.

Technorati-Tags:

ReSharper 4.0 ist fertig

Tuesday, June 10th, 2008

JetBrains hat ReSharper 4.0 fertiggestellt. Ich verwende ReSharper 4.0 seit dem ersten öffentlichen nightly build und kann nur sagen dass JetBrains damit ein Spitzenprodukt weiter verbessert hat. Das wichtigste Feature ist natürlich die Unterstützung aller C# 3.0 Sprachelemente (Lambdas, Extension Methods, LINQ, etc.). Darüber hinaus gibt es neue Features wie z.B.

  • Inline Method: Gegenstück zu Extract Method. Nun kann man beim Refactoring endlich den Rumpf einer Methode inline an den Verwendungsstellen einfügen.
  • Complete Statement: mit Ctrl + Shift + Enter wird die Zeile syntaktisch vervollständigt und der Cursor in die nächste Zeile bewegt. Sehr nützlich bei der Eingabe von if-Statements etc.
  • ASP.NET Performance Verbesserungen: ReSharpers Performance beim Umgang mit ASP.NET Projekten wurde verbessert. Auch der Speicherbedarf wurde reduziert.

Wer ReSharper noch nicht kennt sollte schleunigst hier den Download starten und R# 30 Tage testen. Aber Vorsicht! Suchtgefahr ;-)

Wer mit NHibernate arbeitet sollte zusätzlich mein NHibernate Plugin in Betracht ziehen. Derzeit ist das Projekt noch im Alphastadium aber bereits so stabil dass ich es produktiv im Einsatz habe.

Technorati-Tags: ,

Pay technical debt – Tilge deinen technischen Kredit

Wednesday, May 28th, 2008

Leider ist es nicht immer möglich Code abzuliefern mit dem man selbst bzw. das Team 100% zufrieden ist. Dies kann z.B. daran liegen dass man keine Zeit hat. Sollte dieser Grund oft oder sogar dauerhaft vorliegen sollte sich das Team allerdings die Frage stellen warum man keine Zeit hat ordentliche Arbeit abzuliefern und stattdessen legacy code produziert. Ich verwende den Begriff legacy code übrigens wie Michael Feathers im Sinne von “Code ohne Tests”.

Doch nicht nur mangelnde Zeit kann Grund dafür sein dass man Code verbessern muss, auch neue Erkenntnisse führen dazu. Der einzelne Software Entwickler sowie das Team entwickeln sich (hoffentlich…) weiter und neue Erkenntnisse bzw. ein besseres Verständnis schlagen sich in besserem Code nieder. Ferner entwickelt sich das Produkt weiter, auch dabei muss der Code “mitwachsen”. Aus gutem Grund lautet das Mantra des testdriven development (TDD) Red – Green – Refactor.

Das zeitliche Verschieben des Refactoring ist vergleichbar mit der Aufnahme eines Kredits. Je später man ihn zurück zahlt desto höher fallen die Zinsen aus. Und Zinsen haben eine extrem gefährliche Eigenschaft die oft übersehen wird: sie wachsen exponentiell! Auch diese Eigenschaft lässt sich auf die Softwareentwicklung übertragen. Schiebt man Verbesserungen am Code zu lange vor sich her hat man irgendwann den big ball of mud, einen dicken ekligen Klumpen Code an den sich niemand mehr ran wagt.

Fazit:

  • Technischen Kredit so schnell wie möglich zurück zahlen
  • TODO Kommentare schreiben um die “Kredite” wiederzufinden (ReSharper hat einen To-Do Explorer um alle TODO Kommentare anzuzeigen)
Technorati-Tags: ,

ReSharper NHibernate Plugin 1.0 Alpha 1

Monday, May 26th, 2008

I’m glad to announce the first alpha release of version 1.0 of my ReSharper NHibernate plugin (v0.9.1). You can download the binary version here. Source code will soon be released.

Please note! The R# open api changes somewhere between build 804 and build 807. The plugin is compiled against build 807 and should work with build 807 and above. Please let me know if you have problems using the plugin with a R# build.

Features for v1.0

Navigation and refactoring

  • References to properties and fields in mapping files are found. That means you can Ctrl-Click (Go To Declaration) on a mapped property in the mapping file to navigate to its declaration.
  • Full rename refactoring support on mapped properties and fields.
  • You can navigate from the declaration to the mapping file by Go To Usage (or Find Usages).
  • NHibernates access attribute is interpreted so that mapped fields are found. Note that internal or private fields are not found because of a limitation in ReSharpers reference searcher. If mapping file and implementation of the mapped class are in different assemblies the mapping assembly should reference the assembly with the class implementaion in order to find the references.

Analysis support for .hbm.xml files

  • Undefined mapped properties are marked
  • Undefined types and namespaces are marked
  • Mapping files that are not embedded as resource are marked (#1 error)
  • Undefined access attribute values are marked (only the predefined values are supported)
  • The severity of the errors can be configured under ReSharper | Options | Code Inspection | Inspection Severity | NHibernate mappings.

What’s next?

The next days I will work on releasing the plugin as open source. Plans for future releases are better support for class names and quick fixes for errors found in code inspection. If you would like to see any feature drop me a note please.

Hope you enjoy it! If you find any bugs it would be nice to hear from you!

Technorati-Tags: ,

NHibernate Plugin – Update

Wednesday, April 23rd, 2008

Please note that there is an update to the plugin!

You can find an updated version 0.1.6 of my ReSharper NHibernate Plugin here.

The plugin is compiled against ReSharper build 780. There was a breaking change in the open api so this version should work with build 775 and above.

I worked on the mapping file parser and started to support references. You can Ctrl-Click on a mapped id name, property name or component name to navigate to the declaring source. This works for mapped properties and fields, the access attribute is evaluated. Support for bag, many-to-one etc. will be added soon.

The way back from C# to the mapping file for example with Find Usages/Alt-F7 is still not ready. Sometimes the reference to a mapped property is found, sometimes not. Sorry for that, I’m working on it.

Technorati-Tags: ,

ReSharper NHibernate Plugin Update

Wednesday, April 2nd, 2008

Update: Version 0.1.6 is released which works with ReSharper build 775 and above. See details.

A new build of my NHibernate plugin is available for download here.

I worked mainly on the analysis of .hbm.xml files. The access attribute is now interpreted to find mapped properties and fields. Please note that only the standard values are supported. If you have implemented your own access method (IPropertyAccessor) it is marked as an error.

You may change the severity of the inspections under the usual

  • ReSharper | Options… | Inspection severity | NHibernate mappings.

Please note that the error indicator on the right is not working, only the stripes per error are displayed. I think it is a problem of the EAP version (latest build I used was 767). JetBrainers if you are reading this: please answer my questions in your OpenAPI forum ;-)

Next features I will work on are quick-fixes and navigation.

Please drop me a note if you find any bug or would like to see some feature.

Technorati-Tags: ,

ReSharper NHibernate Plugin – Early bird release

Thursday, March 27th, 2008

Please note that there is an update to the plugin!

I started to implement a ReSharper plugin to support NHibernate mapping files. It runs with ReSharper 4.0 only, so you need to get one of the nightly EAP builds from here.

Please note that the plugin is in a very early state and far away from complete. What we have so far is analysis of .hbm.xml files:

  • Name and type of mapped class is verified
  • Id name and type is verified
  • Property names and types are verified (not the access attribute!)
  • many-to-one and one-to-one names and types are verified
  • Component names and types are verified, including properties and nested components
  • Subclass names are verified

Pease note that the access attribute is not evaluated, so mapped properties have to exist as a property in the mapped class. I will work on this next and will support the standard access methods like field.pascalcase-m-underscore.

After finishing the analysis stage I will start to implement features like navigation (for example from mapped property to mapping file), refactoring (support for rename class/property/field beeing the most wanted) and quick-fixes (for example map this property).

I will release the plugin as open source later. First I have to check many things with JetBrains (for example how to do automated unit tests) and have to clean up the code.

For those of you who can’t wait, here is the download link. You will find a little batch script that copies the plugin files. Please close VS2008 before copying.

Feel free to contact me for feedback, bug reports and feature requests.

Technorati-Tags: ,

ReSharper 4.0 – Erster Eindruck

Saturday, February 16th, 2008

Gestern Abend habe ich das erste Nightly Build (729) von ReSharper 4.0 für VS2008 installiert. Das Setup hat reibungslos funktioniert und hat die vorhandene Version 3.1 (Build 595) ersetzt ohne dass ich vorher ein Uninstall machen musste. Sehr schön!

Auf den ersten Blick macht dieser erste öffentlich zugängliche Build einen guten Eindruck. Die Funktionalität der Version 3.1 scheint intakt. Was sofort auffällt sind die neuen Warnungen und Quick Fixes. So werden jetzt z.B. überflüssige Initialisierungen erkannt und auf Wunsch entfernt:

public class A {
  private IList<B> list = null;  // Initialisieren auf Default ist unnötig
}

Gespannt war ich natürlich ob ReSharper mit den neuen Sprachelementen von C# 3.0 klarkommt. Und dabei habe ich dann gleich den ersten Bug gefunden:

using System;
using System.Linq.Expressions;

namespace Lambdas
{
  public class Lambda
  {
    public int TakeLambda(Func<string, int> f, string s) {
      return f(s);
    }

    public int TakeExpression(Expression<Func<string, int>> f, string s) {
      return f.Compile().Invoke(s);
    }

    public void Example() {
      // Ok
      var i = TakeLambda(x => x.Length, "abc");

      // ReSharper 4.0 Build 729 erkennt ".Length" nicht
      var j = TakeExpression(x => x.Length, "abc");
    }
  }
}
 
Solange man eine Lambda Expression an einen Parameter vom Typ Func<P, Q> übergibt ist alles in Ordnung, ist der Parameter aber vom Type Expression<Func<P, Q>> kann ReSharper offensichtlich den Typ der Lambda Expression nicht inferieren.
 
Fazit: ich werde ReSharper 4.0 ab sofort produktiv einsetzen.
 
Technorati-Tags: