public static T AddDocumentationComments <T>(this T member, CppComment comments, string nativeName) where T : MemberDeclarationSyntax { var paragraphs = ProcessComments(comments, nativeName); var comment = Trivia( DocumentationCommentTrivia(SyntaxKind.SingleLineDocumentationCommentTrivia) .AddContent( XmlNewLine(Environment.NewLine), XmlMultiLineElement("summary", List <XmlNodeSyntax>()) .AddContent(XmlNewLine(Environment.NewLine)) .AddContent(paragraphs.SelectMany(x => new XmlNodeSyntax[] { XmlMultiLineElement("para", List <XmlNodeSyntax>()) .AddContent(XmlNewLine(Environment.NewLine)) .AddContent(x.SelectMany(l => new XmlNodeSyntax[] { XmlText(l), XmlNewLine(Environment.NewLine) }).ToArray()), XmlNewLine(Environment.NewLine) }).ToArray()), XmlText(Environment.NewLine))); member = member.WithLeadingTrivia(TriviaList(comment)); return(member); }
private static IList <string[]> ProcessComments(CppComment comments, string nativeName) { var paragraphs = new List <string[]>(); ProcessComments(comments); return(paragraphs); void ProcessComments(CppComment comment) { switch (comment) { case CppCommentFull full: foreach (var subComment in full.Children) { ProcessComments(subComment); } break; case CppCommentParagraph para: var paraLines = para.Children .OfType <CppCommentText>() .Select(t => t.Text.Trim()) .Where(t => !string.IsNullOrEmpty(t) && t != nativeName) .ToArray(); if (paraLines.Length > 0) { paragraphs.Add(paraLines); } break; default: throw new NotSupportedException(); } } }
private static CSharpTextComment GetChildAsCSharpComment(CppComment comment, bool trimEnd = true) { if (comment?.Children == null) { return(null); } return(new CSharpTextComment(GetChildAsText(comment, trimEnd))); }
public static void AddVSDocComment(this IList <CodeComment> comments, CppComment comment, string name) { if (comment == null) { return; } AddVSDocComment(comments, comment.ChildrenToString(), name); }
private static void AddComment(CSharpComment dest, CppComment comment) { var text = GetAsText(comment); if (!string.IsNullOrEmpty(text)) { dest.Children.Add(new CSharpTextComment(text)); } }
private static string GetAsText(CppComment comment, bool trimEnd = true) { if (comment == null) { return(null); } var text = comment.ToString(); return(trimEnd ? text.TrimEnd() : text); }
static string BuildCommentSummary(CppComment comment, int indent) { // Assemble a comment that ignores inline commands string txt = ""; var children = comment.Children[0].Children; for (int i = 0; i < children.Count; i++) { bool isCommand = IsCommand(children[i]); bool nextCommand = i + 1 == children.Count ? false : IsCommand(children[i + 1]); if (children[i] is CppCommentInlineCommand) { txt += "@" + ((CppCommentInlineCommand)children[i]).CommandName; } else { txt += children[i].ToString(); } if (!(nextCommand || isCommand) && i + 1 < children.Count) { txt += "\r\n"; } } txt = txt.Replace("&", "&"); txt = txt.Replace("<", "<"); txt = txt.Replace(">", ">"); string prefix = new string('\t', indent) + "/// "; string[] lines = txt.Split("\n"); bool first = true; for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("obsolete:")) { lines[i] = $"{new string('\t', indent)}[Obsolete(\"{lines[i].Substring("obsolete:".Length).Trim()}\")]"; } else { lines[i] = prefix + (first?"<summary>":"") + lines[i]; first = false; } } lines[lines.Length - 1] = lines[lines.Length - 1] + "</summary>"; return(string.Join("\n", lines)); }
/////////////////////////////////////////// static bool IsCommand(CppComment cmd) { if (cmd.Kind == CppCommentKind.InlineCommand) { return(true); } if (cmd.Kind == CppCommentKind.Text) { string txt = ((CppCommentText)cmd).Text; return(txt == "@" || txt == "&" || txt == "<" || txt == ">"); } return(false); }
static void PrintComment(CppComment comment) { if (!_printComments || comment == null) { return; } if (!string.IsNullOrEmpty(comment.ToString())) { Console.WriteLine($"// {comment}"); } }
internal static void PrintComments(StreamWriter file, CppComment comment, string tabs = "", bool newLine = false) { if (comment != null) { if (newLine) { file.WriteLine(); } file.WriteLine($"{tabs}/// <summary>"); GetText(file, comment, tabs); file.WriteLine($"{tabs}/// </summary>"); } }
private static string GetChildAsText(CppComment comment, bool trimEnd = true) { if (comment?.Children == null) { return(null); } var builder = new StringBuilder(); foreach (var child in comment.Children) { builder.Append(child); } var text = builder.ToString(); if (trimEnd) { text = text.TrimEnd(); } return(text); }
private static void GetText(StreamWriter file, CppComment comment, string tabs) { switch (comment.Kind) { case CppCommentKind.Text: var commentText = comment as CppCommentTextBase; file.WriteLine($"{tabs}/// {commentText.Text}"); break; case CppCommentKind.Paragraph: case CppCommentKind.Full: foreach (var child in comment.Children) { GetText(file, child, tabs); } break; default: ; break; } }