@@ -6,7 +6,6 @@ namespace StyleCop.Analyzers.DocumentationRules
66 using System ;
77 using System . Collections . Immutable ;
88 using System . Linq ;
9- using System . Threading ;
109 using Microsoft . CodeAnalysis ;
1110 using Microsoft . CodeAnalysis . CSharp ;
1211 using Microsoft . CodeAnalysis . CSharp . Syntax ;
@@ -87,6 +86,8 @@ internal class SA1601PartialElementsMustBeDocumented : DiagnosticAnalyzer
8786 ImmutableArray . Create ( SyntaxKind . ClassDeclaration , SyntaxKind . StructDeclaration , SyntaxKind . InterfaceDeclaration ) ;
8887
8988 private static readonly Action < CompilationStartAnalysisContext > CompilationStartAction = HandleCompilationStart ;
89+ private static readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > BaseTypeDeclarationAction = Analyzer . HandleBaseTypeDeclaration ;
90+ private static readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > MethodDeclarationAction = Analyzer . HandleMethodDeclaration ;
9091
9192 /// <inheritdoc/>
9293 public override ImmutableArray < DiagnosticDescriptor > SupportedDiagnostics { get ; } =
@@ -100,22 +101,13 @@ public override void Initialize(AnalysisContext context)
100101
101102 private static void HandleCompilationStart ( CompilationStartAnalysisContext context )
102103 {
103- Analyzer analyzer = new Analyzer ( context . Options , context . CancellationToken ) ;
104- context . RegisterSyntaxNodeActionHonorExclusions ( analyzer . HandleBaseTypeDeclaration , BaseTypeDeclarationKinds ) ;
105- context . RegisterSyntaxNodeActionHonorExclusions ( analyzer . HandleMethodDeclaration , SyntaxKind . MethodDeclaration ) ;
104+ context . RegisterSyntaxNodeActionHonorExclusions ( BaseTypeDeclarationAction , BaseTypeDeclarationKinds ) ;
105+ context . RegisterSyntaxNodeActionHonorExclusions ( MethodDeclarationAction , SyntaxKind . MethodDeclaration ) ;
106106 }
107107
108- private class Analyzer
108+ private static class Analyzer
109109 {
110- private readonly DocumentationSettings documentationSettings ;
111-
112- public Analyzer ( AnalyzerOptions options , CancellationToken cancellationToken )
113- {
114- StyleCopSettings settings = options . GetStyleCopSettings ( cancellationToken ) ;
115- this . documentationSettings = settings . DocumentationRules ;
116- }
117-
118- public void HandleBaseTypeDeclaration ( SyntaxNodeAnalysisContext context )
110+ public static void HandleBaseTypeDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
119111 {
120112 if ( context . GetDocumentationMode ( ) != DocumentationMode . Diagnose )
121113 {
@@ -130,7 +122,7 @@ public void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context)
130122
131123 Accessibility declaredAccessibility = declaration . GetDeclaredAccessibility ( context . SemanticModel , context . CancellationToken ) ;
132124 Accessibility effectiveAccessibility = declaration . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
133- if ( this . NeedsComment ( declaration . Kind ( ) , declaration . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) )
125+ if ( NeedsComment ( settings . DocumentationRules , declaration . Kind ( ) , declaration . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) )
134126 {
135127 if ( ! XmlCommentHelper . HasDocumentation ( declaration ) )
136128 {
@@ -139,7 +131,7 @@ public void HandleBaseTypeDeclaration(SyntaxNodeAnalysisContext context)
139131 }
140132 }
141133
142- public void HandleMethodDeclaration ( SyntaxNodeAnalysisContext context )
134+ public static void HandleMethodDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
143135 {
144136 if ( context . GetDocumentationMode ( ) != DocumentationMode . Diagnose )
145137 {
@@ -154,7 +146,7 @@ public void HandleMethodDeclaration(SyntaxNodeAnalysisContext context)
154146
155147 Accessibility declaredAccessibility = declaration . GetDeclaredAccessibility ( context . SemanticModel , context . CancellationToken ) ;
156148 Accessibility effectiveAccessibility = declaration . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
157- if ( this . NeedsComment ( declaration . Kind ( ) , declaration . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) )
149+ if ( NeedsComment ( settings . DocumentationRules , declaration . Kind ( ) , declaration . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) )
158150 {
159151 if ( ! XmlCommentHelper . HasDocumentation ( declaration ) )
160152 {
@@ -163,16 +155,16 @@ public void HandleMethodDeclaration(SyntaxNodeAnalysisContext context)
163155 }
164156 }
165157
166- private bool NeedsComment ( SyntaxKind syntaxKind , SyntaxKind parentSyntaxKind , Accessibility declaredAccessibility , Accessibility effectiveAccessibility )
158+ private static bool NeedsComment ( DocumentationSettings documentationSettings , SyntaxKind syntaxKind , SyntaxKind parentSyntaxKind , Accessibility declaredAccessibility , Accessibility effectiveAccessibility )
167159 {
168- if ( this . documentationSettings . DocumentInterfaces
160+ if ( documentationSettings . DocumentInterfaces
169161 && ( syntaxKind == SyntaxKind . InterfaceDeclaration || parentSyntaxKind == SyntaxKind . InterfaceDeclaration ) )
170162 {
171163 // DocumentInterfaces => all interfaces must be documented
172164 return true ;
173165 }
174166
175- if ( this . documentationSettings . DocumentPrivateElements )
167+ if ( documentationSettings . DocumentPrivateElements )
176168 {
177169 // DocumentPrivateMembers => everything except declared private fields must be documented
178170 return true ;
@@ -184,12 +176,12 @@ private bool NeedsComment(SyntaxKind syntaxKind, SyntaxKind parentSyntaxKind, Ac
184176 case Accessibility . Protected :
185177 case Accessibility . ProtectedOrInternal :
186178 // These items are part of the exposed API surface => document if configured
187- return this . documentationSettings . DocumentExposedElements ;
179+ return documentationSettings . DocumentExposedElements ;
188180
189181 case Accessibility . ProtectedAndInternal :
190182 case Accessibility . Internal :
191183 // These items are part of the internal API surface => document if configured
192- return this . documentationSettings . DocumentInternalElements ;
184+ return documentationSettings . DocumentInternalElements ;
193185
194186 case Accessibility . NotApplicable :
195187 case Accessibility . Private :
0 commit comments