Browse Source

Insert after last using instead of inserting before namespace declaration.

This affects the placement of whitespace.
newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
964c2afbfe
  1. 12
      ICSharpCode.NRefactory.CSharp/Refactoring/UsingHelper.cs
  2. 11
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionAlphabeticalTests.cs
  3. 6
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionInsideNamespaceTests.cs
  4. 4
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionTests.cs
  5. 6
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingRunActionTests.cs
  6. 2
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateMethodDeclarationTests.cs

12
ICSharpCode.NRefactory.CSharp/Refactoring/UsingHelper.cs

@ -64,6 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -64,6 +64,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
// Find the main block of using declarations in the chosen scope:
AstNode blockStart = usingParent.Children.FirstOrDefault(IsUsingDeclaration);
AstNode insertionPoint;
bool insertAfter = false;
if (blockStart == null) {
// no using declarations in the file
Debug.Assert(SyntaxTree.MemberRole == NamespaceDeclaration.MemberRole);
@ -72,9 +73,18 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -72,9 +73,18 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
insertionPoint = blockStart;
while (IsUsingDeclaration(insertionPoint) && newUsingInfo.CompareTo(new UsingInfo(insertionPoint, context)) > 0)
insertionPoint = insertionPoint.NextSibling;
if (!IsUsingDeclaration(insertionPoint)) {
// Insert after last using instead of before next node
// This affects where empty lines get placed.
insertionPoint = insertionPoint.PrevSibling;
insertAfter = true;
}
}
if (insertionPoint != null) {
script.InsertBefore(insertionPoint, newUsing);
if (insertAfter)
script.InsertAfter(insertionPoint, newUsing);
else
script.InsertBefore(insertionPoint, newUsing);
}
}

11
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionAlphabeticalTests.cs

@ -1,14 +1,12 @@ @@ -1,14 +1,12 @@
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.CodeIssues;
using System.Linq;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using NUnit.Framework;
using ICSharpCode.NRefactory.CSharp.CodeActions;
using ICSharpCode.NRefactory.CSharp;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
namespace ICSharpCode.NRefactory.CSharp.CodeActions.AddUsing
{
[TestFixture]
public class UnresolvedTypeActionAlphabeticalTests : ContextActionTestBase
public class AddUsingActionAlphabeticalTests : ContextActionTestBase
{
[Test]
public void ShouldAddUsingAtStartIfItIsTheFirstAlphabetically()
@ -71,7 +69,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType @@ -71,7 +69,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
}
[Test]
[Ignore("Add using does not honor the blank line setting yet")]
public void ShouldInsertUsingAfterExistingUsings()
{
string testCode =

6
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionInsideNamespaceTests.cs

@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions; @@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
namespace ICSharpCode.NRefactory.CSharp.CodeActions.AddUsing
{
[TestFixture]
public class UnresolvedTypeActionInsideNamespaceTests : ContextActionTestBase
public class AddUsingActionInsideNamespaceTests : ContextActionTestBase
{
[Test]
public void ShouldInsertUsingStatement()
@ -98,7 +98,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType @@ -98,7 +98,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
}
[Test]
[Ignore("Something is wrong with the blank lines")]
public void ShouldAddUsingAfterExistingUsings()
{
string testCode =
@ -163,7 +162,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType @@ -163,7 +162,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
}
[Test]
[Ignore("Something is wrong with the blank lines")]
public void ShouldAddUsingAfterExistingUsingsInMostNestedNamespace()
{
string testCode =

4
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingActionTests.cs

@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions; @@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
namespace ICSharpCode.NRefactory.CSharp.CodeActions.AddUsing
{
[TestFixture]
public class UnresolvedTypeIssueTests : ContextActionTestBase
public class AddUsingActionTests : ContextActionTestBase
{
void UnresolvedTypeName(string code, string typeName, params string[] namespaces)
{

6
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/AddUsing/AddUsingRunActionTests.cs

@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions; @@ -4,10 +4,10 @@ using ICSharpCode.NRefactory.CSharp.CodeActions;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.CodeIssues.UnresolvedType
namespace ICSharpCode.NRefactory.CSharp.CodeActions.AddUsing
{
[TestFixture]
public class UnresolvedTypeActionTests : ContextActionTestBase
public class AddUsingRunActionTests : ContextActionTestBase
{
[Test]
[Ignore("Add using does not honor the blank line setting yet")]
@ -125,7 +125,6 @@ namespace TestNamespace @@ -125,7 +125,6 @@ namespace TestNamespace
}
[Test]
[Ignore("Something else is broken regarding blank lines as well")]
public void ShouldNotAddBlankLinesAfterIfTheyAreAlreadyThere()
{
string testCode =
@ -155,7 +154,6 @@ namespace TestNamespace @@ -155,7 +154,6 @@ namespace TestNamespace
}
[Test]
[Ignore("Something else is broken regarding blank lines as well")]
public void ShouldLeaveAdditionalBlankLinesThatAlreadyExist()
{
string testCode =

2
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/CreateMethodDeclarationTests.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
//
//
// CreateMethodDeclarationTests.cs
//
// Author:

Loading…
Cancel
Save