Browse Source

Fix bug in "AddUsingDeclaration" refactoring: when running the refactoring two times quickly after another (without waiting for a reparse), the list of using declarations would get corrupted.

Use correct sorting logic for inserting using declarations.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5001 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
cc0f7f60e7
  1. 17
      src/Main/Base/Project/Src/Services/RefactoringService/NamespaceRefactoringService.cs
  2. 1
      src/Main/Base/Project/Src/Services/RefactoringService/RefactoringMenuBuilder.cs

17
src/Main/Base/Project/Src/Services/RefactoringService/NamespaceRefactoringService.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -32,7 +32,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
} else if (!IsSystemNamespace(u1) && IsSystemNamespace(u2)) {
return 1;
}
return a.Usings[0].CompareTo(b.Usings[0]);
return u1.CompareTo(u2);
}
if (a.Aliases.Count != 0 && b.Aliases.Count != 0) {
return a.Aliases.Keys.First().CompareTo(b.Aliases.Keys.First());
@ -95,6 +95,17 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -95,6 +95,17 @@ namespace ICSharpCode.SharpDevelop.Refactoring
public static void AddUsingDeclaration(ICompilationUnit cu, IDocument document, string newNamespace, bool sortExistingUsings)
{
if (cu == null)
throw new ArgumentNullException("cu");
if (document == null)
throw new ArgumentNullException("document");
if (newNamespace == null)
throw new ArgumentNullException("newNamespace");
ParseInformation info = ParserService.ParseFile(cu.FileName, document.TextContent);
if (info != null)
cu = info.MostRecentCompilationUnit;
IUsing newUsingDecl = new DefaultUsing(cu.ProjectContent);
newUsingDecl.Usings.Add(newNamespace);
@ -104,9 +115,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -104,9 +115,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
}
bool inserted = false;
for (int i = 0; i < newUsings.Count; i++) {
if (newUsings[i].Usings.Count >= 1
&& cu.ProjectContent.Language.NameComparer.Compare(newNamespace, newUsings[i].Usings[0]) <= 0)
{
if (CompareUsings(newUsingDecl, newUsings[i]) <= 0) {
newUsings.Insert(i, newUsingDecl);
inserted = true;
break;

1
src/Main/Base/Project/Src/Services/RefactoringService/RefactoringMenuBuilder.cs

@ -188,6 +188,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -188,6 +188,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
item.DropDownItems.Add(subItem);
subItem.Click += delegate {
NamespaceRefactoringService.AddUsingDeclaration(callingClass.CompilationUnit, textArea.Document, newNamespace, true);
ParserService.StartAsyncParse(callingClass.CompilationUnit.FileName, textArea.Document.TextContent);
textArea.MotherTextEditorControl.Refresh();
};
}

Loading…
Cancel
Save