Commits

Nerzhul500 committed 115b58c

#23 Renaming namespaces
#24 Escaped string literals bug fixed

Comments (0)

Files changed (16)

SpellCheckerPlugin.sln

 		{55A52394-1616-42CF-9F80-21B7D66D9E7D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
 		{55A52394-1616-42CF-9F80-21B7D66D9E7D}.Debug|x64.ActiveCfg = Debug|Any CPU
 		{55A52394-1616-42CF-9F80-21B7D66D9E7D}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{55A52394-1616-42CF-9F80-21B7D66D9E7D}.Debug|x86.Build.0 = Debug|Any CPU
 		{55A52394-1616-42CF-9F80-21B7D66D9E7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{55A52394-1616-42CF-9F80-21B7D66D9E7D}.Release|Any CPU.Build.0 = Release|Any CPU
 		{55A52394-1616-42CF-9F80-21B7D66D9E7D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU

SpellCheckerPlugin/SpellCheckerPlugin.Tests/ReverseStringAvailabilityTests.cs

 using JetBrains.ReSharper.Feature.Services.Bulbs;
 using JetBrains.ReSharper.Feature.Services.CSharp.Bulbs;
 using JetBrains.ReSharper.Intentions.CSharp.Test;
+using JetBrains.ReSharper.Intentions.Extensibility;
 using NUnit.Framework;
 
 namespace SpellCheckerPlugin.Tests

SpellCheckerPlugin/SpellCheckerPlugin.Tests/ReverseStringExecuteTests.cs

 using JetBrains.ReSharper.Feature.Services.Bulbs;
 using JetBrains.ReSharper.Feature.Services.CSharp.Bulbs;
 using JetBrains.ReSharper.Intentions.CSharp.Test;
+using JetBrains.ReSharper.Intentions.Extensibility;
 using NUnit.Framework;
 
 namespace SpellCheckerPlugin.Tests

SpellCheckerPlugin/SpellCheckerPlugin.Tests/SpellCheckerPlugin.Tests.csproj

     <Content Include="ReadMe.txt" />
   </ItemGroup>
   <PropertyGroup>
-    <ReSharperSdkTargets Condition=" '$(ReSharperSdkTargets)' == '' ">$(MSBuildExtensionsPath)\JetBrains\ReSharper.SDK\v6.1</ReSharperSdkTargets>
+    <ReSharperSdkTargets Condition=" '$(ReSharperSdkTargets)' == '' ">$(MSBuildExtensionsPath)\JetBrains\ReSharper.SDK\v7.0</ReSharperSdkTargets>
   </PropertyGroup>
   <Import Project="$(ReSharperSdkTargets)\Plugin.Tests.Targets" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

SpellCheckerPlugin/SpellCheckerPlugin/Analyzers/StringLiteralTypoAnalyzer.cs

       SpellChecker checker = Shell.Instance.GetComponent<SpellChecker>();
       if (!element.ConstantValue.IsString()) 
         return;
-      string value = (string) element.ConstantValue.Value;
 
       DocumentRange literalRange = element.GetDocumentRange();
       if (literalRange.GetText().StartsWith("@"))
       DocumentRange innerLiteralRange = literalRange.ExtendLeft(-1).ExtendRight(-1);
       if (!literalRange.IsValid() && !innerLiteralRange.IsValid())
         return;
+      string value = innerLiteralRange.GetText();
       List<TextPart> textParts = TextSplitter.Split(value);
       foreach (var part in textParts)
       {

SpellCheckerPlugin/SpellCheckerPlugin/Bulbs/AdvancedTypoRenameBulbItem.cs

 using JetBrains.ReSharper.Psi;
 using JetBrains.ReSharper.Psi.Search;
 using JetBrains.ReSharper.Refactorings.Rename;
+using JetBrains.ReSharper.Refactorings.RenameNamespace;
 using JetBrains.ReSharper.Refactorings.Workflow;
 using JetBrains.TextControl;
 using SpellCheckerPlugin.Workflows;
     {
       var service = solution.GetComponent<RenameRefactoringService>();
       IRefactoringWorkflow workflow;
-      if (service.IsLocal(myElement))
+      if (myElement is INamespace)
+      {
+        workflow = new RenameNamespaceWorkflowDecorator("NamespaceTypoRename", mySuggestedNames);
+      }
+      else if (service.IsLocal(myElement))
       {
         workflow = new TypoInlineRenameWorkflowDecorator("InlineTypoRename", mySuggestedNames);
       }

SpellCheckerPlugin/SpellCheckerPlugin/Highlightings/CommentTypoHighlighting.cs

   [ConfigurableSeverityHighlighting(SeverityId,
     "CSHARP,VBASIC", OverlapResolve = OverlapResolveKind.WARNING,
     ToolTipFormatString = ToolTipFormatString)]
-  class CommentTypoHighlighting : TextRangeTypoHighlighting
+  public class CommentTypoHighlighting : TextRangeTypoHighlighting
   {
     private const string ToolTipFormatString = "Typo in comment: \"{0}\"";
     internal const string SeverityId = "CommentTypo";

SpellCheckerPlugin/SpellCheckerPlugin/Highlightings/StringLiteralTypoHighlighting.cs

   [ConfigurableSeverityHighlighting(SeverityId,
     "CSHARP,VBASIC", OverlapResolve = OverlapResolveKind.WARNING,
     ToolTipFormatString = ToolTipFormatString)]
-  class StringLiteralTypoHighlighting : TextRangeTypoHighlighting
+  public class StringLiteralTypoHighlighting : TextRangeTypoHighlighting
   {
     private const string ToolTipFormatString = "Typo in string: \"{0}\"";
     internal const string SeverityId = "StringLiteralTypo";

SpellCheckerPlugin/SpellCheckerPlugin/Highlightings/TextRangeTypoHighlighting.cs

 
 namespace SpellCheckerPlugin.Highlightings
 {
-  internal abstract class TextRangeTypoHighlighting : IHighlighting
+  public abstract class TextRangeTypoHighlighting : IHighlighting
   {
     protected DocumentRange myRange;
     private readonly List<string> mySuggestions;

SpellCheckerPlugin/SpellCheckerPlugin/Highlightings/XmlTextTypoHighlighting.cs

   [ConfigurableSeverityHighlighting(SeverityId,
     "XML,RESX,XAML", OverlapResolve = OverlapResolveKind.WARNING,
     ToolTipFormatString = ToolTipFormatString)]
-  class XmlTextTypoHighlighting : TextRangeTypoHighlighting
+  public class XmlTextTypoHighlighting : TextRangeTypoHighlighting
   {
     private const string ToolTipFormatString = "Typo in markup text: \"{0}\"";
     internal const string SeverityId = "XmlTextTypo";

SpellCheckerPlugin/SpellCheckerPlugin/Properties/AssemblyInfo.cs

 [assembly: AssemblyCopyright("Copyright © Artem Bukhonov, 2012")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
-[assembly: AssemblyVersion("1.0.3.0")]
-[assembly: AssemblyFileVersion("1.0.3.0")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
 [assembly: ActionsXml("SpellCheckerPlugin.Actions.xml")]
 
 // The following information is displayed by ReSharper in the Plugins dialog

SpellCheckerPlugin/SpellCheckerPlugin/QuickFixes/TypoQuickFix.cs

     public TypoQuickFix([NotNull] IdentifierTypoHighlighting highlighting)
     {
       myHighlighting = highlighting;
-      if (!highlighting.IsNamespace)
-        myBulbItems.Add(new AdvancedTypoRenameBulbItem(highlighting.Element, highlighting.Suggests));
+      myBulbItems.Add(new AdvancedTypoRenameBulbItem(highlighting.Element, highlighting.Suggests));
       string word = highlighting.WrongPart.Text;
       myBulbItems.Add(new AddToDictionaryBulbItem(word));
       AddInternalDictionaryItemDebugOnly(word);

SpellCheckerPlugin/SpellCheckerPlugin/SpellCheckerPlugin.csproj

       <HintPath>..\..\lib\NHunspell.dll</HintPath>
     </Reference>
     <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Drawing" />
     <Compile Include="SpellEngine\SpellChecker.cs" />
     <Compile Include="SpellEngine\SuggestionGenerator.cs" />
     <Compile Include="SpellEngine\TextSplitter.cs" />
+    <Compile Include="Workflows\ReflectionUtils.cs" />
+    <Compile Include="Workflows\RenameNamespaceControlDecorator.cs" />
+    <Compile Include="Workflows\RenameNamespaceWorkflowDecorator.cs" />
     <Compile Include="Workflows\RenameOverloadsPageDecorator.cs" />
     <Compile Include="Workflows\TypoInlineRenameWorkflowDecorator.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

SpellCheckerPlugin/SpellCheckerPlugin/Workflows/ReflectionUtils.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+
+namespace SpellCheckerPlugin.Workflows
+{
+  public static class ReflectionUtils
+  {
+    public static TField GetFieldOfInstance<TField, TFieldOwner>(TFieldOwner instance, string fieldName) 
+      where TField : class 
+      where TFieldOwner : class 
+    {
+      Type ownerType = typeof (TFieldOwner);
+      FieldInfo fieldInfo = ownerType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
+      if (fieldInfo == null)
+        return default(TField);
+      return fieldInfo.GetValue(instance) as TField;
+    }
+
+    public static void SetFieldOfInstance<TField, TFieldOwner>(TFieldOwner ownerInstance, TField fieldInstance, string fieldName)
+    {
+      Type ownerType = typeof (TFieldOwner);
+      FieldInfo fieldInfo = ownerType.GetField(fieldName);
+      if (fieldInfo == null)
+        return;
+      fieldInfo.SetValue(ownerInstance, fieldInstance);
+    }
+  }
+}

SpellCheckerPlugin/SpellCheckerPlugin/Workflows/RenameNamespaceControlDecorator.cs

+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Drawing;
+using System.Windows.Forms;
+using System.Linq;
+using JetBrains.Application.Progress;
+using JetBrains.CommonControls.Validation;
+using JetBrains.DataFlow;
+using JetBrains.ReSharper.Refactorings.RenameNamespace;
+using JetBrains.ReSharper.Refactorings.Workflow;
+using JetBrains.UI.CrossFramework;
+
+namespace SpellCheckerPlugin.Workflows
+{
+  internal class RenameNamespaceControlDecorator : IRefactoringPage, IValidatorProvider
+  {
+    private readonly RenameNamespaceControl mySourceControl;
+    private readonly ContextMenuStrip mySuggestMenu = new ContextMenuStrip();
+    private readonly TextBox myOriginalTextBox;
+
+    public RenameNamespaceControlDecorator(RenameNamespaceControl sourceControl, List<string> suggests)
+    {
+      mySourceControl = sourceControl;
+      myOriginalTextBox = ReflectionUtils.GetFieldOfInstance<TextBox, RenameNamespaceControl>
+        (sourceControl, "myNewNameTextEdit");
+      if (myOriginalTextBox != null)
+      {
+        myOriginalTextBox.KeyDown += (sender, args) =>
+                                       {
+                                         if (args.KeyCode == Keys.Up || args.KeyCode == Keys.Down)
+                                         {
+                                           ShowSuggests();
+                                         }
+                                       };
+        string originalName = myOriginalTextBox.Text;
+        
+        
+        foreach (var suggest in suggests)
+        {
+          var name = GetNamespaceNameFromOriginal(originalName, suggest);
+          ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem(name);
+          toolStripMenuItem.Click += (sender, args) =>
+                                            {
+                                              string s = (sender as ToolStripMenuItem).Text;
+                                              myOriginalTextBox.Text = s;
+                                            };
+          mySuggestMenu.Items.Add(toolStripMenuItem);
+        }
+        myOriginalTextBox.GotFocus += (sender, args) => ShowSuggests();
+      }
+    }
+
+    private static string GetNamespaceNameFromOriginal(string originalName, string possibleName)
+    {
+      int resultPartCount = originalName.Count(c => c == '.') + 1;
+      string[] possibleParts = possibleName.Split('.');
+      if (resultPartCount == 1)
+        return possibleParts[0];
+      Debug.Assert(possibleParts.Length >= resultPartCount);
+      
+      string[] resultParts = possibleParts.Take(resultPartCount).ToArray();
+      return string.Join(".", resultParts);
+    }
+
+    public IRefactoringPage Commit(IProgressIndicator pi)
+    {
+      return mySourceControl.Commit(pi);
+    }
+
+    public bool Initialize(IProgressIndicator pi)
+    {
+      return mySourceControl.Initialize(pi);
+    }
+
+    public bool RefreshContents(IProgressIndicator pi)
+    {
+      return mySourceControl.RefreshContents(pi);
+    }
+
+    public IProperty<bool> ContinueEnabled
+    {
+      get { return mySourceControl.ContinueEnabled; }
+    }
+
+    public string Description
+    {
+      get { return mySourceControl.Description; }
+    }
+
+    public string Title
+    {
+      get { return mySourceControl.Title; }
+    }
+
+    public EitherControl View
+    {
+      get { return mySourceControl.View; }
+    }
+
+    public bool DoNotShow
+    {
+      get { return mySourceControl.DoNotShow; }
+    }
+
+    public IEnumerable<IValidator> Validators
+    {
+      get { return mySourceControl.Validators; }
+    }
+
+    private void ShowSuggests()
+    {
+      mySuggestMenu.Show(myOriginalTextBox, new Point(0, myOriginalTextBox.Height));
+    }
+  }
+}

SpellCheckerPlugin/SpellCheckerPlugin/Workflows/RenameNamespaceWorkflowDecorator.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using JetBrains.ProjectModel;
+using JetBrains.ReSharper.Psi;
+using JetBrains.ReSharper.Refactorings.Conflicts;
+using JetBrains.ReSharper.Refactorings.RenameNamespace;
+using JetBrains.ReSharper.Refactorings.Workflow;
+using JetBrains.UI.Icons;
+
+namespace SpellCheckerPlugin.Workflows
+{
+  public class RenameNamespaceWorkflowDecorator : RenameNamespaceRefactoringWorkflow
+  {
+    private readonly List<string> mySuggests;
+
+    public RenameNamespaceWorkflowDecorator(string actionId, List<string> suggests) : base(actionId)
+    {
+      mySuggests = suggests;
+    }
+
+    public override IRefactoringPage FirstPendingRefactoringPage
+    {
+      get
+      {
+        var page = base.FirstPendingRefactoringPage;
+        RenameNamespaceControl renameNamespaceControl = page as RenameNamespaceControl;
+        if (renameNamespaceControl != null)
+        {
+          RenameNamespaceControlDecorator decorator = new RenameNamespaceControlDecorator(renameNamespaceControl, mySuggests);
+          return decorator;
+        }
+        return page;
+      }
+    }
+  }
+}