@@ -5,7 +5,6 @@ namespace StyleCop.Analyzers.DocumentationRules
55{
66 using System ;
77 using System . Collections . Immutable ;
8- using System . Threading ;
98 using Microsoft . CodeAnalysis ;
109 using Microsoft . CodeAnalysis . CSharp ;
1110 using Microsoft . CodeAnalysis . CSharp . Syntax ;
@@ -54,6 +53,7 @@ internal class SA1602EnumerationItemsMustBeDocumented : DiagnosticAnalyzer
5453 new DiagnosticDescriptor ( DiagnosticId , Title , MessageFormat , AnalyzerCategory . DocumentationRules , DiagnosticSeverity . Warning , AnalyzerConstants . EnabledByDefault , Description , HelpLink ) ;
5554
5655 private static readonly Action < CompilationStartAnalysisContext > CompilationStartAction = HandleCompilationStart ;
56+ private static readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > EnumMemberDeclarationAction = Analyzer . HandleEnumMemberDeclaration ;
5757
5858 /// <inheritdoc/>
5959 public override ImmutableArray < DiagnosticDescriptor > SupportedDiagnostics { get ; } =
@@ -67,21 +67,12 @@ public override void Initialize(AnalysisContext context)
6767
6868 private static void HandleCompilationStart ( CompilationStartAnalysisContext context )
6969 {
70- Analyzer analyzer = new Analyzer ( context . Options , context . CancellationToken ) ;
71- context . RegisterSyntaxNodeActionHonorExclusions ( analyzer . HandleEnumMember , SyntaxKind . EnumMemberDeclaration ) ;
70+ context . RegisterSyntaxNodeActionHonorExclusions ( EnumMemberDeclarationAction , SyntaxKind . EnumMemberDeclaration ) ;
7271 }
7372
74- private class Analyzer
73+ private static class Analyzer
7574 {
76- private readonly DocumentationSettings documentationSettings ;
77-
78- public Analyzer ( AnalyzerOptions options , CancellationToken cancellationToken )
79- {
80- StyleCopSettings settings = options . GetStyleCopSettings ( cancellationToken ) ;
81- this . documentationSettings = settings . DocumentationRules ;
82- }
83-
84- public void HandleEnumMember ( SyntaxNodeAnalysisContext context )
75+ public static void HandleEnumMemberDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
8576 {
8677 if ( context . GetDocumentationMode ( ) != DocumentationMode . Diagnose )
8778 {
@@ -91,7 +82,7 @@ public void HandleEnumMember(SyntaxNodeAnalysisContext context)
9182 EnumMemberDeclarationSyntax declaration = ( EnumMemberDeclarationSyntax ) context . Node ;
9283 Accessibility declaredAccessibility = declaration . GetDeclaredAccessibility ( ) ;
9384 Accessibility effectiveAccessibility = declaration . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
94- if ( this . NeedsComment ( declaration . Kind ( ) , declaration . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) )
85+ if ( NeedsComment ( settings . DocumentationRules , declaration . Kind ( ) , declaration . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) )
9586 {
9687 if ( ! XmlCommentHelper . HasDocumentation ( declaration ) )
9788 {
@@ -100,16 +91,16 @@ public void HandleEnumMember(SyntaxNodeAnalysisContext context)
10091 }
10192 }
10293
103- private bool NeedsComment ( SyntaxKind syntaxKind , SyntaxKind parentSyntaxKind , Accessibility declaredAccessibility , Accessibility effectiveAccessibility )
94+ private static bool NeedsComment ( DocumentationSettings documentationSettings , SyntaxKind syntaxKind , SyntaxKind parentSyntaxKind , Accessibility declaredAccessibility , Accessibility effectiveAccessibility )
10495 {
105- if ( this . documentationSettings . DocumentInterfaces
96+ if ( documentationSettings . DocumentInterfaces
10697 && ( syntaxKind == SyntaxKind . InterfaceDeclaration || parentSyntaxKind == SyntaxKind . InterfaceDeclaration ) )
10798 {
10899 // DocumentInterfaces => all interfaces must be documented
109100 return true ;
110101 }
111102
112- if ( this . documentationSettings . DocumentPrivateElements )
103+ if ( documentationSettings . DocumentPrivateElements )
113104 {
114105 // DocumentPrivateMembers => everything except declared private fields must be documented
115106 return true ;
@@ -121,12 +112,12 @@ private bool NeedsComment(SyntaxKind syntaxKind, SyntaxKind parentSyntaxKind, Ac
121112 case Accessibility . Protected :
122113 case Accessibility . ProtectedOrInternal :
123114 // These items are part of the exposed API surface => document if configured
124- return this . documentationSettings . DocumentExposedElements ;
115+ return documentationSettings . DocumentExposedElements ;
125116
126117 case Accessibility . ProtectedAndInternal :
127118 case Accessibility . Internal :
128119 // These items are part of the internal API surface => document if configured
129- return this . documentationSettings . DocumentInternalElements ;
120+ return documentationSettings . DocumentInternalElements ;
130121
131122 case Accessibility . NotApplicable :
132123 case Accessibility . Private :
0 commit comments