From db8f554a7b8fdb0108c8965f1a7fc2c42da6a07c Mon Sep 17 00:00:00 2001 From: John Venable Date: Mon, 17 Aug 2015 09:00:49 -0400 Subject: [PATCH] fix SA1024 incorrectly treating explicit interface implementations as private --- .../OrderingRules/SA1202UnitTests.cs | 26 +++++++++++++++++++ .../OrderingRules/SA1204UnitTests.cs | 24 +++++++++++++++++ ...lementsMustAppearBeforeInstanceElements.cs | 5 +++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1202UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1202UnitTests.cs index 3a2aa4f07..dbc8d44d7 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1202UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1202UnitTests.cs @@ -607,6 +607,32 @@ void IA.TestMethod1() { } await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); } + [Fact] + public async Task TestExplicitInterfaceFollowedByPrivateStaticAsync() + { + var testCode = @" +public interface TestInterface +{ + void SomeMethod(); +} + +public class TestClass : TestInterface +{ + private static void ExampleMethod() + { + } + + void TestInterface.SomeMethod() + { + } +} +"; + + var expected = this.CSharpDiagnostic().WithLocation(13, 24).WithArguments("public", "methods", "private"); + + await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); + } + /// /// Verifies that the analyzer will properly handle incomplete members. /// diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1204UnitTests.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1204UnitTests.cs index 0ac5536e5..e012c949f 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1204UnitTests.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/OrderingRules/SA1204UnitTests.cs @@ -351,6 +351,30 @@ public MyClass2() await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false); } + [Fact] + public async Task TestExplicitInterfaceFollowedByPrivateStaticAsync() + { + var testCode = @" +public interface TestInterface +{ + void SomeMethod(); +} + +public class TestClass : TestInterface +{ + void TestInterface.SomeMethod() + { + } + + private static void ExampleMethod() + { + } +} +"; + + await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); + } + /// /// Verifies that the analyzer will properly incomplete members. /// diff --git a/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1204StaticElementsMustAppearBeforeInstanceElements.cs b/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1204StaticElementsMustAppearBeforeInstanceElements.cs index 574fa961d..fdea7b644 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1204StaticElementsMustAppearBeforeInstanceElements.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers/OrderingRules/SA1204StaticElementsMustAppearBeforeInstanceElements.cs @@ -104,7 +104,10 @@ private static void HandleMemberList(SyntaxNodeAnalysisContext context, SyntaxLi var currentMemberStatic = modifiers.Any(SyntaxKind.StaticKeyword); var currentMemberConst = modifiers.Any(SyntaxKind.ConstKeyword); AccessLevel currentAccessLevel; - if (currentMemberStatic && currentSyntaxKind == SyntaxKind.ConstructorDeclaration) + if ((currentSyntaxKind == SyntaxKind.ConstructorDeclaration && modifiers.Any(SyntaxKind.StaticKeyword)) + || (currentSyntaxKind == SyntaxKind.MethodDeclaration && (member as MethodDeclarationSyntax)?.ExplicitInterfaceSpecifier != null) + || (currentSyntaxKind == SyntaxKind.PropertyDeclaration && (member as PropertyDeclarationSyntax)?.ExplicitInterfaceSpecifier != null) + || (currentSyntaxKind == SyntaxKind.IndexerDeclaration && (member as IndexerDeclarationSyntax)?.ExplicitInterfaceSpecifier != null)) { currentAccessLevel = AccessLevel.Public; }