Browse Source

Implemented resharper disableing for redundant using directive.

pull/32/merge
Mike Krüger 13 years ago
parent
commit
1d5c85f3f1
  1. 2
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/GatherVisitorBase.cs
  2. 6
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/RedundantUsingIssue.cs
  3. 17
      ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantUsingInspectorTests.cs

2
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/GatherVisitorBase.cs

@ -159,7 +159,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -159,7 +159,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
bool IsSuppressed(TextLocation location)
protected bool IsSuppressed(TextLocation location)
{
return isDisabled || isGloballySuppressed || suppressedRegions.Any(r => r.IsInside(location));
}

6
ICSharpCode.NRefactory.CSharp/Refactoring/CodeIssues/RedundantUsingIssue.cs

@ -41,7 +41,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -41,7 +41,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
Description = "Removes used declarations that are not required.",
Category = IssueCategories.Redundancies,
Severity = Severity.Hint,
IssueMarker = IssueMarker.GrayOut)]
IssueMarker = IssueMarker.GrayOut,
ResharperDisableKeyword = "RedundantUsingDirective"
)]
public class RedundantUsingIssue : ICodeIssueProvider
{
List<string> namespacesToKeep = new List<string>();
@ -87,6 +89,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -87,6 +89,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
public override void VisitUsingDeclaration(UsingDeclaration usingDeclaration)
{
base.VisitUsingDeclaration(usingDeclaration);
if (IsSuppressed(usingDeclaration.StartLocation))
return;
var nrr = ctx.Resolve(usingDeclaration.Import) as NamespaceResolveResult;
if (nrr != null) {
isInUse[usingDeclaration] = IssueProvider.namespacesToKeep.Contains(nrr.NamespaceName);

17
ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/RedundantUsingInspectorTests.cs

@ -135,5 +135,22 @@ class Bar @@ -135,5 +135,22 @@ class Bar
var issues = GetIssues (new RedundantUsingIssue (), input, out context);
Assert.AreEqual (0, issues.Count);
}
[Test]
public void TestResharperDisableRestore ()
{
var input = @"// ReSharper disable RedundantUsingDirective
using System;
// ReSharper restore RedundantUsingDirective
using System.IO;
class Foo
{
}";
TestRefactoringContext context;
var issues = GetIssues (new RedundantUsingIssue (), input, out context);
Assert.AreEqual (1, issues.Count);
}
}
}

Loading…
Cancel
Save