diff options
author | Joel Martinez <joelmartinez@gmail.com> | 2017-07-21 00:37:01 +0300 |
---|---|---|
committer | Joel Martinez <joelmartinez@gmail.com> | 2017-07-21 00:37:01 +0300 |
commit | f07d64cf3ce1f478de3bb4435de7f9596890c783 (patch) | |
tree | 3a8a174862e06f332166758903c96cca93a817d3 | |
parent | d938cee866a7e94c02ce71fd3352e67f24b8da59 (diff) |
WIP: classic deprecationdocstat-classic-deprecation
-rw-r--r-- | tools/DocStat/DocStat.Tests/ClassicDeprecation.cs | 217 | ||||
-rw-r--r-- | tools/DocStat/DocStat.Tests/DocStat.Tests.csproj | 1 | ||||
-rw-r--r-- | tools/DocStat/DocStat/DocStat.csproj | 1 | ||||
-rw-r--r-- | tools/DocStat/DocStat/EcmaXmlHelper.cs | 3 | ||||
-rw-r--r-- | tools/DocStat/DocStat/Extensions.cs | 36 |
5 files changed, 257 insertions, 1 deletions
diff --git a/tools/DocStat/DocStat.Tests/ClassicDeprecation.cs b/tools/DocStat/DocStat.Tests/ClassicDeprecation.cs new file mode 100644 index 00000000..f5cfe11e --- /dev/null +++ b/tools/DocStat/DocStat.Tests/ClassicDeprecation.cs @@ -0,0 +1,217 @@ +using NUnit.Framework; +using System; +using System.Linq; +using System.Xml.Linq; + +using DocStat; +namespace DocStat.Tests +{ + [TestFixture ()] + public class ClassicDeprecation + { + [Test ()] + public void TypeSummary () + { + TestTransferOfElement ("Type", "Docs", "summary"); + } + + [Test ()] + public void TypeRemarks () + { + TestTransferOfElement ("Type", "Docs", "remarks"); + } + + [Test ()] + public void MemberSummaries () + { + // Load the XML docs + var classic = Data.Load (Data.ClassicXml); + var unified = Data.Load (Data.UnifiedXml); + + var classicMembers = classic.Element ("Type").Elements ("Members").Elements ("Member") + .Where (m => + { + var apistyle = m.Attribute ("apistyle"); + return apistyle == null || apistyle.Value != "classic"; + }); + foreach (var member in classicMembers) + { + var getResult = FixElement (member, unified, "Docs", "summary"); + var result = getResult (); + + XElement classicElement = result.Item1, unifiedElement = result.Item2; + Assert.IsTrue (XNode.DeepEquals (classicElement, unifiedElement)); + + // memberr remarks + getResult = FixElement (member, unified, "Docs", "remarks"); + getResult = FixElement (member, unified, "Docs", "returns"); + //getResult = FixElements (member, unified, "Docs", "param"); + //getResult = FixElements (member, unified, "Docs", "typeparam"); + + // assert that the docs were transferred + } + } + + private static void TestTransferOfElement (params string[] query) + { + // Load the XML docs + var classic = Data.Load (Data.ClassicXml); + var unified = Data.Load (Data.UnifiedXml); + + var getResult = FixElement (classic, unified, query); + + var result = getResult (); + XElement classicElement = result.Item1, unifiedElement = result.Item2; + + // assert that the docs were transferred + Assert.IsTrue (XNode.DeepEquals (classicElement, unifiedElement)); + } + + /// <summary>Transfers the element referred to by the query</summary> + /// <returns>A function that you can use to retrieve the post-fix elements, for comparison</returns> + /// <param name="classic">Classic XDocument. The source of the docs</param> + /// <param name="unified">Unified XDocument. The target of the docs</param> + /// <param name="query">The path to the target element</param> + private static Func<Tuple<XElement, XElement>> FixElement (XDocument classic, XDocument unified, params string[] query) + { + var classicElement = classic.Element (query); + return FixElement (classicElement, unified); + } + /// <summary>Transfers the element referred to by the query</summary> + /// <returns>A function that you can use to retrieve the post-fix elements, for comparison</returns> + /// <param name="classicElement">Classic element.</param> + /// <param name="unified">Unified.</param> + /// <param name="query">Query.</param> + private static Func<Tuple<XElement, XElement>> FixElement (XElement classicElement, XDocument unified, params string[] query) + { + if (query != null && query.Length > 0) + { + classicElement = classicElement.Element (query); + } + var selector = EcmaXmlHelper.GetSelectorFor (classicElement); + + // pick out the corresponding "new element" + var unifiedElement = selector (unified); + + // FIX the docs + if (classicElement.Attribute ("apistyle") != null) + classicElement.Attribute ("apistyle").Remove (); + + EcmaXmlHelper.Fix (unifiedElement, classicElement); + + return () => new Tuple<XElement, XElement> (classicElement, selector (unified)); + } + } + + /// <summary>Some data for the purposes of testing</summary> + static class Data + { + public static XDocument Load (string xml) => XDocument.Parse (xml); + + /// <summary>Some XMl with "classic" elements</summary> + public static string ClassicXml = @"<Type Name=""MTLOrigin"" FullName=""MonoTouch.Metal.MTLOrigin""> + <TypeSignature Language=""C#"" Value=""public struct MTLOrigin"" /> + <TypeSignature Language=""ILAsm"" Value="".class public sequential ansi sealed beforefieldinit MTLOrigin extends System.ValueType"" /> + <AssemblyInfo apistyle=""classic""> + <AssemblyName>monotouch</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <AssemblyInfo apistyle=""unified""> + <AssemblyName>Xamarin.iOS</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <Base> + <BaseTypeName>System.ValueType</BaseTypeName> + </Base> + <Interfaces /> + <Docs> + <summary>The location of a pixel in an image or texture.</summary> + <remarks>this has docs</remarks> + </Docs> + <Members> + <Member MemberName="".ctor""> + <MemberSignature Language=""C#"" Value=""public MTLOrigin (int x, int y, int z);"" apistyle=""classic"" /> + <MemberSignature Language=""ILAsm"" Value="".method public hidebysig specialname rtspecialname instance void .ctor(int32 x, int32 y, int32 z) cil managed"" apistyle=""classic"" /> + <MemberSignature Language=""C#"" Value=""public MTLOrigin (nint x, nint y, nint z);"" apistyle=""unified"" /> + <MemberSignature Language=""ILAsm"" Value="".method public hidebysig specialname rtspecialname instance void .ctor(valuetype System.nint x, valuetype System.nint y, valuetype System.nint z) cil managed"" apistyle=""unified"" /> + <MemberType>Constructor</MemberType> + <AssemblyInfo apistyle=""classic""> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <AssemblyInfo apistyle=""unified""> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <Parameters> + <Parameter Name=""x"" Type=""System.Int32"" apistyle=""classic"" /> + <Parameter Name=""y"" Type=""System.Int32"" apistyle=""classic"" /> + <Parameter Name=""z"" Type=""System.Int32"" apistyle=""classic"" /> + <Parameter Name=""x"" Type=""System.nint"" apistyle=""unified"" /> + <Parameter Name=""y"" Type=""System.nint"" apistyle=""unified"" /> + <Parameter Name=""z"" Type=""System.nint"" apistyle=""unified"" /> + </Parameters> + <Docs> + <param name=""x"">this has docs</param> + <param name=""y"">this has docs</param> + <param name=""z"">this has docs</param> + <summary>this has docs</summary> + <remarks>this has docs</remarks> + </Docs> + </Member> + <Member MemberName=""SomeField"" apistyle=""classic""> + <MemberSignature Language=""C#"" Value=""SomeField"" /> + <MemberSignature Language=""ILAsm"" Value="".field public static literal valuetype System.Int32 SomeField"" /> + <MemberType>Field</MemberType> + <AssemblyInfo> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <ReturnValue> + <ReturnType>System.Int32</ReturnType> + </ReturnValue> + <Docs> + <summary>These should be thrown away</summary> + </Docs> + </Member> + </Members> +</Type>"; + + /// <summary>The new/empty XMl stubs for the same type</summary> + public static string UnifiedXml = @"<Type Name=""MTLOrigin"" FullName=""Metal.MTLOrigin""> + <TypeSignature Language=""C#"" Value=""public struct MTLOrigin"" /> + <TypeSignature Language=""ILAsm"" Value="".class public sequential ansi sealed beforefieldinit MTLOrigin extends System.ValueType"" /> + <AssemblyInfo> + <AssemblyName>Xamarin.iOS</AssemblyName> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <Base> + <BaseTypeName>System.ValueType</BaseTypeName> + </Base> + <Interfaces /> + <Docs> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> + <Members> + <Member MemberName="".ctor""> + <MemberSignature Language=""C#"" Value=""public MTLOrigin (nint x, nint y, nint z);"" /> + <MemberSignature Language=""ILAsm"" Value="".method public hidebysig specialname rtspecialname instance void .ctor(valuetype System.nint x, valuetype System.nint y, valuetype System.nint z) cil managed"" /> + <MemberType>Constructor</MemberType> + <AssemblyInfo> + <AssemblyVersion>0.0.0.0</AssemblyVersion> + </AssemblyInfo> + <Parameters> + <Parameter Name=""x"" Type=""System.nint"" /> + <Parameter Name=""y"" Type=""System.nint"" /> + <Parameter Name=""z"" Type=""System.nint"" /> + </Parameters> + <Docs> + <param name=""x"">To be added.</param> + <param name=""y"">To be added.</param> + <param name=""z"">To be added.</param> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> + </Member> + </Members> +</Type>"; + } +}
\ No newline at end of file diff --git a/tools/DocStat/DocStat.Tests/DocStat.Tests.csproj b/tools/DocStat/DocStat.Tests/DocStat.Tests.csproj index 2a48d3cd..d442f688 100644 --- a/tools/DocStat/DocStat.Tests/DocStat.Tests.csproj +++ b/tools/DocStat/DocStat.Tests/DocStat.Tests.csproj @@ -34,6 +34,7 @@ </ItemGroup>
<ItemGroup>
<Compile Include="EcmaXmlHelperTests.cs" />
+ <Compile Include="ClassicDeprecation.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
diff --git a/tools/DocStat/DocStat/DocStat.csproj b/tools/DocStat/DocStat/DocStat.csproj index 6ba10b6a..67fc9b52 100644 --- a/tools/DocStat/DocStat/DocStat.csproj +++ b/tools/DocStat/DocStat/DocStat.csproj @@ -38,6 +38,7 @@ <Link>Options.cs</Link>
</Compile>
<Compile Include="comparereport.cs" />
+ <Compile Include="Extensions.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Xml.Linq" />
diff --git a/tools/DocStat/DocStat/EcmaXmlHelper.cs b/tools/DocStat/DocStat/EcmaXmlHelper.cs index 8176b0ad..5e760836 100644 --- a/tools/DocStat/DocStat/EcmaXmlHelper.cs +++ b/tools/DocStat/DocStat/EcmaXmlHelper.cs @@ -38,7 +38,8 @@ namespace DocStat case "Member": // The ILAsm signature is unique, and always present return (XElement e) => e.Elements("MemberSignature") - .First((a) => a.Attribute("Language").Value == "ILAsm") + .First((a) => a.Attribute("Language").Value == "ILAsm" && + (a.Attribute ("apistyle") == null || a.Attribute ("apistyle").Value == "unified")) .Attribute("Value"); case "related": return (XElement e) => e.Attribute("href"); ; diff --git a/tools/DocStat/DocStat/Extensions.cs b/tools/DocStat/DocStat/Extensions.cs new file mode 100644 index 00000000..d9356954 --- /dev/null +++ b/tools/DocStat/DocStat/Extensions.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; + +namespace DocStat +{ + public static class Extensions + { + public static void Iter<T> (this IEnumerable<T> list, Action<T> action) + { + foreach (var item in list) + action (item); + } + + public static XElement Element (this XDocument element, params string[] querychain) + { + if (element.Root.Name.LocalName.Equals (querychain.FirstOrDefault ())) + return Element (element.Root, querychain.Skip (1).ToArray ()); + + return Element (element.Root, querychain); + } + + public static XElement Element (this XElement element, params string[] querychain) + { + XElement current = element; + foreach (var q in querychain) + { + if (current == null) break; + current = current.Element (q); + } + + return current == element ? null : current; + } + } +}
\ No newline at end of file |