@@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1111 using Microsoft . CodeAnalysis . CSharp . Syntax ;
1212 using Microsoft . CodeAnalysis . Diagnostics ;
1313 using StyleCop . Analyzers . Helpers ;
14+ using StyleCop . Analyzers . Settings . ObjectModel ;
1415
1516 /// <summary>
1617 /// This is the base class for analyzers which examine the <c><value></c> text of a documentation comment on a property declaration.
@@ -22,7 +23,7 @@ internal abstract class PropertyDocumentationBase : DiagnosticAnalyzer
2223 /// </summary>
2324 internal const string NoCodeFixKey = "NoCodeFix" ;
2425
25- private readonly Action < SyntaxNodeAnalysisContext > propertyDeclarationAction ;
26+ private readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > propertyDeclarationAction ;
2627
2728 protected PropertyDocumentationBase ( )
2829 {
@@ -48,27 +49,32 @@ public override void Initialize(AnalysisContext context)
4849 /// Analyzes the top-level <c><summary></c> element of a documentation comment.
4950 /// </summary>
5051 /// <param name="context">The current analysis context.</param>
52+ /// <param name="needsComment"><see langword="true"/> if the current documentation settings indicate that the
53+ /// element should be documented; otherwise, <see langword="false"/>.</param>
5154 /// <param name="syntax">The <see cref="XmlElementSyntax"/> or <see cref="XmlEmptyElementSyntax"/> of the node
5255 /// to examine.</param>
5356 /// <param name="completeDocumentation">The complete documentation for the declared symbol, with any
5457 /// <c><include></c> elements expanded. If the XML documentation comment included a <c><summary></c>
5558 /// element, this value will be <see langword="null"/>, even if the XML documentation comment also included an
5659 /// <c><include></c> element.</param>
5760 /// <param name="diagnosticLocation">The location where diagnostics, if any, should be reported.</param>
58- protected abstract void HandleXmlElement ( SyntaxNodeAnalysisContext context , XmlNodeSyntax syntax , XElement completeDocumentation , Location diagnosticLocation ) ;
61+ protected abstract void HandleXmlElement ( SyntaxNodeAnalysisContext context , bool needsComment , XmlNodeSyntax syntax , XElement completeDocumentation , Location diagnosticLocation ) ;
5962
60- private void HandlePropertyDeclaration ( SyntaxNodeAnalysisContext context )
63+ private void HandlePropertyDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
6164 {
6265 var node = ( PropertyDeclarationSyntax ) context . Node ;
6366 if ( node . Identifier . IsMissing )
6467 {
6568 return ;
6669 }
6770
68- this . HandleDeclaration ( context , node , node . Identifier . GetLocation ( ) ) ;
71+ Accessibility declaredAccessibility = node . GetDeclaredAccessibility ( context . SemanticModel , context . CancellationToken ) ;
72+ Accessibility effectiveAccessibility = node . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
73+ bool needsComment = SA1600ElementsMustBeDocumented . NeedsComment ( settings . DocumentationRules , node . Kind ( ) , node . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) ;
74+ this . HandleDeclaration ( context , needsComment , node , node . Identifier . GetLocation ( ) ) ;
6975 }
7076
71- private void HandleDeclaration ( SyntaxNodeAnalysisContext context , SyntaxNode node , Location location )
77+ private void HandleDeclaration ( SyntaxNodeAnalysisContext context , bool needsComment , SyntaxNode node , Location location )
7278 {
7379 var documentation = node . GetDocumentationCommentTriviaSyntax ( ) ;
7480 if ( documentation == null )
@@ -102,7 +108,7 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, SyntaxNode nod
102108 }
103109 }
104110
105- this . HandleXmlElement ( context , relevantXmlElement , completeDocumentation , location ) ;
111+ this . HandleXmlElement ( context , needsComment , relevantXmlElement , completeDocumentation , location ) ;
106112 }
107113 }
108114}
0 commit comments