|
24 | 24 |
|
25 | 25 | namespace Mono.Documentation |
26 | 26 | { |
27 | | - public class MDocUpdater : MDocCommand |
| 27 | + public partial class MDocUpdater : MDocCommand |
28 | 28 | { |
29 | 29 | string srcPath; |
30 | 30 | List<AssemblySet> assemblies = new List<AssemblySet> (); |
@@ -2181,7 +2181,10 @@ public void UpdateType (XmlElement root, TypeDefinition type, FrameworkTypeEntry |
2181 | 2181 |
|
2182 | 2182 | if (type.IsGenericType ()) |
2183 | 2183 | { |
2184 | | - MakeTypeParameters (typeEntry, root, type.GenericParameters, type, MDocUpdater.HasDroppedNamespace (type)); |
| 2184 | + if (!DocUtils.IsDelegate(type)) |
| 2185 | + { |
| 2186 | + MakeTypeParameters(typeEntry, root, type.GenericParameters, type, MDocUpdater.HasDroppedNamespace(type)); |
| 2187 | + } |
2185 | 2188 | } |
2186 | 2189 | else |
2187 | 2190 | { |
@@ -3279,14 +3282,6 @@ internal static XmlElement WriteElementWithSubElementText(XmlNode parent, string |
3279 | 3282 | return element; |
3280 | 3283 | } |
3281 | 3284 |
|
3282 | | - static XmlElement AppendElementText (XmlNode parent, string element, string value) |
3283 | | - { |
3284 | | - XmlElement n = parent.OwnerDocument.CreateElement (element); |
3285 | | - parent.AppendChild (n); |
3286 | | - n.InnerText = value; |
3287 | | - return n; |
3288 | | - } |
3289 | | - |
3290 | 3285 | static XmlElement AppendElementAttributeText (XmlNode parent, string element, string attribute, string value) |
3291 | 3286 | { |
3292 | 3287 | XmlElement n = parent.OwnerDocument.CreateElement (element); |
@@ -3959,9 +3954,10 @@ public void MakeParameters (XmlElement root, MemberReference member, IList<Param |
3959 | 3954 | .Select ((n, i) => |
3960 | 3955 | { |
3961 | 3956 | int actualIndex = i; |
3962 | | - if (n.HasAttribute (Consts.Index)) |
3963 | | - int.TryParse (n.GetAttribute (Consts.Index), out actualIndex); |
3964 | | - |
| 3957 | + if (n.HasAttribute (Consts.Index) && int.TryParse(n.GetAttribute(Consts.Index), out int index)) |
| 3958 | + { |
| 3959 | + actualIndex = index; |
| 3960 | + } |
3965 | 3961 |
|
3966 | 3962 | return new |
3967 | 3963 | { |
@@ -4072,121 +4068,89 @@ public void MakeParameters (XmlElement root, MemberReference member, IList<Param |
4072 | 4068 |
|
4073 | 4069 | if (typeEntry.Framework.IsLastFrameworkForType(typeEntry)) |
4074 | 4070 | { |
4075 | | - // Now clean up |
4076 | | - var allFrameworks = typeEntry.Framework.AllFrameworksWithType(typeEntry); |
4077 | | - var finalNodes = paramNodes |
4078 | | - .Cast<XmlElement> ().ToArray (); |
4079 | | - foreach (var parameter in finalNodes) |
4080 | | - { |
4081 | | - // if FXAlternate is entire list, just remove it |
4082 | | - if (parameter.HasAttribute (Consts.FrameworkAlternate) && parameter.GetAttribute (Consts.FrameworkAlternate) == allFrameworks) |
4083 | | - { |
4084 | | - parameter.RemoveAttribute (Consts.FrameworkAlternate); |
4085 | | - } |
4086 | | - } |
4087 | | - |
4088 | | - // if there are no fx attributes left, just remove the indices entirely |
4089 | | - if (!finalNodes.Any (n => n.HasAttribute (Consts.FrameworkAlternate))) |
4090 | | - { |
4091 | | - foreach (var parameter in finalNodes) |
4092 | | - parameter.RemoveAttribute (Consts.Index); |
4093 | | - } |
| 4071 | + ClearFrameworkAlternateIfAll(e, "Parameter", typeEntry.Framework.AllFrameworksWithType(typeEntry)); |
4094 | 4072 | } |
4095 | 4073 | } |
4096 | 4074 |
|
4097 | 4075 | private void MakeTypeParameters (FrameworkTypeEntry entry, XmlElement root, IList<GenericParameter> typeParams, MemberReference member, bool shouldDuplicateWithNew) |
4098 | 4076 | { |
4099 | | - if (typeParams == null || typeParams.Count == 0) |
| 4077 | + if (typeParams == null || typeParams.Count == 0 || ProcessedMoreThanOnce(entry)) |
4100 | 4078 | { |
4101 | | - XmlElement f = (XmlElement)root.SelectSingleNode ("TypeParameters"); |
4102 | | - if (f != null) |
4103 | | - root.RemoveChild (f); |
4104 | 4079 | return; |
4105 | 4080 | } |
4106 | 4081 |
|
4107 | | - XmlElement e = WriteElement (root, "TypeParameters"); |
| 4082 | + XmlElement e = WriteElement(root, "TypeParameters"); |
4108 | 4083 |
|
4109 | | - var nodes = e.SelectNodes ("TypeParameter").Cast<XmlElement> ().ToArray (); |
4110 | | - |
4111 | | - foreach (GenericParameter t in typeParams) |
| 4084 | + if (DocUtils.IsMemberOnFirstFramework(entry, member)) |
4112 | 4085 | { |
| 4086 | + e.RemoveAll(); |
| 4087 | + } |
4113 | 4088 |
|
| 4089 | + var nodes = e.SelectNodes("TypeParameter") |
| 4090 | + .Cast<XmlElement>() |
| 4091 | + .Select((n, i) => |
| 4092 | + { |
| 4093 | + int index = i; |
| 4094 | + if (n.HasAttribute(Consts.Index) && int.TryParse(n.GetAttribute(Consts.Index), out int result)) |
| 4095 | + { |
| 4096 | + index = result; |
| 4097 | + } |
| 4098 | + |
| 4099 | + return new |
| 4100 | + { |
| 4101 | + Element = n, |
| 4102 | + Name = n.GetAttribute("Name"), |
| 4103 | + Index = index, |
| 4104 | + FrameworkAlternates = n.GetAttribute(Consts.FrameworkAlternate) |
| 4105 | + }; |
| 4106 | + }) |
| 4107 | + .ToArray(); |
| 4108 | + |
| 4109 | + for (int i = 0; i < typeParams.Count; i++) |
| 4110 | + { |
| 4111 | + var t = typeParams[i]; |
4114 | 4112 | #if NEW_CECIL |
4115 | 4113 | Mono.Collections.Generic.Collection<GenericParameterConstraint> constraints = t.Constraints; |
4116 | 4114 | #else |
4117 | 4115 | IList<TypeReference> constraints = t.Constraints; |
4118 | 4116 | #endif |
4119 | 4117 | GenericParameterAttributes attrs = t.Attributes; |
4120 | 4118 |
|
4121 | | - var existing = nodes.FirstOrDefault(x => x.GetAttribute("Name") == t.Name); |
| 4119 | + var existing = nodes.Where(node => node.Name == t.Name && node.Index == i).FirstOrDefault(); |
4122 | 4120 | if (existing != null) |
4123 | 4121 | { |
4124 | | - MakeParamsAttributes(existing, AttributeFormatter.PreProcessCustomAttributes(t.CustomAttributes), entry, member); |
| 4122 | + var xElement = existing.Element; |
| 4123 | + var fxaValue = FXUtils.AddFXToList(existing.FrameworkAlternates, entry.Framework.Name); |
| 4124 | + xElement.RemoveAttribute(Consts.Index); |
| 4125 | + xElement.SetAttribute(Consts.Index, i.ToString()); |
| 4126 | + xElement.RemoveAttribute(Consts.FrameworkAlternate); |
| 4127 | + xElement.SetAttribute(Consts.FrameworkAlternate, fxaValue); |
| 4128 | + MakeParamsAttributes(existing.Element, AttributeFormatter.PreProcessCustomAttributes(t.CustomAttributes), entry, member); |
4125 | 4129 | } |
4126 | 4130 | else |
4127 | 4131 | { |
4128 | 4132 | XmlElement pe = root.OwnerDocument.CreateElement("TypeParameter"); |
4129 | | - e.AppendChild(pe); |
4130 | | - pe.SetAttribute("Name", t.Name); |
4131 | | - MakeParamsAttributes(pe, AttributeFormatter.PreProcessCustomAttributes(t.CustomAttributes), entry, member); |
4132 | | - XmlElement ce = (XmlElement)e.SelectSingleNode("Constraints"); |
4133 | | - if (attrs == GenericParameterAttributes.NonVariant && constraints.Count == 0) |
| 4133 | + var sameIndexElements = nodes.Where(node => node.Index == i).ToArray(); |
| 4134 | + if (sameIndexElements != null && sameIndexElements.Length > 0) |
4134 | 4135 | { |
4135 | | - if (ce != null) |
4136 | | - e.RemoveChild(ce); |
| 4136 | + // order the type parameters by index |
| 4137 | + e.InsertAfter(pe, sameIndexElements.Last().Element); |
4137 | 4138 | } |
4138 | | - if (ce != null) |
4139 | | - ce.RemoveAll(); |
4140 | 4139 | else |
4141 | 4140 | { |
4142 | | - ce = root.OwnerDocument.CreateElement("Constraints"); |
4143 | | - } |
4144 | | - if ((attrs & GenericParameterAttributes.Contravariant) != 0) |
4145 | | - AppendElementText(ce, "ParameterAttribute", "Contravariant"); |
4146 | | - if ((attrs & GenericParameterAttributes.Covariant) != 0) |
4147 | | - AppendElementText(ce, "ParameterAttribute", "Covariant"); |
4148 | | - if ((attrs & GenericParameterAttributes.DefaultConstructorConstraint) != 0) |
4149 | | - AppendElementText(ce, "ParameterAttribute", "DefaultConstructorConstraint"); |
4150 | | - if ((attrs & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) |
4151 | | - AppendElementText(ce, "ParameterAttribute", "NotNullableValueTypeConstraint"); |
4152 | | - if ((attrs & GenericParameterAttributes.ReferenceTypeConstraint) != 0) |
4153 | | - AppendElementText(ce, "ParameterAttribute", "ReferenceTypeConstraint"); |
4154 | | - |
4155 | | -#if NEW_CECIL |
4156 | | - foreach (GenericParameterConstraint c in constraints) |
4157 | | - { |
4158 | | - TypeDefinition cd = c.ConstraintType.Resolve (); |
4159 | | - AppendElementText (ce, |
4160 | | - (cd != null && cd.IsInterface) ? "InterfaceName" : "BaseTypeName", |
4161 | | - GetDocTypeFullName (c.ConstraintType)); |
4162 | | - } |
4163 | | -#else |
4164 | | - foreach (TypeReference c in constraints) |
4165 | | - { |
4166 | | - TypeDefinition cd = c.Resolve(); |
4167 | | - AppendElementText(ce, |
4168 | | - (cd != null && cd.IsInterface) ? "InterfaceName" : "BaseTypeName", |
4169 | | - GetDocTypeFullName(c)); |
4170 | | - } |
4171 | | -#endif |
4172 | | - if (ce.HasChildNodes) |
4173 | | - { |
4174 | | - pe.AppendChild(ce); |
| 4141 | + e.AppendChild(pe); |
4175 | 4142 | } |
| 4143 | + pe.SetAttribute("Name", t.Name); |
| 4144 | + pe.SetAttribute(Consts.Index, i.ToString()); |
| 4145 | + pe.SetAttribute(Consts.FrameworkAlternate, entry.Framework.Name); |
| 4146 | + MakeParamsAttributes(pe, AttributeFormatter.PreProcessCustomAttributes(t.CustomAttributes), entry, member); |
| 4147 | + MakeTypeParameterConstraints(root, e, pe, t); |
4176 | 4148 | } |
4177 | 4149 | } |
4178 | 4150 |
|
4179 | | - nodes = e.SelectNodes("TypeParameter").Cast<XmlElement>().ToArray(); |
4180 | | - if (nodes.Length != typeParams.Count) |
| 4151 | + if (DocUtils.IsMemberOnLastFramework(entry, member)) |
4181 | 4152 | { |
4182 | | - foreach (var node in nodes) |
4183 | | - { |
4184 | | - var existing = typeParams.FirstOrDefault(x => x.Name == node.GetAttribute("Name")); |
4185 | | - if (existing == null) |
4186 | | - { |
4187 | | - node.ParentNode.RemoveChild(node); |
4188 | | - } |
4189 | | - } |
| 4153 | + ClearFrameworkAlternateIfAll(e, "TypeParameter", DocUtils.GetAllFrameworksString(entry, member)); |
4190 | 4154 | } |
4191 | 4155 | } |
4192 | 4156 |
|
|
0 commit comments