diff options
author | huangmin-ms <huangmin@microsoft.com> | 2022-08-29 11:00:07 +0300 |
---|---|---|
committer | huangmin-ms <huangmin@microsoft.com> | 2022-08-29 11:00:07 +0300 |
commit | dc4f2e04e96ed9beb580340689971531b387798e (patch) | |
tree | a7b5a1332fd7576e7f94ff306b1abb3d8c0cf511 | |
parent | de9c2fe4c98446af10d5aa8cc69819804e7d398c (diff) | |
parent | bfe98ddac489c0bf9dc9df7eaba8e01c97931b4a (diff) |
Merge branch 'mh/608072' of https://github.com/mono/api-doc-tools into mh/608072mh/608072
12 files changed, 304 insertions, 8 deletions
diff --git a/mdoc/Consts.cs b/mdoc/Consts.cs index 64d86ab7..a420f910 100644 --- a/mdoc/Consts.cs +++ b/mdoc/Consts.cs @@ -41,6 +41,7 @@ namespace Mono.Documentation public const string FrameworksIndex = "FrameworksIndex"; public const string FrameworkAlternate = "FrameworkAlternate"; public const string Index = "Index"; + public const string Name = "Name"; public static bool CollapseInheritedInterfaces = true; diff --git a/mdoc/Makefile b/mdoc/Makefile index 95f78e8f..5fe352dd 100644 --- a/mdoc/Makefile +++ b/mdoc/Makefile @@ -150,6 +150,14 @@ Test/DocTest-differentTypeDefinitions-Second.dll: rm -f $@ $(CSCOMPILE) $(TEST_CSCFLAGS) -unsafe -debug -optimize -target:library -out:$@ Test/DocTest-differentTypeDefinitions.cs /define:SECOND +Test/DocTest-differentTypeParameterNames-First.dll: + rm -f $@ + $(CSCOMPILE) $(TEST_CSCFLAGS) -unsafe -debug -optimize -target:library -out:$@ Test/DocTest-differentTypeParameterNames.cs /define:FIRST + +Test/DocTest-differentTypeParameterNames-Second.dll: + rm -f $@ + $(CSCOMPILE) $(TEST_CSCFLAGS) -unsafe -debug -optimize -target:library -out:$@ Test/DocTest-differentTypeParameterNames.cs /define:SECOND + Test/DocTest-typeForwards-First.dll: rm -f $@ $(CSCOMPILE) $(TEST_CSCFLAGS) -unsafe -debug -optimize -target:library -out:$@ Test/DocTest-typeForwards.cs /define:FIRST @@ -232,6 +240,21 @@ check-monodocer-differentTypeDefinitions : Test/DocTest-differentTypeDefinitions $(MONO) $(PROGRAM) update -o Test/en.actual -frameworks Test/FrameworkTestData-fx-differentTypeDefinitions $(DIFF) Test/en.expected.differentTypeDefinitions Test/en.actual +.PHONY: check-monodocer-differentTypeParameterNames +check-monodocer-differentTypeParameterNames : Test/DocTest-differentTypeParameterNames-First.dll Test/DocTest-differentTypeParameterNames-Second.dll + -rm -Rf Test/en.actual + + -rm -Rf Test/FrameworkTestData-fx-differentTypeParameterNames + mkdir Test/FrameworkTestData-fx-differentTypeParameterNames + mkdir Test/FrameworkTestData-fx-differentTypeParameterNames/One + mkdir Test/FrameworkTestData-fx-differentTypeParameterNames/Two + cp Test/DocTest-differentTypeParameterNames-First.dll Test/FrameworkTestData-fx-differentTypeParameterNames/One + cp Test/DocTest-differentTypeParameterNames-Second.dll Test/FrameworkTestData-fx-differentTypeParameterNames/Two + $(MONO) $(PROGRAM) fx-bootstrap Test/FrameworkTestData-fx-differentTypeParameterNames + + $(MONO) $(PROGRAM) update -o Test/en.actual -frameworks Test/FrameworkTestData-fx-differentTypeParameterNames + $(DIFF) Test/en.expected.differentTypeParameterNames Test/en.actual + .PHONY: check-monodocer-typeForwards check-monodocer-typeForwards : Test/DocTest-typeForwards-First.dll Test/DocTest-typeForwards-Second.dll Test/DocTest-typeForwards-Third.dll -rm -Rf Test/en.actual @@ -951,7 +974,8 @@ check-doc-tools: \ check-ignored-namespace-generic \ check-multiple-mdoc \ check-type-projection \ - check-long-file-name + check-long-file-name \ + check-monodocer-differentTypeParameterNames #check-monodocer-dropns-delete check-doc-tools-update: check-monodocer-since-update \ diff --git a/mdoc/Mono.Documentation/Updater/DocumentationMember.cs b/mdoc/Mono.Documentation/Updater/DocumentationMember.cs index c0ee7356..33e9a1bc 100644 --- a/mdoc/Mono.Documentation/Updater/DocumentationMember.cs +++ b/mdoc/Mono.Documentation/Updater/DocumentationMember.cs @@ -3,8 +3,9 @@ using System.Xml; using System.Linq; using StringList = System.Collections.Generic.List<string>; using StringToStringMap = System.Collections.Generic.Dictionary<string, string>; -using Mono.Documentation.Updater.Frameworks; - +using Mono.Documentation.Updater.Frameworks;
+
+[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("mdoc.Test")] namespace Mono.Documentation.Updater {
public class DocumentationMember @@ -167,12 +168,11 @@ namespace Mono.Documentation.Updater Parameters = new StringList (ptypes); } } - XmlNodeList tp = node.SelectNodes ("TypeParameters/TypeParameter[not(@apistyle) or @apistyle='classic']"); - if (tp.Count > 0) + var tpElements = node.SelectNodes ("TypeParameters/TypeParameter[not(@apistyle) or @apistyle='classic']").Cast<XmlElement>().ToArray(); + if (tpElements.Length > 0) { - TypeParameters = new StringList (tp.Count); - for (int i = 0; i < tp.Count; ++i) - TypeParameters.Add (tp[i].Attributes["Name"].Value); + // Type parameter names may vary with moniker so we should group them by their indexes. + TypeParameters = GetTypeParametersFromXMLElements(tpElements); } else { @@ -201,6 +201,27 @@ namespace Mono.Documentation.Updater return MemberSignatures.Values.First (); else return $"{MemberType}{ReturnType} {MemberName}<{TypeParameters.Count}> ({Parameters.Count})"; + }
+
+ internal static StringList GetTypeParametersFromXMLElements(XmlElement[] tpElements)
+ {
+ if (tpElements == null || tpElements.Length == 0)
+ {
+ return null;
+ }
+
+ if (tpElements.Any(tp => tp.HasAttribute(Consts.Index)))
+ {
+ return tpElements.Select(tp => new
+ {
+ Index = tp.GetAttribute(Consts.Index),
+ Name = tp.GetAttribute(Consts.Name)
+ }).GroupBy(tp => tp.Index).Select(tp => tp.First().Name).ToList();
+ }
+ else
+ {
+ return tpElements.Select(tp => tp.GetAttribute(Consts.Name)).ToList();
+ }
} } }
\ No newline at end of file diff --git a/mdoc/Test/DocTest-differentTypeParameterNames.cs b/mdoc/Test/DocTest-differentTypeParameterNames.cs new file mode 100644 index 00000000..75ad26a1 --- /dev/null +++ b/mdoc/Test/DocTest-differentTypeParameterNames.cs @@ -0,0 +1,24 @@ +namespace TheNamespace +{ +#if FIRST + public class GenericType<K1, V1> + { + public void GenericMethod<T1, U1>() + { + } + + public delegate void GenericDelegate<D1>(); + } +#endif + +#if SECOND + public class GenericType<K2, V2> + { + public void GenericMethod<T2, U2>() + { + } + + public delegate void GenericDelegate<D2>(); + } +#endif +}
\ No newline at end of file diff --git a/mdoc/Test/en.expected.differentTypeParameterNames/FrameworksIndex/One.xml b/mdoc/Test/en.expected.differentTypeParameterNames/FrameworksIndex/One.xml new file mode 100644 index 00000000..e0c2a868 --- /dev/null +++ b/mdoc/Test/en.expected.differentTypeParameterNames/FrameworksIndex/One.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<Framework Name="One"> + <Assemblies> + <Assembly Name="DocTest-differentTypeParameterNames-First" Version="0.0.0.0" /> + </Assemblies> + <Namespace Name="TheNamespace"> + <Type Name="TheNamespace.GenericType`2" Id="T:TheNamespace.GenericType`2"> + <Member Id="M:TheNamespace.GenericType`2.#ctor" /> + <Member Id="M:TheNamespace.GenericType`2.GenericMethod``2" /> + </Type> + <Type Name="TheNamespace.GenericType`2/GenericDelegate`1" Id="T:TheNamespace.GenericType`2.GenericDelegate`1" /> + </Namespace> +</Framework>
\ No newline at end of file diff --git a/mdoc/Test/en.expected.differentTypeParameterNames/FrameworksIndex/Two.xml b/mdoc/Test/en.expected.differentTypeParameterNames/FrameworksIndex/Two.xml new file mode 100644 index 00000000..bea1aa8a --- /dev/null +++ b/mdoc/Test/en.expected.differentTypeParameterNames/FrameworksIndex/Two.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<Framework Name="Two"> + <Assemblies> + <Assembly Name="DocTest-differentTypeParameterNames-Second" Version="0.0.0.0" /> + </Assemblies> + <Namespace Name="TheNamespace"> + <Type Name="TheNamespace.GenericType`2" Id="T:TheNamespace.GenericType`2"> + <Member Id="M:TheNamespace.GenericType`2.#ctor" /> + <Member Id="M:TheNamespace.GenericType`2.GenericMethod``2" /> + </Type> + <Type Name="TheNamespace.GenericType`2/GenericDelegate`1" Id="T:TheNamespace.GenericType`2.GenericDelegate`1" /> + </Namespace> +</Framework>
\ No newline at end of file diff --git a/mdoc/Test/en.expected.differentTypeParameterNames/TheNamespace/GenericType`2+GenericDelegate`1.xml b/mdoc/Test/en.expected.differentTypeParameterNames/TheNamespace/GenericType`2+GenericDelegate`1.xml new file mode 100644 index 00000000..e8c44092 --- /dev/null +++ b/mdoc/Test/en.expected.differentTypeParameterNames/TheNamespace/GenericType`2+GenericDelegate`1.xml @@ -0,0 +1,31 @@ +<Type Name="GenericType<K2,V2>+GenericDelegate<D2>" FullName="TheNamespace.GenericType<K2,V2>+GenericDelegate<D2>"> + <TypeSignature Language="C#" Value="public delegate void GenericType<K1,V1>.GenericDelegate<D1>();" FrameworkAlternate="One" /> + <TypeSignature Language="ILAsm" Value=".class nested public auto ansi sealed GenericType`2/GenericDelegate`1<K1, V1, D1> extends System.MulticastDelegate" FrameworkAlternate="One" /> + <TypeSignature Language="C#" Value="public delegate void GenericType<K2,V2>.GenericDelegate<D2>();" FrameworkAlternate="Two" /> + <TypeSignature Language="ILAsm" Value=".class nested public auto ansi sealed GenericType`2/GenericDelegate`1<K2, V2, D2> extends System.MulticastDelegate" FrameworkAlternate="Two" /> + <AssemblyInfo> + <AssemblyName>DocTest-differentTypeParameterNames-First</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <AssemblyInfo> + <AssemblyName>DocTest-differentTypeParameterNames-Second</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <TypeParameters> + <TypeParameter Name="D1" Index="0" FrameworkAlternate="One" /> + <TypeParameter Name="D2" Index="0" FrameworkAlternate="Two" /> + </TypeParameters> + <Base> + <BaseTypeName>System.Delegate</BaseTypeName> + </Base> + <Parameters /> + <ReturnValue> + <ReturnType>System.Void</ReturnType> + </ReturnValue> + <Docs> + <typeparam name="D1">To be added.</typeparam> + <typeparam name="D2">To be added.</typeparam> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> +</Type> diff --git a/mdoc/Test/en.expected.differentTypeParameterNames/TheNamespace/GenericType`2.xml b/mdoc/Test/en.expected.differentTypeParameterNames/TheNamespace/GenericType`2.xml new file mode 100644 index 00000000..18b524c1 --- /dev/null +++ b/mdoc/Test/en.expected.differentTypeParameterNames/TheNamespace/GenericType`2.xml @@ -0,0 +1,85 @@ +<Type Name="GenericType<K2,V2>" FullName="TheNamespace.GenericType<K2,V2>"> + <TypeSignature Language="C#" Value="public class GenericType<K1,V1>" FrameworkAlternate="One" /> + <TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit GenericType`2<K1, V1> extends System.Object" FrameworkAlternate="One" /> + <TypeSignature Language="C#" Value="public class GenericType<K2,V2>" FrameworkAlternate="Two" /> + <TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit GenericType`2<K2, V2> extends System.Object" FrameworkAlternate="Two" /> + <AssemblyInfo> + <AssemblyName>DocTest-differentTypeParameterNames-First</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <AssemblyInfo> + <AssemblyName>DocTest-differentTypeParameterNames-Second</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <TypeParameters> + <TypeParameter Name="K1" Index="0" FrameworkAlternate="One" /> + <TypeParameter Name="K2" Index="0" FrameworkAlternate="Two" /> + <TypeParameter Name="V1" Index="1" FrameworkAlternate="One" /> + <TypeParameter Name="V2" Index="1" FrameworkAlternate="Two" /> + </TypeParameters> + <Base> + <BaseTypeName>System.Object</BaseTypeName> + </Base> + <Interfaces /> + <Docs> + <typeparam name="K1">To be added.</typeparam> + <typeparam name="K2">To be added.</typeparam> + <typeparam name="V1">To be added.</typeparam> + <typeparam name="V2">To be added.</typeparam> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> + <Members> + <Member MemberName=".ctor"> + <MemberSignature Language="C#" Value="public GenericType ();" /> + <MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" /> + <MemberType>Constructor</MemberType> + <AssemblyInfo> + <AssemblyName>DocTest-differentTypeParameterNames-First</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <AssemblyInfo> + <AssemblyName>DocTest-differentTypeParameterNames-Second</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <Parameters /> + <Docs> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> + </Member> + <Member MemberName="GenericMethod<T2,U2>"> + <MemberSignature Language="C#" Value="public void GenericMethod<T1,U1> ();" FrameworkAlternate="One" /> + <MemberSignature Language="ILAsm" Value=".method public hidebysig instance void GenericMethod<T1, U1>() cil managed" FrameworkAlternate="One" /> + <MemberSignature Language="C#" Value="public void GenericMethod<T2,U2> ();" FrameworkAlternate="Two" /> + <MemberSignature Language="ILAsm" Value=".method public hidebysig instance void GenericMethod<T2, U2>() cil managed" FrameworkAlternate="Two" /> + <MemberType>Method</MemberType> + <AssemblyInfo> + <AssemblyName>DocTest-differentTypeParameterNames-First</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <AssemblyInfo> + <AssemblyName>DocTest-differentTypeParameterNames-Second</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <ReturnValue> + <ReturnType>System.Void</ReturnType> + </ReturnValue> + <TypeParameters> + <TypeParameter Name="T1" Index="0" FrameworkAlternate="One" /> + <TypeParameter Name="T2" Index="0" FrameworkAlternate="Two" /> + <TypeParameter Name="U1" Index="1" FrameworkAlternate="One" /> + <TypeParameter Name="U2" Index="1" FrameworkAlternate="Two" /> + </TypeParameters> + <Parameters /> + <Docs> + <typeparam name="T1">To be added.</typeparam> + <typeparam name="T2">To be added.</typeparam> + <typeparam name="U1">To be added.</typeparam> + <typeparam name="U2">To be added.</typeparam> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> + </Member> + </Members> +</Type> diff --git a/mdoc/Test/en.expected.differentTypeParameterNames/index.xml b/mdoc/Test/en.expected.differentTypeParameterNames/index.xml new file mode 100644 index 00000000..2ae6c5ed --- /dev/null +++ b/mdoc/Test/en.expected.differentTypeParameterNames/index.xml @@ -0,0 +1,33 @@ +<Overview> + <Assemblies> + <Assembly Name="DocTest-differentTypeParameterNames-First" Version="0.0.0.0"> + <Attributes> + <Attribute> + <AttributeName>System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute+DebuggingModes.IgnoreSymbolStoreSequencePoints)</AttributeName> + </Attribute> + <Attribute> + <AttributeName>System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)</AttributeName> + </Attribute> + </Attributes> + </Assembly> + <Assembly Name="DocTest-differentTypeParameterNames-Second" Version="0.0.0.0"> + <Attributes> + <Attribute> + <AttributeName>System.Diagnostics.Debuggable(System.Diagnostics.DebuggableAttribute+DebuggingModes.IgnoreSymbolStoreSequencePoints)</AttributeName> + </Attribute> + <Attribute> + <AttributeName>System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)</AttributeName> + </Attribute> + </Attributes> + </Assembly> + </Assemblies> + <Remarks>To be added.</Remarks> + <Copyright>To be added.</Copyright> + <Types> + <Namespace Name="TheNamespace"> + <Type Name="GenericType`2" DisplayName="GenericType<K2,V2>" Kind="Class" /> + <Type Name="GenericType`2+GenericDelegate`1" DisplayName="GenericType<K2,V2>+GenericDelegate<D2>" Kind="Delegate" /> + </Namespace> + </Types> + <Title>Untitled</Title> +</Overview> diff --git a/mdoc/Test/en.expected.differentTypeParameterNames/ns-.xml b/mdoc/Test/en.expected.differentTypeParameterNames/ns-.xml new file mode 100644 index 00000000..36dfeb30 --- /dev/null +++ b/mdoc/Test/en.expected.differentTypeParameterNames/ns-.xml @@ -0,0 +1,6 @@ +<Namespace Name=""> + <Docs> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> +</Namespace> diff --git a/mdoc/Test/en.expected.differentTypeParameterNames/ns-TheNamespace.xml b/mdoc/Test/en.expected.differentTypeParameterNames/ns-TheNamespace.xml new file mode 100644 index 00000000..757c55bd --- /dev/null +++ b/mdoc/Test/en.expected.differentTypeParameterNames/ns-TheNamespace.xml @@ -0,0 +1,6 @@ +<Namespace Name="TheNamespace"> + <Docs> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> +</Namespace> diff --git a/mdoc/mdoc.Test/DocumentationMemberTest.cs b/mdoc/mdoc.Test/DocumentationMemberTest.cs new file mode 100644 index 00000000..bb3f2d99 --- /dev/null +++ b/mdoc/mdoc.Test/DocumentationMemberTest.cs @@ -0,0 +1,39 @@ +using Mono.Documentation.Updater; +using NUnit.Framework; +using System.Linq; +using System.Xml; + +namespace mdoc.Test +{ + [TestFixture] + public class DocumentationMemberTest + { + [Test] + public void Test_GetTypeParametersFromXMLElements() + { + var actual = DocumentationMember.GetTypeParametersFromXMLElements(null); + Assert.IsNull(actual); + + actual = DocumentationMember.GetTypeParametersFromXMLElements(new XmlElement[0]); + Assert.IsNull(actual); + + var doc1 = new XmlDocument(); + doc1.LoadXml("<TypeParameters> " + + "<TypeParameter Name = \"T\" Index = \"0\" FrameworkAlternate = \"net-5.0;net-6.0;netcore-3.0;netcore-3.1\" />" + + "<TypeParameter Name = \"TFrom\" Index = \"0\" FrameworkAlternate = \"net-7.0\" />" + + "<TypeParameter Name = \"U\" Index = \"1\" FrameworkAlternate = \"net-5.0;net-6.0;netcore-3.0;netcore-3.1\" />" + + "<TypeParameter Name = \"TTo\" Index = \"1\" FrameworkAlternate = \"net-7.0\" />" + + "</TypeParameters>"); + + var tpElements = doc1.SelectNodes("TypeParameters/TypeParameter[not(@apistyle) or @apistyle='classic']").Cast<XmlElement>().ToArray(); + actual = DocumentationMember.GetTypeParametersFromXMLElements(tpElements); + Assert.AreEqual(2, actual.Count); + + var doc2 = new XmlDocument(); + doc2.LoadXml("<TypeParameters> <TypeParameter Name = \"T\" /> <TypeParameter Name = \"U\" /><TypeParameter Name = \"V\" /></TypeParameters>"); + tpElements = doc2.SelectNodes("TypeParameters/TypeParameter[not(@apistyle) or @apistyle='classic']").Cast<XmlElement>().ToArray(); + actual = DocumentationMember.GetTypeParametersFromXMLElements(tpElements); + Assert.AreEqual(3, actual.Count); + } + } +} |