@@ -89,16 +89,40 @@ public SA1625ElementDocumentationMustNotBeCopiedAndPasted()
8989 /// <inheritdoc/>
9090 protected override void HandleXmlElement ( SyntaxNodeAnalysisContext context , IEnumerable < XmlNodeSyntax > syntaxList , params Location [ ] diagnosticLocations )
9191 {
92- var comments = syntaxList . Select (
93- x => new Tuple < string , Location > ( XmlCommentHelper . GetText ( x , true ) ? . Trim ( ) , x . GetLocation ( ) ) ) ;
92+ var objectPool = SharedPools . Default < HashSet < string > > ( ) ;
93+ HashSet < string > documentationTexts = objectPool . Allocate ( ) ;
94+
95+ foreach ( var documentationSyntax in syntaxList )
96+ {
97+ var documentation = XmlCommentHelper . GetText ( documentationSyntax , true ) ? . Trim ( ) ;
98+
99+ if ( ShouldSkipElement ( documentation ) )
100+ {
101+ continue ;
102+ }
94103
95- ReportDuplicates ( context , comments ) ;
104+ if ( documentationTexts . Contains ( documentation ) )
105+ {
106+ // Add violation
107+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , documentationSyntax . GetLocation ( ) ) ) ;
108+ }
109+ else
110+ {
111+ documentationTexts . Add ( documentation ) ;
112+ }
113+ }
114+
115+ objectPool . ClearAndFree ( documentationTexts ) ;
96116 }
97117
98118 /// <inheritdoc/>
99119 protected override void HandleCompleteDocumentation ( SyntaxNodeAnalysisContext context , XElement completeDocumentation , params Location [ ] diagnosticLocations )
100120 {
101- var includedComments = completeDocumentation . Nodes ( )
121+ var objectPool = SharedPools . Default < HashSet < string > > ( ) ;
122+ HashSet < string > documentationTexts = objectPool . Allocate ( ) ;
123+
124+ // Concatenate all XML node values
125+ var documentationElements = completeDocumentation . Nodes ( )
102126 . OfType < XElement > ( )
103127 . Select ( x =>
104128 {
@@ -112,36 +136,33 @@ protected override void HandleCompleteDocumentation(SyntaxNodeAnalysisContext co
112136 var elementValue = builder . ToString ( ) ;
113137 StringBuilderPool . ReturnAndFree ( builder ) ;
114138
115- return new Tuple < string , Location > ( elementValue , diagnosticLocations . First ( ) ) ;
139+ return elementValue ;
116140 } ) ;
117141
118- ReportDuplicates ( context , includedComments ) ;
119- }
120-
121- private static void ReportDuplicates ( SyntaxNodeAnalysisContext context , IEnumerable < Tuple < string , Location > > comments )
122- {
123- var objectPool = SharedPools . Default < HashSet < string > > ( ) ;
124- HashSet < string > documentationTexts = objectPool . Allocate ( ) ;
125-
126- foreach ( var comment in comments )
142+ foreach ( var documentation in documentationElements )
127143 {
128- if ( string . IsNullOrWhiteSpace ( comment . Item1 ) || string . Equals ( comment . Item1 , ParameterNotUsed , StringComparison . Ordinal ) )
144+ if ( ShouldSkipElement ( documentation ) )
129145 {
130146 continue ;
131147 }
132148
133- if ( documentationTexts . Contains ( comment . Item1 ) )
149+ if ( documentationTexts . Contains ( documentation ) )
134150 {
135151 // Add violation
136- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , comment . Item2 ) ) ;
152+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , diagnosticLocations . First ( ) ) ) ;
137153 }
138154 else
139155 {
140- documentationTexts . Add ( comment . Item1 ) ;
156+ documentationTexts . Add ( documentation ) ;
141157 }
142158 }
143159
144160 objectPool . ClearAndFree ( documentationTexts ) ;
145161 }
162+
163+ private static bool ShouldSkipElement ( string element )
164+ {
165+ return string . IsNullOrWhiteSpace ( element ) || string . Equals ( element , ParameterNotUsed , StringComparison . Ordinal ) ;
166+ }
146167 }
147168}
0 commit comments