@@ -13,6 +13,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1313 using Microsoft . CodeAnalysis . CSharp . Syntax ;
1414 using Microsoft . CodeAnalysis . Diagnostics ;
1515 using StyleCop . Analyzers . Helpers ;
16+ using StyleCop . Analyzers . Settings . ObjectModel ;
1617
1718 /// <summary>
1819 /// This is the base class for analyzers which examine the <c><summary></c> or <c><content></c> text of
@@ -23,8 +24,8 @@ internal abstract class PartialElementDocumentationSummaryBase : DiagnosticAnaly
2324 private static readonly XElement EmptyElement = new XElement ( "empty" ) ;
2425
2526 private readonly Action < CompilationStartAnalysisContext > compilationStartAction ;
26- private readonly Action < SyntaxNodeAnalysisContext > typeDeclarationAction ;
27- private readonly Action < SyntaxNodeAnalysisContext > methodDeclarationAction ;
27+ private readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > typeDeclarationAction ;
28+ private readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > methodDeclarationAction ;
2829
2930 protected PartialElementDocumentationSummaryBase ( )
3031 {
@@ -46,14 +47,16 @@ public override void Initialize(AnalysisContext context)
4647 /// Analyzes the top-level <c><summary></c> or <c><content></c> element of a documentation comment.
4748 /// </summary>
4849 /// <param name="context">The current analysis context.</param>
50+ /// <param name="needsComment"><see langword="true"/> if the current documentation settings indicate that the
51+ /// element should be documented; otherwise, <see langword="false"/>.</param>
4952 /// <param name="syntax">The <see cref="XmlElementSyntax"/> or <see cref="XmlEmptyElementSyntax"/> of the node
5053 /// to examine.</param>
5154 /// <param name="completeDocumentation">The complete documentation for the declared symbol, with any
5255 /// <c><include></c> elements expanded. If the XML documentation comment included a <c><summary></c>
5356 /// element, this value will be <see langword="null"/>, even if the XML documentation comment also included an
5457 /// <c><include></c> element.</param>
5558 /// <param name="diagnosticLocations">The location(s) where diagnostics, if any, should be reported.</param>
56- protected abstract void HandleXmlElement ( SyntaxNodeAnalysisContext context , XmlNodeSyntax syntax , XElement completeDocumentation , params Location [ ] diagnosticLocations ) ;
59+ protected abstract void HandleXmlElement ( SyntaxNodeAnalysisContext context , bool needsComment , XmlNodeSyntax syntax , XElement completeDocumentation , params Location [ ] diagnosticLocations ) ;
5760
5861 private static bool IsPartialMethodDefinition ( SyntaxNode node )
5962 {
@@ -68,7 +71,7 @@ private static bool IsPartialMethodDefinition(SyntaxNode node)
6871 && ( methodDeclaration . Body == null ) ;
6972 }
7073
71- private void HandleTypeDeclaration ( SyntaxNodeAnalysisContext context )
74+ private void HandleTypeDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
7275 {
7376 // We handle TypeDeclarationSyntax instead of BaseTypeDeclarationSyntax because enums are not allowed to be
7477 // partial.
@@ -84,10 +87,13 @@ private void HandleTypeDeclaration(SyntaxNodeAnalysisContext context)
8487 return ;
8588 }
8689
87- this . HandleDeclaration ( context , node , node . Identifier . GetLocation ( ) ) ;
90+ Accessibility declaredAccessibility = node . GetDeclaredAccessibility ( context . SemanticModel , context . CancellationToken ) ;
91+ Accessibility effectiveAccessibility = node . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
92+ bool needsComment = SA1600ElementsMustBeDocumented . NeedsComment ( settings . DocumentationRules , node . Kind ( ) , node . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) ;
93+ this . HandleDeclaration ( context , needsComment , node , node . Identifier . GetLocation ( ) ) ;
8894 }
8995
90- private void HandleMethodDeclaration ( SyntaxNodeAnalysisContext context )
96+ private void HandleMethodDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
9197 {
9298 var node = ( MethodDeclarationSyntax ) context . Node ;
9399 if ( node . Identifier . IsMissing )
@@ -101,10 +107,13 @@ private void HandleMethodDeclaration(SyntaxNodeAnalysisContext context)
101107 return ;
102108 }
103109
104- this . HandleDeclaration ( context , node , node . Identifier . GetLocation ( ) ) ;
110+ Accessibility declaredAccessibility = node . GetDeclaredAccessibility ( context . SemanticModel , context . CancellationToken ) ;
111+ Accessibility effectiveAccessibility = node . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
112+ bool needsComment = SA1600ElementsMustBeDocumented . NeedsComment ( settings . DocumentationRules , node . Kind ( ) , node . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) ;
113+ this . HandleDeclaration ( context , needsComment , node , node . Identifier . GetLocation ( ) ) ;
105114 }
106115
107- private void HandleDeclaration ( SyntaxNodeAnalysisContext context , SyntaxNode node , params Location [ ] locations )
116+ private void HandleDeclaration ( SyntaxNodeAnalysisContext context , bool needsComment , SyntaxNode node , params Location [ ] locations )
108117 {
109118 var documentation = node . GetDocumentationCommentTriviaSyntax ( ) ;
110119 if ( documentation == null )
@@ -153,7 +162,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, SyntaxNode nod
153162 }
154163 }
155164
156- this . HandleXmlElement ( context , relevantXmlElement , completeDocumentation , locations ) ;
165+ this . HandleXmlElement ( context , needsComment , relevantXmlElement , completeDocumentation , locations ) ;
157166 }
158167
159168 private string ExpandDocumentation ( Compilation compilation , DocumentationCommentTriviaSyntax documentCommentTrivia , XmlNodeSyntax includeTag )
0 commit comments