Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
[CodeIssues] Don't warn for unused parameters on overrides and interf…
Browse files Browse the repository at this point in the history
…ace implementations.
  • Loading branch information
riviti committed Sep 9, 2012
1 parent f829d58 commit 3b5e573
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Expand Up @@ -25,6 +25,8 @@
// THE SOFTWARE.

using ICSharpCode.NRefactory.Semantics;
using System.Linq;
using ICSharpCode.NRefactory.TypeSystem;

namespace ICSharpCode.NRefactory.CSharp.Refactoring
{
Expand All @@ -51,6 +53,24 @@ public GatherVisitor (BaseRefactoringContext ctx, SyntaxTree unit)
this.unit = unit;
}

public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)
{
// Only some methods are candidates for the warning

if (methodDeclaration.Body.IsNull)
return;
var methodResolveResult = ctx.Resolve(methodDeclaration) as MemberResolveResult;
if (methodResolveResult == null)
return;
var member = methodResolveResult.Member;
if (member.IsOverride)
return;
if (member.ImplementedInterfaceMembers.Any ())
return;

base.VisitMethodDeclaration(methodDeclaration);
}

public override void VisitParameterDeclaration (ParameterDeclaration parameterDeclaration)
{
base.VisitParameterDeclaration (parameterDeclaration);
Expand Down
Expand Up @@ -43,6 +43,36 @@ void TestMethod (int i)
}";
Test<ParameterNotUsedIssue> (input, 1);
}

[Test]
public void TestInterfaceImplementation ()
{
var input = @"
interface ITestClass {
void TestMethod (int i);
}
class TestClass : ITestClass {
public void TestMethod (int i)
{
}
}";
Test<ParameterNotUsedIssue> (input, 0);
}

[Test]
public void TestAbstractMethodImplementation ()
{
var input = @"
abstract class TestBase {
public abstract void TestMethod (int i);
}
class TestClass : TestBase {
public override void TestMethod (int i)
{
}
}";
Test<ParameterNotUsedIssue> (input, 0);
}

[Test]
public void TestUsedParameter ()
Expand Down

0 comments on commit 3b5e573

Please sign in to comment.