diff options
author | Joel Martinez <joelmartinez@gmail.com> | 2020-03-26 00:11:05 +0300 |
---|---|---|
committer | Joel Martinez <joelmartinez@gmail.com> | 2020-05-06 22:46:53 +0300 |
commit | 54dd5da3c8698aad9708c5237b40e6ce6dd3dc44 (patch) | |
tree | efe412c1e08dcf86599bc297661c0ba759dca8a8 /mdoc | |
parent | adfd1dd650ea3cee2802bfd719c026d37350cda0 (diff) |
ReturnType is now monikerized.
different return types in different frameworks will now
have the FrameworkAlternate attribute added to it
Diffstat (limited to 'mdoc')
-rw-r--r-- | mdoc/Mono.Documentation/MDocUpdater.cs | 43 | ||||
-rw-r--r-- | mdoc/Mono.Documentation/Updater/DocUtils.cs | 13 | ||||
-rw-r--r-- | mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs | 2 | ||||
-rw-r--r-- | mdoc/Mono.Documentation/Updater/Frameworks/FrameworkEntry.cs | 3 | ||||
-rw-r--r-- | mdoc/Test/en.expected.importecmadoc/System/Array.xml | 20 | ||||
-rw-r--r-- | mdoc/mdoc.Test/Enumeration/EnumeratorTests.cs | 38 | ||||
-rw-r--r-- | mdoc/mdoc.Test/UwpTestWinRtComponentCpp/UwpTestWinRtComponentCpp.log | 1 | ||||
-rw-r--r-- | mdoc/mdoc.Test/XmlUpdateTests.cs | 9 |
8 files changed, 100 insertions, 29 deletions
diff --git a/mdoc/Mono.Documentation/MDocUpdater.cs b/mdoc/Mono.Documentation/MDocUpdater.cs index 7149ef56..14be199a 100644 --- a/mdoc/Mono.Documentation/MDocUpdater.cs +++ b/mdoc/Mono.Documentation/MDocUpdater.cs @@ -4349,7 +4349,7 @@ namespace Mono.Documentation return typename; } - private void MakeReturnValue (FrameworkTypeEntry typeEntry, XmlElement root, TypeReference type, IList<CustomAttribute> attributes, bool shouldDuplicateWithNew = false) + private void MakeReturnValue (FrameworkTypeEntry typeEntry, XmlElement root, TypeReference type, MemberReference member, IList<CustomAttribute> attributes, bool shouldDuplicateWithNew = false) { XmlElement e = WriteElement (root, "ReturnValue"); var valueToUse = GetDocTypeFullName (type); @@ -4364,18 +4364,29 @@ namespace Mono.Documentation valueToUse = valueToUse.Remove(valueToUse.Length - 1); } - AddXmlNode (e.SelectNodes ("ReturnType").Cast<XmlElement> ().ToArray (), - x => x.InnerText == valueToUse, - x => x.InnerText = valueToUse, - () => - { - var newNode = WriteElementText (e, "ReturnType", valueToUse, forceNewElement: true); - if (attributes != null) - MakeAttributes (e, GetCustomAttributes (attributes, ""), typeEntry.Framework, typeEntry); - return newNode; - }, - type); + DocUtils.AddElementWithFx(
+ typeEntry,
+ parent: e,
+ isFirst: typeEntry.IsMemberOnFirstFramework(member),// typeEntry.Framework.IsFirstFrameworkForType(typeEntry),
+ isLast: typeEntry.IsMemberOnLastFramework(member),// typeEntry.Framework.IsLastFrameworkForType(typeEntry),
+ allfxstring: new Lazy<string>(() => typeEntry.AllFrameworkStringForMember(member)),
+ clear: parent =>
+ {
+ parent.RemoveAll();
+ },
+ findExisting: parent =>
+ {
+ return parent.ChildNodes.Cast<XmlElement>().SingleOrDefault(rt => rt.Name == "ReturnType" && rt.InnerText == valueToUse);
+ },
+ addItem: parent =>
+ {
+ var newNode = WriteElementText(e, "ReturnType", valueToUse, forceNewElement: true);
+ if (attributes != null)
+ MakeAttributes(e, GetCustomAttributes(attributes, ""), typeEntry.Framework, typeEntry);
+
+ return newNode;
+ }); } private bool IsReadonlyAttribute(IList<CustomAttribute> attributes) @@ -4397,13 +4408,13 @@ namespace Mono.Documentation if (mi is MethodDefinition && ((MethodDefinition)mi).IsConstructor) return; else if (mi is MethodDefinition) - MakeReturnValue (typeEntry, root, ((MethodDefinition)mi).ReturnType, ((MethodDefinition)mi).MethodReturnType.CustomAttributes, shouldDuplicateWithNew); + MakeReturnValue (typeEntry, root, ((MethodDefinition)mi).ReturnType,mi, ((MethodDefinition)mi).MethodReturnType.CustomAttributes, shouldDuplicateWithNew); else if (mi is PropertyDefinition) - MakeReturnValue (typeEntry, root, ((PropertyDefinition)mi).PropertyType, null, shouldDuplicateWithNew); + MakeReturnValue (typeEntry, root, ((PropertyDefinition)mi).PropertyType, mi, null, shouldDuplicateWithNew); else if (mi is FieldDefinition) - MakeReturnValue (typeEntry, root, ((FieldDefinition)mi).FieldType, null, shouldDuplicateWithNew); + MakeReturnValue (typeEntry, root, ((FieldDefinition)mi).FieldType, mi, null, shouldDuplicateWithNew); else if (mi is EventDefinition) - MakeReturnValue (typeEntry, root, ((EventDefinition)mi).EventType, null, shouldDuplicateWithNew); + MakeReturnValue (typeEntry, root, ((EventDefinition)mi).EventType, mi, null, shouldDuplicateWithNew); else if (mi is AttachedEventReference) return; else if (mi is AttachedPropertyReference) diff --git a/mdoc/Mono.Documentation/Updater/DocUtils.cs b/mdoc/Mono.Documentation/Updater/DocUtils.cs index ec485cbc..2e607923 100644 --- a/mdoc/Mono.Documentation/Updater/DocUtils.cs +++ b/mdoc/Mono.Documentation/Updater/DocUtils.cs @@ -16,12 +16,12 @@ namespace Mono.Documentation.Updater public static class DocUtils
{
- public static void AddElementWithFx(FrameworkTypeEntry typeEntry, XmlElement parent, Action<XmlElement> clear, Func<XmlElement, XmlElement> findExisting, Func<XmlElement, XmlElement> addItem)
+ public static void AddElementWithFx(FrameworkTypeEntry typeEntry, XmlElement parent, bool isFirst, bool isLast, Lazy<string> allfxstring, Action<XmlElement> clear, Func<XmlElement, XmlElement> findExisting, Func<XmlElement, XmlElement> addItem)
{
if (typeEntry.TimesProcessed > 1)
return;
- if (typeEntry.Framework.IsFirstFrameworkForType(typeEntry))
+ if (isFirst)
{
clear(parent);
}
@@ -35,15 +35,14 @@ namespace Mono.Documentation.Updater item.AddFrameworkToElement(typeEntry.Framework);
- if (typeEntry.Framework.IsLastFrameworkForType(typeEntry))
+ if (isLast)
{
- item.ClearFrameworkIfAll(typeEntry);
+ item.ClearFrameworkIfAll(allfxstring.Value);
}
}
- public static void ClearFrameworkIfAll(this XmlElement element, FrameworkTypeEntry typeEntry)
+ public static void ClearFrameworkIfAll(this XmlElement element, string allfxstring)
{
- var allFrameworks = typeEntry.Framework.AllFrameworksWithType(typeEntry);
- if (element.HasAttribute(Consts.FrameworkAlternate) && element.GetAttribute(Consts.FrameworkAlternate) == allFrameworks)
+ if (element.HasAttribute(Consts.FrameworkAlternate) && element.GetAttribute(Consts.FrameworkAlternate) == allfxstring)
{
element.RemoveAttribute(Consts.FrameworkAlternate);
}
diff --git a/mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs b/mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs index 1917b597..3be0636f 100644 --- a/mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs +++ b/mdoc/Mono.Documentation/Updater/DocumentationEnumerator.cs @@ -107,7 +107,7 @@ namespace Mono.Documentation.Updater continue; MethodDefinition mDef = mi as MethodDefinition; - if (mDef != null && !mDef.IsConstructor) + if (mDef != null && !mDef.IsConstructor && (mDef.Name.StartsWith("op_Explicit", StringComparison.Ordinal) || mDef.Name.StartsWith("op_Implicit", StringComparison.Ordinal))) { // Casting operators can overload based on return type. string rtype = GetReplacedString ( diff --git a/mdoc/Mono.Documentation/Updater/Frameworks/FrameworkEntry.cs b/mdoc/Mono.Documentation/Updater/Frameworks/FrameworkEntry.cs index ec11252d..5343ae35 100644 --- a/mdoc/Mono.Documentation/Updater/Frameworks/FrameworkEntry.cs +++ b/mdoc/Mono.Documentation/Updater/Frameworks/FrameworkEntry.cs @@ -90,7 +90,8 @@ namespace Mono.Documentation.Updater.Frameworks return fxType.ContainsCSharpSig (memberSig) || fxType.ContainsDocId(docidsig); }).ToArray (); - if (!fxlist.Any ()) return false; + if (!fxlist.Any ()) + return false; var lastListed = fxlist.Last (); return lastListed.Name == this.Name; diff --git a/mdoc/Test/en.expected.importecmadoc/System/Array.xml b/mdoc/Test/en.expected.importecmadoc/System/Array.xml index 52aa128d..1ba88394 100644 --- a/mdoc/Test/en.expected.importecmadoc/System/Array.xml +++ b/mdoc/Test/en.expected.importecmadoc/System/Array.xml @@ -127,10 +127,22 @@ and the second dimension indexed by 1, 2, and 3. </para> </Parameters> <Docs> <typeparam name="T">To be added.</typeparam> - <param name="array">To be added.</param> - <summary>To be added.</summary> - <returns>To be added.</returns> - <remarks>To be added.</remarks> + <param name="array">The array to wrap in a read-only <see cref="T:System.Collections.Generic.IList<T>" /> wrapper.</param> + <summary> + <para>Returns a read-only <see cref="T: System.Collections.Generic.IList<T>" /> wrapper around the specified array.</para> + </summary> + <returns> + <para>A read-only <see cref="T:System.Collections.Generic.IList<T>" /> wrapper around the specified array.</para> + </returns> + <remarks> + <para> + <block subset="none" type="note">To prevent any modifications to the array, expose the array only through this wrapper.</block> + </para> + <para>The returned <see langword="IList<T>" /> has the same enumeration order as the array it wraps.</para> + <para>A collection that is read-only is simply a collection with a wrapper that prevents modifying the underlying array; therefore, if changes are made to the underlying array, the read-only collection reflects those changes.</para> + </remarks> + <exception cref="T:System.ArgumentNullException"> + <paramref name="array" /> is <see langword="null" />.</exception> </Docs> </Member> <Member MemberName="ConvertAll<TInput,TOutput>"> diff --git a/mdoc/mdoc.Test/Enumeration/EnumeratorTests.cs b/mdoc/mdoc.Test/Enumeration/EnumeratorTests.cs index 5f6ca5fe..9a375972 100644 --- a/mdoc/mdoc.Test/Enumeration/EnumeratorTests.cs +++ b/mdoc/mdoc.Test/Enumeration/EnumeratorTests.cs @@ -51,8 +51,41 @@ namespace mdoc.Test [Test] public void GetMethod() => TestMethodMember("BeginRead", XML_METHOD_TESTMETHOD); + [Test] + public void MergeDiffReturnTypes_MatchExplicitConversion_String() => testReturnType("op_Explicit", "System.String"); + + [Test] + public void MergeDiffReturnTypes_MatchExplicitConversion_CharArray() => testReturnType("op_Explicit", "System.Char[]"); + + [Test] + public void MergeDiffReturnTypes_MatchExplicitConversion_Int() => testReturnType("op_Implicit", "System.Int32"); + [Test] + public void MergeDiffReturnTypes_MatchExplicitConversion_IntArray() => testReturnType("op_Implicit", "System.Int32[]"); + #region Test infrastructure + private void testReturnType(string methName, string r) + { + TypeDefinition theclass = GetTypeDef<ConcreteClass>(); + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(@"<Member MemberName="""+ methName +@"""> + <MemberType>Method</MemberType> + <ReturnValue> + <ReturnType>" + r + @"</ReturnType> + </ReturnValue> + <Parameters> + <Parameter Name=""value"" Type=""mdoc.Test.EnumeratorTests+ConcreteClass"" /> + </Parameters> + </Member>"); + + DocumentationMember docmember = new DocumentationMember(doc.DocumentElement, typeEntry: null); + var result = DocumentationEnumerator.GetMember(theclass, docmember) as MethodReference; + + Assert.IsNotNull(result); + Assert.AreEqual(methName, result.Name); + Assert.AreEqual(r, result.ReturnType.FullName); + } private void TestProperty (string propertyName) { TypeDefinition theclass = GetTypeDef<ConcreteClass> (); @@ -110,6 +143,11 @@ namespace mdoc.Test string IFace1.AProperty { get; set; } string IFace2.AProperty { get; set; } public IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) => null; + + public static explicit operator string(ConcreteClass value) => value.AProperty; + public static explicit operator char[](ConcreteClass value) => value.AProperty.ToCharArray(); + public static implicit operator int(ConcreteClass value) => value.AProperty.Length; + public static implicit operator int[](ConcreteClass value) => value.AProperty.ToCharArray().Select(c => (int)c).ToArray(); } #endregion diff --git a/mdoc/mdoc.Test/UwpTestWinRtComponentCpp/UwpTestWinRtComponentCpp.log b/mdoc/mdoc.Test/UwpTestWinRtComponentCpp/UwpTestWinRtComponentCpp.log new file mode 100644 index 00000000..8480651a --- /dev/null +++ b/mdoc/mdoc.Test/UwpTestWinRtComponentCpp/UwpTestWinRtComponentCpp.log @@ -0,0 +1 @@ +C:\Users\marj\Documents\GitHub\api-doc-tools\mdoc\mdoc.Test\UwpTestWinRtComponentCpp\UwpTestWinRtComponentCpp.vcxproj(41,3): error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.Default.props" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\\Microsoft.Cpp.Default.props" is correct, and that the file exists on disk. diff --git a/mdoc/mdoc.Test/XmlUpdateTests.cs b/mdoc/mdoc.Test/XmlUpdateTests.cs index 1781f8a6..fbb4ce45 100644 --- a/mdoc/mdoc.Test/XmlUpdateTests.cs +++ b/mdoc/mdoc.Test/XmlUpdateTests.cs @@ -700,6 +700,9 @@ namespace mdoc.Test DocUtils.AddElementWithFx( typeEntry, parentx, + isFirst: typeEntry.Framework.IsFirstFrameworkForType(typeEntry), + isLast: typeEntry.Framework.IsLastFrameworkForType(typeEntry), + allfxstring: new Lazy<string>(() => typeEntry.Framework.AllFrameworksWithType(typeEntry)), clear: parent => { parent.RemoveAll(); @@ -737,6 +740,9 @@ namespace mdoc.Test DocUtils.AddElementWithFx( te, parentx, + isFirst: te.Framework.IsFirstFrameworkForType(te), + isLast: te.Framework.IsLastFrameworkForType(te), + allfxstring: new Lazy<string>(() => typeEntry.Framework.AllFrameworksWithType(typeEntry)), clear: parent => { parent.RemoveAll(); @@ -779,6 +785,9 @@ namespace mdoc.Test DocUtils.AddElementWithFx( te, parentx, + isFirst: typeEntry.Framework.IsFirstFrameworkForType(typeEntry), + isLast: typeEntry.Framework.IsLastFrameworkForType(typeEntry), + allfxstring: new Lazy<string>(() => typeEntry.Framework.AllFrameworksWithType(typeEntry)), clear: parent => { parent.RemoveAll(); |