From db164c0c0bc969321d077cd57c17d1f94a80b35b Mon Sep 17 00:00:00 2001 From: Kimon Topouzidis Date: Fri, 28 Jul 2017 22:09:19 +0300 Subject: [PATCH] Ensured a single element for remarks in the generated XML documentation comments. (#904) --- src/Generator.Tests/AST/TestAST.cs | 24 +++++++++---------- .../Generators/CSharp/CSharpCommentPrinter.cs | 15 ++++++++++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/Generator.Tests/AST/TestAST.cs b/src/Generator.Tests/AST/TestAST.cs index fd97a614..facb2e42 100644 --- a/src/Generator.Tests/AST/TestAST.cs +++ b/src/Generator.Tests/AST/TestAST.cs @@ -393,31 +393,31 @@ namespace CppSharp.Generator.Tests.AST // Get the string that needs to be written to the debugger stdin file // handle when a control character is typed. // -// -// Some GUI programs will intercept "control + char" sequences and want -// to have them do what normally would happen when using a real -// terminal, so this function allows GUI programs to emulate this -// functionality. -// // The character that was typed along with the control key // // The string that should be written into the file handle that is // feeding the input stream for the debugger, or NULL if there is // no string for this control key. -// ".Replace("\r", string.Empty), commentMethod.Replace("\r", string.Empty)); +// +// +// Some GUI programs will intercept "control + char" sequences and want +// to have them do what normally would happen when using a real +// terminal, so this function allows GUI programs to emulate this +// functionality. +// ".Replace("\r", string.Empty), commentMethod.Replace("\r", string.Empty)); var methodTestDoxygen = @class.Methods.First(m => m.Name == "SBAttachInfo"); var commentMethodDoxygen = methodTestDoxygen.Comment.FullComment.CommentToString(CommentKind.BCPLSlash); Assert.AreEqual(@"/// Attach to a process by name. -/// -/// This function implies that a future call to SBTarget::Attach(...) -/// will be synchronous. -/// /// A full or partial name for the process to attach to. /// /// If false, attach to an existing process whose name matches. /// If true, then wait for the next process whose name matches. -/// ".Replace("\r", string.Empty), commentMethodDoxygen.Replace("\r", string.Empty)); +/// +/// +/// This function implies that a future call to SBTarget::Attach(...) +/// will be synchronous. +/// ".Replace("\r", string.Empty), commentMethodDoxygen.Replace("\r", string.Empty)); } [Test] diff --git a/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs b/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs index 945de99a..76854c99 100644 --- a/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpCommentPrinter.cs @@ -138,6 +138,14 @@ namespace CppSharp.Generators.CSharp { var commentPrefix = Comment.GetMultiLineCommentPrologue(kind); var commentBuilder = new StringBuilder(); + + sections.Sort((x, y) => x.Type.CompareTo(y.Type)); + var remarks = sections.Where(s => s.Type == CommentElement.Remarks).ToList(); + if (remarks.Any()) + remarks.First().GetLines().AddRange(remarks.Skip(1).SelectMany(s => s.GetLines())); + if (remarks.Count > 1) + sections.RemoveRange(sections.IndexOf(remarks.First()) + 1, remarks.Count - 1); + foreach (var section in sections.Where(s => s.HasLines)) { var lines = section.GetLines(); @@ -201,9 +209,12 @@ namespace CppSharp.Generators.CSharp private enum CommentElement { Summary, - Remarks, + Typeparam, Param, - Returns + Returns, + Exception, + Remarks, + Example } } }