@@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.DocumentationRules
1212 using Microsoft . CodeAnalysis . CSharp . Syntax ;
1313 using Microsoft . CodeAnalysis . Diagnostics ;
1414 using StyleCop . Analyzers . Helpers ;
15+ using StyleCop . Analyzers . Settings . ObjectModel ;
1516
1617 /// <summary>
1718 /// A generic C# element is missing documentation for one or more of its generic type parameters.
@@ -41,9 +42,9 @@ internal class SA1618GenericTypeParametersMustBeDocumented : DiagnosticAnalyzer
4142 private static readonly DiagnosticDescriptor Descriptor =
4243 new DiagnosticDescriptor ( DiagnosticId , Title , MessageFormat , AnalyzerCategory . DocumentationRules , DiagnosticSeverity . Warning , AnalyzerConstants . EnabledByDefault , Description , HelpLink ) ;
4344
44- private static readonly Action < SyntaxNodeAnalysisContext > TypeDeclarationAction = HandleTypeDeclaration ;
45- private static readonly Action < SyntaxNodeAnalysisContext > MethodDeclarationAction = HandleMethodDeclaration ;
46- private static readonly Action < SyntaxNodeAnalysisContext > DelegateDeclarationAction = HandleDelegateDeclaration ;
45+ private static readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > TypeDeclarationAction = HandleTypeDeclaration ;
46+ private static readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > MethodDeclarationAction = HandleMethodDeclaration ;
47+ private static readonly Action < SyntaxNodeAnalysisContext , StyleCopSettings > DelegateDeclarationAction = HandleDelegateDeclaration ;
4748
4849 /// <inheritdoc/>
4950 public override ImmutableArray < DiagnosticDescriptor > SupportedDiagnostics { get ; } =
@@ -60,7 +61,7 @@ public override void Initialize(AnalysisContext context)
6061 context . RegisterSyntaxNodeAction ( DelegateDeclarationAction , SyntaxKind . DelegateDeclaration ) ;
6162 }
6263
63- private static void HandleTypeDeclaration ( SyntaxNodeAnalysisContext context )
64+ private static void HandleTypeDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
6465 {
6566 TypeDeclarationSyntax typeDeclaration = ( TypeDeclarationSyntax ) context . Node ;
6667
@@ -70,25 +71,40 @@ private static void HandleTypeDeclaration(SyntaxNodeAnalysisContext context)
7071 return ;
7172 }
7273
73- HandleMemberDeclaration ( context , typeDeclaration , typeDeclaration . TypeParameterList ) ;
74+ Accessibility declaredAccessibility = typeDeclaration . GetDeclaredAccessibility ( context . SemanticModel , context . CancellationToken ) ;
75+ Accessibility effectiveAccessibility = typeDeclaration . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
76+ bool needsComment = SA1600ElementsMustBeDocumented . NeedsComment ( settings . DocumentationRules , typeDeclaration . Kind ( ) , typeDeclaration . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) ;
77+ HandleMemberDeclaration ( context , needsComment , typeDeclaration , typeDeclaration . TypeParameterList ) ;
7478 }
7579
76- private static void HandleMethodDeclaration ( SyntaxNodeAnalysisContext context )
80+ private static void HandleMethodDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
7781 {
7882 MethodDeclarationSyntax methodDeclaration = ( MethodDeclarationSyntax ) context . Node ;
7983
80- HandleMemberDeclaration ( context , methodDeclaration , methodDeclaration . TypeParameterList ) ;
84+ Accessibility declaredAccessibility = methodDeclaration . GetDeclaredAccessibility ( context . SemanticModel , context . CancellationToken ) ;
85+ Accessibility effectiveAccessibility = methodDeclaration . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
86+ bool needsComment = SA1600ElementsMustBeDocumented . NeedsComment ( settings . DocumentationRules , methodDeclaration . Kind ( ) , methodDeclaration . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) ;
87+ HandleMemberDeclaration ( context , needsComment , methodDeclaration , methodDeclaration . TypeParameterList ) ;
8188 }
8289
83- private static void HandleDelegateDeclaration ( SyntaxNodeAnalysisContext context )
90+ private static void HandleDelegateDeclaration ( SyntaxNodeAnalysisContext context , StyleCopSettings settings )
8491 {
8592 DelegateDeclarationSyntax delegateDeclaration = ( DelegateDeclarationSyntax ) context . Node ;
8693
87- HandleMemberDeclaration ( context , delegateDeclaration , delegateDeclaration . TypeParameterList ) ;
94+ Accessibility declaredAccessibility = delegateDeclaration . GetDeclaredAccessibility ( context . SemanticModel , context . CancellationToken ) ;
95+ Accessibility effectiveAccessibility = delegateDeclaration . GetEffectiveAccessibility ( context . SemanticModel , context . CancellationToken ) ;
96+ bool needsComment = SA1600ElementsMustBeDocumented . NeedsComment ( settings . DocumentationRules , delegateDeclaration . Kind ( ) , delegateDeclaration . Parent . Kind ( ) , declaredAccessibility , effectiveAccessibility ) ;
97+ HandleMemberDeclaration ( context , needsComment , delegateDeclaration , delegateDeclaration . TypeParameterList ) ;
8898 }
8999
90- private static void HandleMemberDeclaration ( SyntaxNodeAnalysisContext context , SyntaxNode node , TypeParameterListSyntax typeParameterList )
100+ private static void HandleMemberDeclaration ( SyntaxNodeAnalysisContext context , bool needsComment , SyntaxNode node , TypeParameterListSyntax typeParameterList )
91101 {
102+ if ( ! needsComment )
103+ {
104+ // Documentation is not required for this element.
105+ return ;
106+ }
107+
92108 if ( typeParameterList == null )
93109 {
94110 // The member does not have a type parameter list
0 commit comments