@@ -5,6 +5,8 @@ namespace StyleCop.Analyzers.DocumentationRules
55{
66 using System ;
77 using System . Collections . Immutable ;
8+ using System . Linq ;
9+ using System . Xml . Linq ;
810 using Helpers ;
911 using Microsoft . CodeAnalysis ;
1012 using Microsoft . CodeAnalysis . CSharp ;
@@ -75,19 +77,55 @@ private static void HandleBaseTypeLikeDeclaration(SyntaxNodeAnalysisContext cont
7577 }
7678
7779 DocumentationCommentTriviaSyntax documentation = context . Node . GetDocumentationCommentTriviaSyntax ( ) ;
78-
79- XmlNodeSyntax inheritDocElement = documentation ? . Content . GetFirstXmlElement ( XmlCommentHelper . InheritdocXmlTag ) ;
80- if ( inheritDocElement == null )
80+ if ( documentation == null )
8181 {
8282 return ;
8383 }
8484
85- if ( HasXmlCrefAttribute ( inheritDocElement ) )
85+ Location location ;
86+
87+ var includeElement = documentation . Content . GetFirstXmlElement ( XmlCommentHelper . IncludeXmlTag ) as XmlEmptyElementSyntax ;
88+ if ( includeElement != null )
8689 {
87- return ;
90+ var declaration = context . SemanticModel . GetDeclaredSymbol ( baseType , context . CancellationToken ) ;
91+ if ( declaration == null )
92+ {
93+ return ;
94+ }
95+
96+ var rawDocumentation = declaration . GetDocumentationCommentXml ( expandIncludes : true , cancellationToken : context . CancellationToken ) ;
97+ var completeDocumentation = XElement . Parse ( rawDocumentation , LoadOptions . None ) ;
98+
99+ var inheritDocElement = completeDocumentation . Nodes ( ) . OfType < XElement > ( ) . FirstOrDefault ( element => element . Name == XmlCommentHelper . InheritdocXmlTag ) ;
100+ if ( inheritDocElement == null )
101+ {
102+ return ;
103+ }
104+
105+ if ( HasXmlCrefAttribute ( inheritDocElement ) )
106+ {
107+ return ;
108+ }
109+
110+ location = includeElement . GetLocation ( ) ;
88111 }
112+ else
113+ {
114+ XmlNodeSyntax inheritDocElement = documentation . Content . GetFirstXmlElement ( XmlCommentHelper . InheritdocXmlTag ) ;
115+ if ( inheritDocElement == null )
116+ {
117+ return ;
118+ }
119+
120+ if ( HasXmlCrefAttribute ( inheritDocElement ) )
121+ {
122+ return ;
123+ }
89124
90- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , inheritDocElement . GetLocation ( ) ) ) ;
125+ location = inheritDocElement . GetLocation ( ) ;
126+ }
127+
128+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , location ) ) ;
91129 }
92130
93131 private static void HandleMemberDeclaration ( SyntaxNodeAnalysisContext context )
@@ -102,17 +140,12 @@ private static void HandleMemberDeclaration(SyntaxNodeAnalysisContext context)
102140 }
103141
104142 DocumentationCommentTriviaSyntax documentation = memberSyntax . GetDocumentationCommentTriviaSyntax ( ) ;
105-
106- XmlNodeSyntax inheritDocElement = documentation ? . Content . GetFirstXmlElement ( XmlCommentHelper . InheritdocXmlTag ) ;
107- if ( inheritDocElement == null )
143+ if ( documentation == null )
108144 {
109145 return ;
110146 }
111147
112- if ( HasXmlCrefAttribute ( inheritDocElement ) )
113- {
114- return ;
115- }
148+ Location location ;
116149
117150 ISymbol declaredSymbol = context . SemanticModel . GetDeclaredSymbol ( memberSyntax , context . CancellationToken ) ;
118151 if ( declaredSymbol == null && memberSyntax . IsKind ( SyntaxKind . EventFieldDeclaration ) )
@@ -125,11 +158,51 @@ private static void HandleMemberDeclaration(SyntaxNodeAnalysisContext context)
125158 }
126159 }
127160
161+ var includeElement = documentation . Content . GetFirstXmlElement ( XmlCommentHelper . IncludeXmlTag ) as XmlEmptyElementSyntax ;
162+ if ( includeElement != null )
163+ {
164+ if ( declaredSymbol == null )
165+ {
166+ return ;
167+ }
168+
169+ var rawDocumentation = declaredSymbol . GetDocumentationCommentXml ( expandIncludes : true , cancellationToken : context . CancellationToken ) ;
170+ var completeDocumentation = XElement . Parse ( rawDocumentation , LoadOptions . None ) ;
171+
172+ var inheritDocElement = completeDocumentation . Nodes ( ) . OfType < XElement > ( ) . FirstOrDefault ( element => element . Name == XmlCommentHelper . InheritdocXmlTag ) ;
173+ if ( inheritDocElement == null )
174+ {
175+ return ;
176+ }
177+
178+ if ( HasXmlCrefAttribute ( inheritDocElement ) )
179+ {
180+ return ;
181+ }
182+
183+ location = includeElement . GetLocation ( ) ;
184+ }
185+ else
186+ {
187+ XmlNodeSyntax inheritDocElement = documentation . Content . GetFirstXmlElement ( XmlCommentHelper . InheritdocXmlTag ) ;
188+ if ( inheritDocElement == null )
189+ {
190+ return ;
191+ }
192+
193+ if ( HasXmlCrefAttribute ( inheritDocElement ) )
194+ {
195+ return ;
196+ }
197+
198+ location = inheritDocElement . GetLocation ( ) ;
199+ }
200+
128201 // If we don't have a declared symbol we have some kind of field declaration. A field can not override or
129202 // implement anything so we want to report a diagnostic.
130203 if ( declaredSymbol == null || ! NamedTypeHelpers . IsImplementingAnInterfaceMember ( declaredSymbol ) )
131204 {
132- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , inheritDocElement . GetLocation ( ) ) ) ;
205+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , location ) ) ;
133206 }
134207 }
135208
@@ -149,5 +222,10 @@ private static bool HasXmlCrefAttribute(XmlNodeSyntax inheritDocElement)
149222
150223 return false ;
151224 }
225+
226+ private static bool HasXmlCrefAttribute ( XElement inheritDocElement )
227+ {
228+ return inheritDocElement . Attribute ( XmlCommentHelper . CrefArgumentName ) != null ;
229+ }
152230 }
153231}
0 commit comments