11using System ;
2+ using System . Collections . Generic ;
23using System . Collections . Immutable ;
34using System . Composition ;
45using System . Linq ;
6+ using System . Runtime . Remoting . Contexts ;
57using System . Threading ;
68using System . Threading . Tasks ;
79using CodeDocumentor . Helper ;
1113using Microsoft . CodeAnalysis . CodeFixes ;
1214using Microsoft . CodeAnalysis . CSharp ;
1315using Microsoft . CodeAnalysis . CSharp . Syntax ;
16+ using Microsoft . VisualStudio . Package ;
1417
1518namespace CodeDocumentor
1619{
20+
1721 /// <summary>
1822 /// The class code fix provider.
1923 /// </summary>
@@ -23,7 +27,7 @@ public class ClassCodeFixProvider : CodeFixProvider
2327 /// <summary>
2428 /// The title.
2529 /// </summary>
26- private const string title = "Add documentation header to this class" ;
30+ private const string title = "Code Documentor this class" ;
2731
2832 /// <summary>
2933 /// Gets the fixable diagnostic ids.
@@ -66,6 +70,33 @@ public override sealed async Task RegisterCodeFixesAsync(CodeFixContext context)
6670 diagnostic ) ;
6771 }
6872
73+
74+ /// <summary>
75+ /// Builds the headers.
76+ /// </summary>
77+ /// <param name="root">The root.</param>
78+ /// <param name="nodesToReplace">The nodes to replace.</param>
79+ internal static void BuildComments ( SyntaxNode root , Dictionary < CSharpSyntaxNode , CSharpSyntaxNode > nodesToReplace )
80+ {
81+ var declarations = root . DescendantNodes ( ) . Where ( w => w . IsKind ( SyntaxKind . ClassDeclaration ) ) . OfType < ClassDeclarationSyntax > ( ) . ToArray ( ) ;
82+
83+ foreach ( var declarationSyntax in declarations )
84+ {
85+ if ( CodeDocumentorPackage . Options ? . IsEnabledForPublishMembersOnly == true
86+ && PrivateMemberVerifier . IsPrivateMember ( declarationSyntax ) )
87+ {
88+ continue ;
89+ }
90+
91+ if ( declarationSyntax . HasSummary ( ) )
92+ {
93+ continue ;
94+ }
95+ var newDeclaration = BuildNewDeclaration ( declarationSyntax ) ;
96+ nodesToReplace . TryAdd ( declarationSyntax , newDeclaration ) ;
97+ }
98+ }
99+
69100 /// <summary>
70101 /// Adds documentation header async.
71102 /// </summary>
@@ -74,7 +105,15 @@ public override sealed async Task RegisterCodeFixesAsync(CodeFixContext context)
74105 /// <param name="declarationSyntax"> The declaration syntax. </param>
75106 /// <param name="cancellationToken"> The cancellation token. </param>
76107 /// <returns> A Document. </returns>
77- private async Task < Document > AddDocumentationHeaderAsync ( Document document , SyntaxNode root , ClassDeclarationSyntax declarationSyntax , CancellationToken cancellationToken )
108+ internal static async Task < Document > AddDocumentationHeaderAsync ( Document document , SyntaxNode root , ClassDeclarationSyntax declarationSyntax , CancellationToken cancellationToken )
109+ {
110+ var newDeclaration = BuildNewDeclaration ( declarationSyntax ) ;
111+ SyntaxNode newRoot = root . ReplaceNode ( declarationSyntax , newDeclaration ) ;
112+
113+ return document . WithSyntaxRoot ( newRoot ) ;
114+ }
115+
116+ private static ClassDeclarationSyntax BuildNewDeclaration ( ClassDeclarationSyntax declarationSyntax )
78117 {
79118 SyntaxList < SyntaxNode > list = SyntaxFactory . List < SyntaxNode > ( ) ;
80119
@@ -96,9 +135,7 @@ private async Task<Document> AddDocumentationHeaderAsync(Document document, Synt
96135
97136 var newLeadingTrivia = DocumentationHeaderHelper . BuildLeadingTrivia ( leadingTrivia , commentTrivia ) ;
98137 ClassDeclarationSyntax newDeclaration = declarationSyntax . WithLeadingTrivia ( newLeadingTrivia ) ;
99- SyntaxNode newRoot = root . ReplaceNode ( declarationSyntax , newDeclaration ) ;
100-
101- return document . WithSyntaxRoot ( newRoot ) ;
138+ return newDeclaration ;
102139 }
103140 }
104141}
0 commit comments