diff options
author | Joel Martinez <joelmartinez@gmail.com> | 2019-01-11 23:33:31 +0300 |
---|---|---|
committer | Joel Martinez <joelmartinez@gmail.com> | 2019-01-16 18:52:50 +0300 |
commit | 9d84d2e025237c1cf7d985681fde10dab0fd5d13 (patch) | |
tree | 5feb9ca913e4c38221bcb540fd1e4ac7dea57346 /mdoc | |
parent | f272ad0752bccb0d5127c22b94666884a0a08a6c (diff) |
#291: better handling of property indexing in multi-fx
Diffstat (limited to 'mdoc')
-rw-r--r-- | mdoc/Consts.cs | 1 | ||||
-rw-r--r-- | mdoc/Mono.Documentation/MDocUpdater.cs | 41 | ||||
-rw-r--r-- | mdoc/mdoc.Test/XmlConsts.cs | 61 | ||||
-rw-r--r-- | mdoc/mdoc.Test/XmlUpdateTests.cs | 147 |
4 files changed, 161 insertions, 89 deletions
diff --git a/mdoc/Consts.cs b/mdoc/Consts.cs index c2e61a36..45899c98 100644 --- a/mdoc/Consts.cs +++ b/mdoc/Consts.cs @@ -29,5 +29,6 @@ namespace Mono.Documentation public const string CompilationMappingAttribute = "Microsoft.FSharp.Core.CompilationMappingAttribute"; public const string FrameworksIndex = "FrameworksIndex"; public const string FrameworkAlternate = "FrameworkAlternate"; + public const string Index = "Index"; } } diff --git a/mdoc/Mono.Documentation/MDocUpdater.cs b/mdoc/Mono.Documentation/MDocUpdater.cs index c3004cac..e0e5a0ee 100644 --- a/mdoc/Mono.Documentation/MDocUpdater.cs +++ b/mdoc/Mono.Documentation/MDocUpdater.cs @@ -3590,7 +3590,16 @@ namespace Mono.Documentation var i = 0; foreach (var node in nodes) { - node.SetAttribute ("Index", i.ToString ()); + if (!node.HasAttribute("Index")) + { + node.SetAttribute("Index", i.ToString()); + } + else + { + int thisIndex; + if (Int32.TryParse(node.GetAttribute("Index"), out thisIndex)) + i = thisIndex; + } i++; } }; @@ -3656,14 +3665,19 @@ namespace Mono.Documentation addFXAttributes (xdata.Select (x => x.Element)); //-find type in previous frameworks - - string fxList = FXUtils.PreviouslyProcessedFXString (typeEntry); - //-find < parameter where index = currentIndex > - var currentNode = xdata[i].Element; - currentNode.SetAttribute (Consts.FrameworkAlternate, fxList); + var existingElements = xdata.Where(x => x.ActualIndex == i && x.Type == p.Type).ToArray(); + foreach (var currentNode in existingElements.Select(el => el.Element)) + { - addParameter (p.Definition, currentNode, p.Type, i, true, typeEntry.Framework.Name, true); + if (!currentNode.HasAttribute(Consts.FrameworkAlternate)) + { + string fxList = FXUtils.PreviouslyProcessedFXString(typeEntry); + currentNode.SetAttribute(Consts.FrameworkAlternate, fxList); + } + } + + addParameter (p.Definition, existingElements.Last().Element, p.Type, i, true, typeEntry.Framework.Name, true); fxAlternateTriggered = true; } @@ -3724,9 +3738,11 @@ namespace Mono.Documentation } } + // Now clean up var allFrameworks = typeEntry.Framework.AllFrameworksString; - foreach (var parameter in paramNodes - .Cast<XmlElement>()) + var finalNodes = paramNodes + .Cast<XmlElement>().ToArray(); + foreach (var parameter in finalNodes) { // if FXAlternate is entire list, just remove it if (parameter.HasAttribute(Consts.FrameworkAlternate) && parameter.GetAttribute(Consts.FrameworkAlternate) == allFrameworks) @@ -3734,6 +3750,13 @@ namespace Mono.Documentation parameter.RemoveAttribute(Consts.FrameworkAlternate); } } + + // if there are no fx attributes left, just remove the indices entirely + if (typeEntry.Framework.IsLastFramework && !finalNodes.Any(n => n.HasAttribute(Consts.FrameworkAlternate))) + { + foreach (var parameter in finalNodes) + parameter.RemoveAttribute(Consts.Index); + } } private void MakeTypeParameters (FrameworkTypeEntry entry, XmlElement root, IList<GenericParameter> typeParams, MemberReference member, bool shouldDuplicateWithNew) diff --git a/mdoc/mdoc.Test/XmlConsts.cs b/mdoc/mdoc.Test/XmlConsts.cs index fb79b7ba..0c295060 100644 --- a/mdoc/mdoc.Test/XmlConsts.cs +++ b/mdoc/mdoc.Test/XmlConsts.cs @@ -10,9 +10,25 @@ <ReturnType>System.Void</ReturnType> </ReturnValue> <Parameters> - <Parameter Name = ""a"" Type=""System.Int32"" /> - <Parameter Name = ""b"" Type=""System.String"" /> - <Parameter Name = ""c"" Type=""System.Int32"" /> + <Parameter Name = ""a"" Type=""System.Int32"" Index=""0"" FrameworkAlternate=""One"" /> + <Parameter Name = ""b"" Type=""System.String"" Index=""1"" FrameworkAlternate=""One"" /> + <Parameter Name = ""c"" Type=""System.Int32"" Index=""2"" FrameworkAlternate=""One"" /> + </Parameters> + <Docs> + <summary>To be added.</summary> + <remarks>To be added.</remarks> + </Docs> + </Member>"; + + public const string NormalSingleXml = @"<Member MemberName=""Meth""> + <MemberType>Method</MemberType> + <ReturnValue> + <ReturnType>System.Void</ReturnType> + </ReturnValue> + <Parameters> + <Parameter Name = ""a"" Type=""System.Int32"" Index=""0"" FrameworkAlternate=""One"" /> + <Parameter Name = ""d"" Type=""System.String"" Index=""1"" FrameworkAlternate=""One"" /> + <Parameter Name = ""c"" Type=""System.Int32"" Index=""2"" FrameworkAlternate=""One"" /> </Parameters> <Docs> <summary>To be added.</summary> @@ -80,9 +96,9 @@ <ReturnType>System.Void</ReturnType> </ReturnValue> <Parameters> - <Parameter Name = ""d"" Type=""System.Int32"" Index=""0"" FrameworkAlternate=""One;Three;Two"" /> - <Parameter Name = ""e"" Type=""System.String"" Index=""1"" FrameworkAlternate=""One;Three;Two"" /> - <Parameter Name = ""f"" Type=""System.Int32"" Index=""2"" FrameworkAlternate=""One;Three;Two"" /> + <Parameter Name = ""d"" Type=""System.Int32"" /> + <Parameter Name = ""e"" Type=""System.String"" /> + <Parameter Name = ""f"" Type=""System.Int32"" /> </Parameters> <Docs> <summary>To be added.</summary> @@ -90,6 +106,39 @@ </Docs> </Member>"; + public const string XML_METHOD_TESTMETHOD_BEFORE = @"<Member MemberName=""BeginRead""> + <MemberType>Method</MemberType> + <ReturnValue> + <ReturnType>System.IAsyncResult</ReturnType> + </ReturnValue> + <Parameters> + <Parameter Name = ""buffer"" Type=""System.Byte[]"" Index=""0"" FrameworkAlternate=""One"" /> + <Parameter Name = ""array"" Type=""System.Byte[]"" Index=""0"" FrameworkAlternate=""Two"" /> + <Parameter Name = ""offset"" Type=""System.Int32"" Index=""1"" FrameworkAlternate=""One;Two"" /> + <Parameter Name = ""count"" Type=""System.Int32"" Index=""2"" FrameworkAlternate=""One;Two"" /> + <Parameter Name = ""asyncCallback"" Type=""System.AsyncCallback"" Index=""3"" FrameworkAlternate=""One;Two"" /> + <Parameter Name = ""asyncState"" Type=""System.Object"" Index=""4"" FrameworkAlternate=""One;Two"" /> + </Parameters> + </Member>"; + + //byte[] buffer, int offset, int count, AsyncCallback cback, object state + public const string XML_METHOD_TESTMETHOD_AFTER = @"<Member MemberName=""BeginRead""> + <MemberType>Method</MemberType> + <ReturnValue> + <ReturnType>System.IAsyncResult</ReturnType> + </ReturnValue> + <Parameters> + <Parameter Name = ""buffer"" Type=""System.Byte[]"" Index=""0"" FrameworkAlternate=""One;Three"" /> + <Parameter Name = ""array"" Type=""System.Byte[]"" Index=""0"" FrameworkAlternate=""Two"" /> + <Parameter Name = ""offset"" Type=""System.Int32"" Index=""1"" /> + <Parameter Name = ""count"" Type=""System.Int32"" Index=""2"" /> + <Parameter Name = ""asyncCallback"" Type=""System.AsyncCallback"" Index=""3"" FrameworkAlternate=""One;Two"" /> + <Parameter Name = ""cback"" Type=""System.AsyncCallback"" Index=""3"" FrameworkAlternate=""Three"" /> + <Parameter Name = ""asyncState"" Type=""System.Object"" Index=""4"" FrameworkAlternate=""One;Two"" /> + <Parameter Name = ""state"" Type=""System.Object"" Index=""4"" FrameworkAlternate=""Three"" /> + </Parameters> + </Member>"; + #endregion #region Framework diff --git a/mdoc/mdoc.Test/XmlUpdateTests.cs b/mdoc/mdoc.Test/XmlUpdateTests.cs index a562b29b..11726e38 100644 --- a/mdoc/mdoc.Test/XmlUpdateTests.cs +++ b/mdoc/mdoc.Test/XmlUpdateTests.cs @@ -2,6 +2,7 @@ using System; using Mono.Documentation; using System.Xml; +using System.Xml.XPath; using System.Linq; using Mono.Cecil; using System.Collections.Generic; @@ -25,6 +26,10 @@ namespace mdoc.Test public void Meth (int a, string b, int c) { } } + public class MyComplicatedClass + { + public IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback cback, object state) => null; + } } namespace mdoc.Test2 @@ -70,6 +75,8 @@ namespace mdoc.Test var context = InitContext <MyClass>(startingEmptyXml, 0); FrameworkTypeEntry typeEntry = context.fx.Frameworks[0].Types.First (); + context.fx.Frameworks.RemoveAt(2); + context.fx.Frameworks.RemoveAt(1); bool fxAlternateTriggered = false; context.updater.MakeParameters (context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry, ref fxAlternateTriggered); @@ -81,38 +88,6 @@ namespace mdoc.Test } [Test ()] - public void Parameters_Updating_Normal2 () - { - var context = InitContext <MyClass>(normalSingleXml,1); - - FrameworkTypeEntry typeEntry = context.fx.Frameworks[1].Types.First (); - bool fxAlternateTriggered = false; - - context.updater.MakeParameters (context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry, ref fxAlternateTriggered); - - var afterXML = context.doc.OuterXml; - - Assert.AreEqual (Normalize (normalSingleXml), afterXML); - - } - - [Test ()] - public void Parameters_Updating_Normal3 () - { - var context = InitContext <MyClass>(normalSingleXml, 2); - - FrameworkTypeEntry typeEntry = context.fx.Frameworks[2].Types.First (); - bool fxAlternateTriggered = false; - - context.updater.MakeParameters (context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry, ref fxAlternateTriggered); - - var afterXML = context.doc.OuterXml; - - Assert.AreEqual (Normalize (multiFrameworkXml), afterXML); - - } - - [Test ()] public void Parameters_Updating_Existing_MultiFramework () { var context = InitContext <MyClass>(multiFrameworkXml, 0); @@ -124,44 +99,11 @@ namespace mdoc.Test var afterXML = context.doc.OuterXml; - Assert.AreEqual (context.beforeXML, Normalize(afterXML)); - - } - - [Test ()] - public void Parameters_Updating_Existing_MultiFramework2 () - { - var context = InitContext <MyClass>(multiFrameworkXml, 2); - - FrameworkTypeEntry typeEntry = context.fx.Frameworks[2].Types.First (); - bool fxAlternateTriggered = false; - - context.updater.MakeParameters (context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry, ref fxAlternateTriggered); - - var afterXML = context.doc.OuterXml; - - Assert.AreEqual (context.beforeXML, Normalize (afterXML)); - - } - - - - [Test ()] - public void Parameters_Updating_Existing_Align () - { - var context = InitContext<MyClass> (multiFrameworkXml, 2, forceAlignment: true); - - FrameworkTypeEntry typeEntry = context.fx.Frameworks[2].Types.First (); - bool fxAlternateTriggered = false; - - context.updater.MakeParameters (context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry, ref fxAlternateTriggered); - - var afterXML = context.doc.OuterXml; - - Assert.IsFalse (fxAlternateTriggered); - Assert.AreEqual (Normalize (multiFrameworkAligned), Normalize (afterXML)); + // the original state was cleared out on account that this was the first of the frameworks + Assert.AreEqual (Normalize(XmlConsts.NormalSingleXml), Normalize(afterXML)); } + #endregion #region MyClass2 tests @@ -214,6 +156,40 @@ namespace mdoc.Test } + [Test()] + public void Parameters_Updating_BeginRead() + { + FrameworkIndex fx = new FrameworkIndex("", 3); + + fx.Frameworks.Add(new FrameworkEntry(fx.Frameworks) { Id = "One", Name = "One", Replace = "mdoc.Test2", With = "mdoc.Test" }); + fx.Frameworks.Add(new FrameworkEntry(fx.Frameworks) { Id = "Two", Name = "Two", Replace = "mdoc.Test2", With = "mdoc.Test" }); + fx.Frameworks.Add(new FrameworkEntry(fx.Frameworks) { Id = "Three", Name = "Three", Replace = "mdoc.Test2", With = "mdoc.Test" }); + + var context = InitComplexContext<MyComplicatedClass>(XmlConsts.XML_METHOD_TESTMETHOD_BEFORE, "mdoc.Test", "BeginRead", fx); + var theType = context.method.DeclaringType.Resolve(); + + foreach (var it in fx.Frameworks) + { + var t = it.ProcessType(theType); + foreach(var m in theType.Methods) + { + t.ProcessMember(m); + } + } + + var typeEntry = context.fx.Frameworks[2].Types.First(); + + bool fxAlternateTriggered = true; + + context.updater.MakeParameters(context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry, ref fxAlternateTriggered); + + var afterXML = context.doc.OuterXml; + + // TODO: make representative post-method XML + Assert.AreEqual(Normalize(XmlConsts.XML_METHOD_TESTMETHOD_AFTER), afterXML); + + } + [Test ()] public void Parameters_Updating_Existing_MultiFramework22 () { @@ -226,7 +202,7 @@ namespace mdoc.Test var afterXML = context.doc.OuterXml; - Assert.AreEqual (context.beforeXML, Normalize (afterXML)); + Assert.AreEqual (Normalize(XmlConsts.NormalSingleXml2), Normalize (afterXML)); } @@ -276,15 +252,16 @@ namespace mdoc.Test Func<int, FrameworkTypeEntry> typeEntry = i => context.fx.Frameworks[i].Types.First (); bool fxAlternateTriggered = false; context.updater.MakeParameters (context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry(0), ref fxAlternateTriggered); - Assert.IsTrue (fxAlternateTriggered); + // this will be false, since it clears out the parameters list on the first run + Assert.IsFalse (fxAlternateTriggered, "first run"); fxAlternateTriggered = false; context.updater.MakeParameters (context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry (1), ref fxAlternateTriggered); - Assert.IsFalse (fxAlternateTriggered); + Assert.IsFalse (fxAlternateTriggered, "second run"); fxAlternateTriggered = false; context.updater.MakeParameters (context.doc.FirstChild as XmlElement, context.method, context.parameters, typeEntry (2), ref fxAlternateTriggered); - Assert.IsFalse (fxAlternateTriggered); + Assert.IsFalse (fxAlternateTriggered, "third run"); var afterXML = context.doc.OuterXml; Assert.AreEqual (Normalize (XmlConsts.MultiFrameworkAlignedOther), Normalize (afterXML)); @@ -731,10 +708,11 @@ namespace mdoc.Test Assert.IsTrue (attributes[0].HasAttribute (Consts.FrameworkAlternate)); } - string Normalize(string xml) { + string Normalize(string xml, bool clearFx = false) { XmlDocument doc = new XmlDocument (); doc.LoadXml (xml); + return doc.OuterXml; } string typeFrameXml = @"<Type><Members>{0}</Members></Type>"; @@ -792,7 +770,7 @@ namespace mdoc.Test </ReturnValue> <Parameters> <Parameter Name = ""a"" Type=""System.Int32"" Index=""0"" /> - <Parameter Name = ""d"" Type=""System.String"" Index=""1"" FrameworkAlternate=""One;Three;Two"" /> + <Parameter Name = ""d"" Type=""System.String"" Index=""1"" /> <Parameter Name = ""c"" Type=""System.Int32"" Index=""2"" /> </Parameters> <Docs> @@ -826,6 +804,27 @@ namespace mdoc.Test </Member>"; + private ParamContext InitComplexContext<T>(string methodXml, string ns, string methodName, FrameworkIndex fx) + { + var doc = new XmlDocument(); + doc.LoadXml(methodXml); + var beforeXML = doc.OuterXml; + + TypeDefinition type = GetDefinition<T>(ns); + var method = type.Methods.First(m => m.Name == methodName) as MethodReference; + + var updater = new MDocUpdater(); + + return new ParamContext() + { + doc = doc, + beforeXML = beforeXML, + method = method, + parameters = method.Parameters.ToList(), + fx = fx, + updater = updater + }; + } private ParamContext InitContext <T>(string methodXml, int fxIndex, bool forceAlignment=false) { |