From 8090b07c6577a26c43ff5e2ab3dca25ccbb77479 Mon Sep 17 00:00:00 2001
From: Abhay Singh
Date: Sun, 27 Feb 2022 15:48:31 +0530
Subject: [PATCH] Added workaround to support Enum documentation for C++
---
.../BasicArticleGenerator.cs | 24 +++++++++++-
test/code2yaml.Tests/Code2YamlTest.cs | 38 +++++++++++++++++++
2 files changed, 61 insertions(+), 1 deletion(-)
diff --git a/src/Microsoft.Content.Build.Code2Yaml.ArticleGenerator/BasicArticleGenerator.cs b/src/Microsoft.Content.Build.Code2Yaml.ArticleGenerator/BasicArticleGenerator.cs
index 1befbc1..070aa10 100644
--- a/src/Microsoft.Content.Build.Code2Yaml.ArticleGenerator/BasicArticleGenerator.cs
+++ b/src/Microsoft.Content.Build.Code2Yaml.ArticleGenerator/BasicArticleGenerator.cs
@@ -188,7 +188,8 @@ private static string RemoveArgs(string original)
protected void FillSummary(ArticleItemYaml yaml, XElement node)
{
- yaml.Summary = node.NullableElement("briefdescription").NullableInnerXml() + ParseSummaryFromDetailedDescription(node.NullableElement("detaileddescription"));
+ yaml.Summary = node.NullableElement("briefdescription").NullableInnerXml() + ParseSummaryFromDetailedDescription(node.NullableElement("detaileddescription"))
+ + EnumValueAsSummary(node);
if (yaml.Summary == string.Empty)
{
yaml.Summary = null;
@@ -449,6 +450,23 @@ private string ParseReturnDescription(XElement detailedDescription)
return returnValue.NullableInnerXml();
}
+ // Only for c++ language.
+ private string EnumValueAsSummary(XElement enumMember)
+ {
+ string language = (string) enumMember.Parent?.Parent?.Attribute("language");
+ if ( (string.Equals(language, "c++", StringComparison.OrdinalIgnoreCase) && string.Equals(language, "cplusplus", StringComparison.OrdinalIgnoreCase)) || (string)enumMember.Attribute("kind") != "enum")
+ {
+ return null;
+ }
+ string rowValues = "";
+
+ foreach (var node in enumMember.Elements("enumvalue"))
+ {
+ rowValues += "| " + node.Element("name").NullableInnerXml() + " | " + node.Element("briefdescription").NullableInnerXml() + node.Element("detaileddescription").NullableInnerXml() + " |
";
+ }
+ return $"| Name | Description |
{rowValues}
"; ;
+ }
+
///
///
///
@@ -508,6 +526,10 @@ private static int ParseStartline(string startlineStr)
{
type = MemberType.Field;
}
+ else if (kind.Contains("enum"))
+ {
+ type = MemberType.Enum;
+ }
//else if (kind.Contains("friend"))
//{
// type = MemberType.Friend;
diff --git a/test/code2yaml.Tests/Code2YamlTest.cs b/test/code2yaml.Tests/Code2YamlTest.cs
index 4ce5a0e..29f55fc 100644
--- a/test/code2yaml.Tests/Code2YamlTest.cs
+++ b/test/code2yaml.Tests/Code2YamlTest.cs
@@ -148,6 +148,44 @@ public void checkIndentation() {
Assert.Equal("App's summary
\r\n\r\n
\r\n
".Replace("\r\n", "\n"), referenceItem.Summary.Replace("\r\n", "\n"));
}
+ [Fact]
+ public void TestMetadataFromCPlusPlusProject()
+ {
+ // arrange
+ var outputFolder = Path.Combine(_workingFolder, "output");
+ var config = new ConfigModel
+ {
+ InputPaths = new List { "TestData/cplusplus" },
+ Language = "cplusplus",
+ OutputPath = outputFolder,
+ };
+ var context = new BuildContext();
+ context.SetSharedObject(Constants.Constants.Config, config);
+ var procedure = new StepCollection(
+ new RunDoxygen(),
+ new PreprocessXml(),
+ new ScanHierarchy(),
+ new TaskParallel(
+ new List
+ {
+ new GenerateToc { NameGenerator = NameGeneratorFactory.Create(config.Language) },
+ new GenerateArticles { Generator = ArticleGeneratorFactory.Create(config.Language) },
+ }));
+
+ // act
+ procedure.RunAsync(context).Wait();
+
+ // assert
+ var outputPathStruct = Path.Combine(outputFolder, "Check.CheckStruct1.yml");
+ var outputPathClass = Path.Combine(outputFolder, "Check.CheckClass1.yml");
+ var outputPathamespace = Path.Combine(outputFolder, "Check.yml");
+ var outputToc = Path.Combine(outputFolder, "toc.yml");
+ Assert.True(File.Exists(outputPathStruct));
+ Assert.True(File.Exists(outputPathClass));
+ Assert.True(File.Exists(outputPathamespace));
+ Assert.True(File.Exists(outputToc));
+ }
+
public void Dispose()
{
try