/// <summary>
        /// Adds documentation header async.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="root">The root.</param>
        /// <param name="declarationSyntax">The declaration syntax.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A Document.</returns>
        private async Task <Document> AddDocumentationHeaderAsync(Document document, SyntaxNode root, EnumDeclarationSyntax declarationSyntax, CancellationToken cancellationToken)
        {
            SyntaxTriviaList leadingTrivia = declarationSyntax.GetLeadingTrivia();

            string comment = CommentHelper.CreateEnumComment(declarationSyntax.Identifier.ValueText);
            DocumentationCommentTriviaSyntax commentTrivia = await Task.Run(() => DocumentationHeaderHelper.CreateOnlySummaryDocumentationCommentTrivia(comment), cancellationToken);

            SyntaxTriviaList      newLeadingTrivia = leadingTrivia.Insert(leadingTrivia.Count - 1, SyntaxFactory.Trivia(commentTrivia));
            EnumDeclarationSyntax newDeclaration   = declarationSyntax.WithLeadingTrivia(newLeadingTrivia);

            SyntaxNode newRoot = root.ReplaceNode(declarationSyntax, newDeclaration);

            return(document.WithSyntaxRoot(newRoot));
        }
        public CSharpSyntaxNode Convert(EnumDeclaration node)
        {
            EnumDeclarationSyntax csEnum = SyntaxFactory.EnumDeclaration(node.Name.Text);

            csEnum = csEnum.AddModifiers(node.Modifiers.ToCsNodes <SyntaxToken>());
            csEnum = csEnum.AddMembers(node.Members.ToCsNodes <EnumMemberDeclarationSyntax>());

            if (node.JsDoc.Count > 0)
            {
                csEnum = csEnum.WithLeadingTrivia(SyntaxFactory.Trivia(node.JsDoc[0].ToCsNode <DocumentationCommentTriviaSyntax>()));
            }

            return(csEnum);
        }
Esempio n. 3
0
        public static EnumDeclarationSyntax Apply(EnumDeclarationSyntax node, Func <EnumDeclarationSyntax, SyntaxTrivia, EnumDeclarationSyntax> builder)
        {
            var leadingTrivia  = node.GetLeadingTrivia();
            var trailingTrivia = node.GetTrailingTrivia();

            node = node.WithoutLeadingTrivia();
            node = node.WithoutTrailingTrivia();

            var wp = leadingTrivia.FirstOrDefault(w => w.Kind() == SyntaxKind.WhitespaceTrivia);

            node = builder?.Invoke(node, wp);

            node = node.WithLeadingTrivia(leadingTrivia);

            node = node.WithTrailingTrivia(trailingTrivia);

            return(node);
        }
Esempio n. 4
0
        public override SyntaxNode VisitEnumDeclaration(EnumDeclarationSyntax node)
        {
            if (node.AttributeLists.Count > 0)
            {
                var newAttributeLists = new SyntaxList <AttributeListSyntax>();
                foreach (var attributeList in node.AttributeLists)
                {
                    var nodesToRemove = attributeList.Attributes.Where(attribute => NodeHelper.AttributeNameMatches(attribute, Constants.Proto.BASE_PROP_NAME)).ToArray();

                    // If the lists are the same length, we are removing all attributes and can just avoid populating newAttributes.
                    if (nodesToRemove.Length != attributeList.Attributes.Count)
                    {
                        var newAttribute = (AttributeListSyntax)VisitAttributeList(attributeList.RemoveNodes(nodesToRemove, SyntaxRemoveOptions.KeepNoTrivia));
                        newAttributeLists = newAttributeLists.Add(newAttribute);
                    }
                }
                var leadTriv = node.GetLeadingTrivia();
                node = node.WithAttributeLists(newAttributeLists);
                node = node.WithLeadingTrivia(leadTriv);
            }
            return(base.VisitEnumDeclaration(node));
        }
        private EnumDeclarationSyntax AddEnumDocs(EnumDeclarationSyntax enumNode, string summaryText, Dictionary <string, string> memberDocs)
        {
            if (!summaryText.EndsWith('.'))
            {
                summaryText += ".";
            }
            var xmlPad            = XmlText(" ");
            var xmlNewLine        = XmlNewLine("\r\n");
            var xmlNewLineNoTrail = XmlText(XmlTextNewLine("\r\n", false));
            var seeTag            = XmlName("see");
            var docs = new XmlNodeSyntax[]
            {
                xmlPad,
                XmlSummaryElement(
                    xmlNewLine,
                    xmlPad,
                    XmlText(summaryText),
                    xmlNewLine,
                    xmlPad
                    ),
                xmlNewLine,
                xmlPad,
                XmlRemarksElement(
                    XmlText($"Autogenerated from "),
                    XmlSeeHrefElement(_url, $"{enumNode.Identifier.ValueText} docs"),
                    XmlText($".")
                    ),
                xmlNewLineNoTrail
            };

            XmlElementEndTag(seeTag);

            var nodes = enumNode.Members.Select(member => AddEnumMemberDocs(member, memberDocs[member.Identifier.ValueText]));

            enumNode = enumNode.WithMembers(SeparatedList(nodes));
            return(enumNode.WithLeadingTrivia(Trivia(DocumentationComment(docs))));
        }