104 changed files with 6577 additions and 4248 deletions
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,145 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using ICSharpCode.NRefactory.Semantics; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
[ContextAction("Sort usings", Description = "Sorts usings by their origin and then alphabetically.")] |
||||||
|
public class SortUsingsAction: ICodeActionProvider |
||||||
|
{ |
||||||
|
public IEnumerable<CodeAction> GetActions(RefactoringContext context) |
||||||
|
{ |
||||||
|
var usingNode = FindUsingNodeAtCursor(context); |
||||||
|
if (usingNode == null) |
||||||
|
yield break; |
||||||
|
|
||||||
|
yield return new CodeAction(context.TranslateString("Sort usings"), script => |
||||||
|
{ |
||||||
|
var blocks = EnumerateUsingBlocks(context.RootNode); |
||||||
|
|
||||||
|
foreach (var block in blocks) |
||||||
|
{ |
||||||
|
var originalNodes = block.ToArray(); |
||||||
|
var sortedNodes = SortUsingBlock(originalNodes, context).ToArray(); |
||||||
|
|
||||||
|
for (var i = 0; i < originalNodes.Length; ++i) |
||||||
|
script.Replace(originalNodes[i], sortedNodes[i].Clone()); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
private static AstNode FindUsingNodeAtCursor(RefactoringContext context) |
||||||
|
{ |
||||||
|
// If cursor is inside using declaration
|
||||||
|
var locationAsIs = context.Location; |
||||||
|
// If cursor is at end of line with using declaration
|
||||||
|
var locationLeft = new TextLocation(locationAsIs.Line, locationAsIs.Column - 1); |
||||||
|
|
||||||
|
var possibleNodes = new[] { locationAsIs, locationLeft } |
||||||
|
.Select(_ => context.RootNode.GetNodeAt(_, IsUsingDeclaration)); |
||||||
|
var usingNode = possibleNodes.Where(_ => _ != null).Distinct().SingleOrDefault(); |
||||||
|
|
||||||
|
return usingNode; |
||||||
|
} |
||||||
|
|
||||||
|
private static bool IsUsingDeclaration(AstNode node) |
||||||
|
{ |
||||||
|
return node is UsingDeclaration || node is UsingAliasDeclaration; |
||||||
|
} |
||||||
|
|
||||||
|
private static IEnumerable<IEnumerable<AstNode>> EnumerateUsingBlocks(AstNode root) |
||||||
|
{ |
||||||
|
var alreadyAddedNodes = new HashSet<AstNode>(); |
||||||
|
|
||||||
|
foreach (var child in root.Descendants) |
||||||
|
if (IsUsingDeclaration(child) && !alreadyAddedNodes.Contains(child)) { |
||||||
|
var blockNodes = EnumerateUsingBlockNodes(child); |
||||||
|
|
||||||
|
alreadyAddedNodes.UnionWith(blockNodes); |
||||||
|
yield return blockNodes; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static IEnumerable<AstNode> EnumerateUsingBlockNodes(AstNode firstNode) |
||||||
|
{ |
||||||
|
for (var node = firstNode; IsUsingDeclaration(node); node = node.NextSibling) |
||||||
|
yield return node; |
||||||
|
} |
||||||
|
|
||||||
|
private static IEnumerable<AstNode> SortUsingBlock(IEnumerable<AstNode> nodes, RefactoringContext context) |
||||||
|
{ |
||||||
|
var infos = nodes.Select(_ => new UsingInfo(_, context)); |
||||||
|
var orderedInfos = infos.OrderBy(_ => _, new UsingInfoComparer()); |
||||||
|
var orderedNodes = orderedInfos.Select(_ => _.Node); |
||||||
|
|
||||||
|
return orderedNodes; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private sealed class UsingInfo |
||||||
|
{ |
||||||
|
public AstNode Node { get; private set; } |
||||||
|
|
||||||
|
public string Alias { get; private set; } |
||||||
|
public string Name { get; private set; } |
||||||
|
|
||||||
|
public bool IsAlias { get; private set; } |
||||||
|
public bool IsAssembly { get; private set; } |
||||||
|
public bool IsSystem { get; private set; } |
||||||
|
|
||||||
|
public UsingInfo(AstNode node, RefactoringContext context) |
||||||
|
{ |
||||||
|
var importAndAlias = GetImportAndAlias(node); |
||||||
|
|
||||||
|
Node = node; |
||||||
|
|
||||||
|
Alias = importAndAlias.Item2; |
||||||
|
Name = importAndAlias.Item1.ToString(); |
||||||
|
|
||||||
|
IsAlias = Alias != null; |
||||||
|
|
||||||
|
var result = context.Resolve(importAndAlias.Item1) as NamespaceResolveResult; |
||||||
|
var mainSourceAssembly = result != null ? result.Namespace.ContributingAssemblies.First() : null; |
||||||
|
var unresolvedAssembly = mainSourceAssembly != null ? mainSourceAssembly.UnresolvedAssembly : null; |
||||||
|
IsAssembly = unresolvedAssembly is DefaultUnresolvedAssembly; |
||||||
|
|
||||||
|
IsSystem = IsAssembly && Name.StartsWith("System"); |
||||||
|
} |
||||||
|
|
||||||
|
private static Tuple<AstType, string> GetImportAndAlias(AstNode node) |
||||||
|
{ |
||||||
|
var plainUsing = node as UsingDeclaration; |
||||||
|
if (plainUsing != null) |
||||||
|
return Tuple.Create(plainUsing.Import, (string)null); |
||||||
|
|
||||||
|
var aliasUsing = node as UsingAliasDeclaration; |
||||||
|
if (aliasUsing != null) |
||||||
|
return Tuple.Create(aliasUsing.Import, aliasUsing.Alias); |
||||||
|
|
||||||
|
throw new InvalidOperationException(string.Format("Invalid using node: {0}", node)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private sealed class UsingInfoComparer: IComparer<UsingInfo> |
||||||
|
{ |
||||||
|
public int Compare(UsingInfo x, UsingInfo y) |
||||||
|
{ |
||||||
|
if (x.IsAlias != y.IsAlias) |
||||||
|
return x.IsAlias && !y.IsAlias ? 1 : -1; |
||||||
|
else if (x.IsAssembly != y.IsAssembly) |
||||||
|
return x.IsAssembly && !y.IsAssembly ? -1 : 1; |
||||||
|
else if (x.IsSystem != y.IsSystem) |
||||||
|
return x.IsSystem && !y.IsSystem ? -1 : 1; |
||||||
|
else if (x.Alias != y.Alias) |
||||||
|
return Comparer<string>.Default.Compare(x.Alias, y.Alias); |
||||||
|
else if (x.Name != y.Name) |
||||||
|
return Comparer<string>.Default.Compare(x.Name, y.Name); |
||||||
|
else |
||||||
|
return 0; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,60 +0,0 @@ |
|||||||
//
|
|
||||||
// VariableNotUsedIssue.cs
|
|
||||||
//
|
|
||||||
// Author:
|
|
||||||
// Mansheng Yang <lightyang0@gmail.com>
|
|
||||||
//
|
|
||||||
// Copyright (c) 2012 Mansheng Yang <lightyang0@gmail.com>
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
|
||||||
// in the Software without restriction, including without limitation the rights
|
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
|
||||||
// furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in
|
|
||||||
// all copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
// THE SOFTWARE.
|
|
||||||
|
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Linq; |
|
||||||
using ICSharpCode.NRefactory.CSharp.Resolver; |
|
||||||
using ICSharpCode.NRefactory.TypeSystem; |
|
||||||
|
|
||||||
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
|
||||||
{ |
|
||||||
public abstract class VariableNotUsedIssue : ICodeIssueProvider |
|
||||||
{ |
|
||||||
static FindReferences refFinder = new FindReferences (); |
|
||||||
|
|
||||||
public IEnumerable<CodeIssue> GetIssues (BaseRefactoringContext context) |
|
||||||
{ |
|
||||||
var unit = context.RootNode as SyntaxTree; |
|
||||||
if (unit == null) |
|
||||||
return Enumerable.Empty<CodeIssue> (); |
|
||||||
return GetGatherVisitor(context, unit).GetIssues (); |
|
||||||
} |
|
||||||
|
|
||||||
protected static bool FindUsage (BaseRefactoringContext context, SyntaxTree unit, IVariable variable, |
|
||||||
AstNode declaration) |
|
||||||
{ |
|
||||||
var found = false; |
|
||||||
refFinder.FindLocalReferences (variable, context.UnresolvedFile, unit, context.Compilation, |
|
||||||
(node, resolveResult) => |
|
||||||
{ |
|
||||||
found = found || node != declaration; |
|
||||||
}, context.CancellationToken); |
|
||||||
return found; |
|
||||||
} |
|
||||||
|
|
||||||
internal abstract GatherVisitorBase GetGatherVisitor (BaseRefactoringContext context, SyntaxTree unit); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,154 @@ |
|||||||
|
//
|
||||||
|
// LocalReferenceFinder.cs
|
||||||
|
//
|
||||||
|
// Author:
|
||||||
|
// Simon Lindgren <simon.n.lindgren@gmail.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2012 Simon Lindgren
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
|
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||||
|
using ICSharpCode.NRefactory.Semantics; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using ICSharpCode.NRefactory.Utils; |
||||||
|
using System.Diagnostics; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Refactoring |
||||||
|
{ |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds references to <see cref="IVariable">IVariables</see>.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This class is more efficient than <see cref="FindReferences"/>
|
||||||
|
/// if there is already a resolved tree or if multiple searches needs
|
||||||
|
/// to be performed.
|
||||||
|
/// </remarks>
|
||||||
|
public class LocalReferenceFinder |
||||||
|
{ |
||||||
|
LocalReferenceLocator locator; |
||||||
|
|
||||||
|
MultiDictionary<IVariable, ReferenceResult> references = new MultiDictionary<IVariable, ReferenceResult>(); |
||||||
|
|
||||||
|
HashSet<AstNode> visitedRoots = new HashSet<AstNode>(); |
||||||
|
|
||||||
|
public LocalReferenceFinder(CSharpAstResolver resolver) |
||||||
|
{ |
||||||
|
locator = new LocalReferenceLocator(resolver, this); |
||||||
|
} |
||||||
|
|
||||||
|
public LocalReferenceFinder(BaseRefactoringContext context) : this(context.Resolver) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
void VisitIfNeccessary(AstNode rootNode) |
||||||
|
{ |
||||||
|
// If any of the parent nodes are recorded as visited,
|
||||||
|
// we don't need to traverse rootNode this time.
|
||||||
|
var tmpRoot = rootNode; |
||||||
|
while(tmpRoot != null){ |
||||||
|
if (visitedRoots.Contains(tmpRoot)) |
||||||
|
return; |
||||||
|
tmpRoot = tmpRoot.Parent; |
||||||
|
} |
||||||
|
|
||||||
|
locator.ProccessRoot (rootNode); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the references to <paramref name="variable"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name='rootNode'>
|
||||||
|
/// Root node for the search.
|
||||||
|
/// </param>
|
||||||
|
/// <param name='variable'>
|
||||||
|
/// The variable to find references for.
|
||||||
|
/// </param>
|
||||||
|
/// <remarks>
|
||||||
|
/// When a single <see cref="LocalReferenceFinder"/> is reused for multiple
|
||||||
|
/// searches, which references outside of <paramref name="rootNode"/> are
|
||||||
|
/// or are not reported is undefined.
|
||||||
|
/// </remarks>
|
||||||
|
public IList<ReferenceResult> FindReferences(AstNode rootNode, IVariable variable) |
||||||
|
{ |
||||||
|
lock (locator) { |
||||||
|
VisitIfNeccessary(rootNode); |
||||||
|
var lookup = (ILookup<IVariable, ReferenceResult>)references; |
||||||
|
if (!lookup.Contains(variable)) |
||||||
|
return new List<ReferenceResult>(); |
||||||
|
// Clone the list for thread safety
|
||||||
|
return references[variable].ToList(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class LocalReferenceLocator : DepthFirstAstVisitor |
||||||
|
{ |
||||||
|
CSharpAstResolver resolver; |
||||||
|
|
||||||
|
LocalReferenceFinder referenceFinder; |
||||||
|
|
||||||
|
public LocalReferenceLocator(CSharpAstResolver resolver, LocalReferenceFinder referenceFinder) |
||||||
|
{ |
||||||
|
this.resolver = resolver; |
||||||
|
this.referenceFinder = referenceFinder; |
||||||
|
} |
||||||
|
|
||||||
|
IList<IVariable> processedVariables = new List<IVariable>(); |
||||||
|
|
||||||
|
public void ProccessRoot (AstNode rootNode) |
||||||
|
{ |
||||||
|
rootNode.AcceptVisitor(this); |
||||||
|
referenceFinder.visitedRoots.Add(rootNode); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void VisitChildren(AstNode node) |
||||||
|
{ |
||||||
|
if (referenceFinder.visitedRoots.Contains(node)) |
||||||
|
return; |
||||||
|
var localResolveResult = resolver.Resolve(node) as LocalResolveResult; |
||||||
|
if (localResolveResult != null && !processedVariables.Contains(localResolveResult.Variable)) { |
||||||
|
referenceFinder.references.Add(localResolveResult.Variable, new ReferenceResult(node, localResolveResult)); |
||||||
|
|
||||||
|
processedVariables.Add(localResolveResult.Variable); |
||||||
|
base.VisitChildren(node); |
||||||
|
Debug.Assert(processedVariables.Contains(localResolveResult.Variable), "Variable should still be in the list of processed variables."); |
||||||
|
processedVariables.Remove(localResolveResult.Variable); |
||||||
|
} else { |
||||||
|
base.VisitChildren(node); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class ReferenceResult |
||||||
|
{ |
||||||
|
public ReferenceResult (AstNode node, LocalResolveResult resolveResult) |
||||||
|
{ |
||||||
|
Node = node; |
||||||
|
ResolveResult = resolveResult; |
||||||
|
} |
||||||
|
|
||||||
|
public AstNode Node { get; private set; } |
||||||
|
|
||||||
|
public LocalResolveResult ResolveResult { get; private set; } |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,80 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
// software and associated documentation files (the "Software"), to deal in the Software
|
||||||
|
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||||
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||||
|
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
// substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||||
|
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Linq.Expressions; |
||||||
|
using ICSharpCode.NRefactory.Semantics; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.Resolver |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Represents the result of an await expression.
|
||||||
|
/// </summary>
|
||||||
|
public class AwaitResolveResult : ResolveResult |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The method representing the GetAwaiter() call. Can be null if the GetAwaiter method was not found.
|
||||||
|
/// </summary>
|
||||||
|
public readonly ResolveResult GetAwaiterInvocation; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Awaiter type. Will not be null (but can be UnknownType).
|
||||||
|
/// </summary>
|
||||||
|
public readonly IType AwaiterType; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Property representing the IsCompleted property on the awaiter type. Can be null if the awaiter type or the property was not found, or when awaiting a dynamic expression.
|
||||||
|
/// </summary>
|
||||||
|
public readonly IProperty IsCompletedProperty; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Method representing the OnCompleted method on the awaiter type. Can be null if the awaiter type or the method was not found, or when awaiting a dynamic expression.
|
||||||
|
/// </summary>
|
||||||
|
public readonly IMethod OnCompletedMethod; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Method representing the GetResult method on the awaiter type. Can be null if the awaiter type or the method was not found, or when awaiting a dynamic expression.
|
||||||
|
/// </summary>
|
||||||
|
public readonly IMethod GetResultMethod; |
||||||
|
|
||||||
|
public AwaitResolveResult(IType resultType, ResolveResult getAwaiterInvocation, IType awaiterType, IProperty isCompletedProperty, IMethod onCompletedMethod, IMethod getResultMethod) |
||||||
|
: base(resultType) |
||||||
|
{ |
||||||
|
if (awaiterType == null) |
||||||
|
throw new ArgumentNullException("awaiterType"); |
||||||
|
if (getAwaiterInvocation == null) |
||||||
|
throw new ArgumentNullException("getAwaiterInvocation"); |
||||||
|
this.GetAwaiterInvocation = getAwaiterInvocation; |
||||||
|
this.AwaiterType = awaiterType; |
||||||
|
this.IsCompletedProperty = isCompletedProperty; |
||||||
|
this.OnCompletedMethod = onCompletedMethod; |
||||||
|
this.GetResultMethod = getResultMethod; |
||||||
|
} |
||||||
|
|
||||||
|
public override bool IsError { |
||||||
|
get { return this.GetAwaiterInvocation.IsError || (AwaiterType.Kind != TypeKind.Dynamic && (this.IsCompletedProperty == null || this.OnCompletedMethod == null || this.GetResultMethod == null)); } |
||||||
|
} |
||||||
|
|
||||||
|
public override IEnumerable<ResolveResult> GetChildResults() { |
||||||
|
return new[] { GetAwaiterInvocation }; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,109 @@ |
|||||||
|
using NUnit.Framework; |
||||||
|
using ICSharpCode.NRefactory.CSharp.Refactoring; |
||||||
|
|
||||||
|
namespace ICSharpCode.NRefactory.CSharp.CodeActions |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class SortUsingsTests : ContextActionTestBase |
||||||
|
{ |
||||||
|
[Test] |
||||||
|
public void TestActiveWhenCursorAtUsing() |
||||||
|
{ |
||||||
|
Test<SortUsingsAction>(@"using Sys$tem.Linq;
|
||||||
|
using System;", @"using System; |
||||||
|
using System.Linq;");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestActiveWhenCursorBehindUsing() |
||||||
|
{ |
||||||
|
Test<SortUsingsAction>(@"using System.Linq;$
|
||||||
|
using System;", @"using System; |
||||||
|
using System.Linq;");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestInActiveWhenCursorOutsideUsings() |
||||||
|
{ |
||||||
|
TestWrongContext<SortUsingsAction>(@"using System.Linq;
|
||||||
|
using System; |
||||||
|
$");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestSortsAllUsingBlocksInFile() |
||||||
|
{ |
||||||
|
Test<SortUsingsAction>(@"using $System.Linq;
|
||||||
|
using System; |
||||||
|
|
||||||
|
namespace Foo |
||||||
|
{ |
||||||
|
using System.IO; |
||||||
|
using System.Collections; |
||||||
|
} |
||||||
|
|
||||||
|
namespace Bar |
||||||
|
{ |
||||||
|
using System.IO; |
||||||
|
using System.Runtime; |
||||||
|
using System.Diagnostics; |
||||||
|
}", @"using System; |
||||||
|
using System.Linq; |
||||||
|
|
||||||
|
namespace Foo |
||||||
|
{ |
||||||
|
using System.Collections; |
||||||
|
using System.IO; |
||||||
|
} |
||||||
|
|
||||||
|
namespace Bar |
||||||
|
{ |
||||||
|
using System.Diagnostics; |
||||||
|
using System.IO; |
||||||
|
using System.Runtime; |
||||||
|
}");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestAliasesGoesToTheEnd() |
||||||
|
{ |
||||||
|
Test<SortUsingsAction>(@"$using Sys = System;
|
||||||
|
using System;", @"using System; |
||||||
|
using Sys = System;");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestUnknownNamespacesGoesAfterKnownOnes() |
||||||
|
{ |
||||||
|
Test<SortUsingsAction>(@"$using Foo;
|
||||||
|
using System;", @"using System; |
||||||
|
using Foo;");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestMixedStuff() |
||||||
|
{ |
||||||
|
Test<SortUsingsAction>(@"$using Foo;
|
||||||
|
using System.Linq; |
||||||
|
using Sys = System; |
||||||
|
using System; |
||||||
|
using FooAlias = Foo; |
||||||
|
using Linq = System.Linq;", @"using System; |
||||||
|
using System.Linq; |
||||||
|
using Foo; |
||||||
|
using Linq = System.Linq; |
||||||
|
using Sys = System; |
||||||
|
using FooAlias = Foo;");
|
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestPreservesEmptyLinesWhichIsInFactABug() |
||||||
|
{ |
||||||
|
Test<SortUsingsAction>(@"$using System.Linq;
|
||||||
|
|
||||||
|
using System;", @"using System; |
||||||
|
|
||||||
|
using System.Linq;");
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue