diff options
author | Tianqi Zhang <tianzh@microsoft.com> | 2020-06-10 06:07:55 +0300 |
---|---|---|
committer | Joel Martinez <joelmartinez@gmail.com> | 2020-06-10 18:23:10 +0300 |
commit | eaba6771fbf0fe994accb8e17fe274474e8dee79 (patch) | |
tree | dd9d7c76df8304518b371f3a452570b3e4f7f819 /mdoc | |
parent | 5721d52f5ffa2c6100886ea47f7db4ba4264e28c (diff) |
refactor attribute formatter to be standalone class
Diffstat (limited to 'mdoc')
21 files changed, 240 insertions, 238 deletions
diff --git a/mdoc/Mono.Documentation/MDocUpdater.cs b/mdoc/Mono.Documentation/MDocUpdater.cs index 3734016c..86318b4b 100644 --- a/mdoc/Mono.Documentation/MDocUpdater.cs +++ b/mdoc/Mono.Documentation/MDocUpdater.cs @@ -43,6 +43,8 @@ namespace Mono.Documentation DocumentationEnumerator docEnum; + AttributeFormatter attributeFormatter = new AttributeFormatter(); + string since; static MemberFormatter docTypeFormatterField; @@ -73,18 +75,6 @@ namespace Mono.Documentation "System.Runtime.InteropServices.TypeIdentifierAttribute" }; - internal static MemberFormatter slashdocFormatterField; - internal static MemberFormatter slashdocFormatter - { - get - { - if (slashdocFormatterField == null) - slashdocFormatterField = new SlashDocMemberFormatter(MDocUpdater.Instance.TypeMap); - - return slashdocFormatterField; - } - } - internal static MemberFormatter csharpSlashdocFormatterField; internal static MemberFormatter csharpSlashdocFormatter { @@ -334,10 +324,7 @@ namespace Mono.Documentation Console.WriteLine($"Loading typemap file at {typeMapPath}"); TypeMap map = TypeMap.FromXml(typeMapPath); this.TypeMap = map; - - foreach (var f in FormatterManager.TypeFormatters.Union(FormatterManager.MemberFormatters)) - f.TypeMap = map; - + FormatterManager.UpdateTypeMap(map); } Console.WriteLine($"Opening frameworks file '{configPath}'"); @@ -1013,7 +1000,7 @@ namespace Mono.Documentation index_assembly.AppendChild (culture); } - MakeAttributes (index_assembly, GetCustomAttributes (assembly.CustomAttributes, ""), fx, typeEntry: null, assemblyName: assembly.Name.Name); + MakeAttributes (index_assembly, attributeFormatter.GetCustomAttributes(assembly.CustomAttributes, ""), fx, typeEntry: null, assemblyName: assembly.Name.Name); parent.AppendChild (index_assembly); } @@ -1297,12 +1284,6 @@ namespace Mono.Documentation throw new ArgumentException ("Unknown kind for type: " + type.FullName); } - [Obsolete("Use DocUtils.IsPublic instead")] - public static bool IsPublic (TypeDefinition type) - { - return DocUtils.IsPublic (type); - } - private void CleanupFiles (string dest, HashSet<string> goodfiles) { // Look for files that no longer correspond to types @@ -2234,7 +2215,7 @@ namespace Mono.Documentation ClearElement (root, "Interfaces"); } - MakeAttributes (root, GetCustomAttributes (type), typeEntry.Framework, typeEntry); + MakeAttributes (root, attributeFormatter.GetCustomAttributes(type), typeEntry.Framework, typeEntry); if (DocUtils.IsDelegate (type)) {
@@ -2448,7 +2429,7 @@ namespace Mono.Documentation ClearElement (me, "AssemblyInfo"); } - MakeAttributes (me, GetCustomAttributes (mi), typeEntry.Framework, typeEntry); + MakeAttributes (me, attributeFormatter.GetCustomAttributes(mi), typeEntry.Framework, typeEntry); MakeReturnValue (typeEntry, me, mi, MDocUpdater.HasDroppedNamespace (mi)); if (mi is MethodReference) @@ -2920,92 +2901,6 @@ namespace Mono.Documentation } } - IEnumerable<string> GetCustomAttributes (MemberReference mi) - { - IEnumerable<string> attrs = Enumerable.Empty<string> (); - - ICustomAttributeProvider p = mi as ICustomAttributeProvider; - if (p != null) - attrs = attrs.Concat (GetCustomAttributes (p.CustomAttributes, "")); - - TypeDefinition typeDefinition = mi as TypeDefinition; - if (typeDefinition != null && typeDefinition.IsSerializable) - { - attrs = attrs.Concat (new[] { "System.Serializable" }); - } - - PropertyDefinition pd = mi as PropertyDefinition; - if (pd != null) - { - if (pd.GetMethod != null) - attrs = attrs.Concat (GetCustomAttributes (pd.GetMethod.CustomAttributes, "get: ")); - if (pd.SetMethod != null) - attrs = attrs.Concat (GetCustomAttributes (pd.SetMethod.CustomAttributes, "set: ")); - } - - EventDefinition ed = mi as EventDefinition; - if (ed != null) - { - if (ed.AddMethod != null) - attrs = attrs.Concat (GetCustomAttributes (ed.AddMethod.CustomAttributes, "add: ")); - if (ed.RemoveMethod != null) - attrs = attrs.Concat (GetCustomAttributes (ed.RemoveMethod.CustomAttributes, "remove: ")); - } - - return attrs; - } - - public IEnumerable<string> GetCustomAttributes (IList<CustomAttribute> attributes, string prefix) - { - foreach (CustomAttribute attribute in attributes.OrderBy (ca => ca.AttributeType.FullName).Where (i => !IsIgnoredAttribute(i))) - { - TypeDefinition attrType = attribute.AttributeType as TypeDefinition; - if (attrType != null && !IsPublic (attrType)) - continue; - if (slashdocFormatter.GetName (attribute.AttributeType) == null) - continue; - - if (Array.IndexOf (IgnorableAttributes, attribute.AttributeType.FullName) >= 0) - continue; - - StringList fields = new StringList (); - - for (int i = 0; i < attribute.ConstructorArguments.Count; ++i) - { - CustomAttributeArgument argument = attribute.ConstructorArguments[i]; - fields.Add (MakeAttributesValueString ( - argument.Value, - argument.Type)); - } - var namedArgs = - (from namedArg in attribute.Fields - select new { Type = namedArg.Argument.Type, Name = namedArg.Name, Value = namedArg.Argument.Value }) - .Concat ( - (from namedArg in attribute.Properties - select new { Type = namedArg.Argument.Type, Name = namedArg.Name, Value = namedArg.Argument.Value })) - .OrderBy (v => v.Name); - foreach (var d in namedArgs) - fields.Add (string.Format ("{0}={1}", d.Name, - MakeAttributesValueString (d.Value, d.Type))); - - string a2 = String.Join (", ", fields.ToArray ()); - if (a2 != "") a2 = "(" + a2 + ")"; - - string name = attribute.GetDeclaringType (); - if (name.EndsWith ("Attribute")) name = name.Substring (0, name.Length - "Attribute".Length); - yield return prefix + name + a2; - } - } - - private bool IsIgnoredAttribute (CustomAttribute customAttribute) - { - // An Obsolete attribute with a known string is added to all ref-like structs - // https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/span-safety.md#metadata-representation-or-ref-like-structs - return customAttribute.AttributeType.FullName == typeof(ObsoleteAttribute).FullName - && customAttribute.HasConstructorArguments - && customAttribute.ConstructorArguments.First().Value.ToString() == Consts.RefTypeObsoleteString; - } - static readonly string[] ValidExtensionMembers = { "Docs", "MemberSignature", @@ -3041,8 +2936,8 @@ namespace Mono.Documentation RemoveExcept (member.SelectSingleNode ("Docs"), ValidExtensionDocMembers); WriteElementText (member, "MemberType", "ExtensionMethod"); XmlElement link = member.OwnerDocument.CreateElement ("Link"); - var linktype = slashdocFormatter.GetName (me.DeclaringType); - var linkmember = slashdocFormatter.GetDeclaration (me); + var linktype = FormatterManager.SlashdocFormatter.GetName (me.DeclaringType); + var linkmember = FormatterManager.SlashdocFormatter.GetDeclaration (me); link.SetAttribute ("Type", linktype); link.SetAttribute ("Member", linkmember); member.AppendChild (link); @@ -3082,8 +2977,8 @@ namespace Mono.Documentation var reference = info.Parameters[0].ParameterType; TypeReference typeReference = reference as TypeReference; var declaration = reference != null ? - slashdocFormatter.GetDeclaration (typeReference) : - slashdocFormatter.GetDeclaration (reference); + FormatterManager.SlashdocFormatter.GetDeclaration (typeReference) : + FormatterManager.SlashdocFormatter.GetDeclaration (reference); AppendElementAttributeText (targets, "Target", "Type", declaration); } @@ -3107,7 +3002,7 @@ namespace Mono.Documentation #else foreach (TypeReference c in constraints) AppendElementAttributeText (targets, "Target", "Type", - slashdocFormatter.GetDeclaration (c)); + FormatterManager.SlashdocFormatter.GetDeclaration (c)); #endif } } @@ -3608,7 +3503,7 @@ namespace Mono.Documentation string indent = new string (' ', 10); foreach (var source in new ExceptionLookup (exceptions.Value)[member]) { - string cref = slashdocFormatter.GetDeclaration (source.Exception); + string cref = FormatterManager.SlashdocFormatter.GetDeclaration (source.Exception); var node = docs.SelectSingleNode ("exception[@cref='" + cref + "']"); if (node != null) continue; @@ -3731,32 +3626,6 @@ namespace Mono.Documentation return anyNodesLeft; } - // FIXME: get TypeReferences instead of string comparison? - private static string[] IgnorableAttributes = { - // Security related attributes - "System.Reflection.AssemblyKeyFileAttribute", - "System.Reflection.AssemblyDelaySignAttribute", - // Present in @RefType - "System.Runtime.InteropServices.OutAttribute", - // For naming the indexer to use when not using indexers - "System.Reflection.DefaultMemberAttribute", - // for decimal constants - "System.Runtime.CompilerServices.DecimalConstantAttribute", - // compiler generated code - Consts.CompilerGeneratedAttribute, - // more compiler generated code, e.g. iterator methods - "System.Diagnostics.DebuggerHiddenAttribute", - "System.Runtime.CompilerServices.FixedBufferAttribute", - "System.Runtime.CompilerServices.UnsafeValueTypeAttribute", - "System.Runtime.CompilerServices.AsyncStateMachineAttribute", - // extension methods - "System.Runtime.CompilerServices.ExtensionAttribute", - // Used to differentiate 'object' from C#4 'dynamic' - "System.Runtime.CompilerServices.DynamicAttribute", - // F# compiler attribute - "Microsoft.FSharp.Core.CompilationMapping", - }; - public static string FilterSpecialChars (string value) { return new string (FilterSpecialCharsCore (value).ToArray()); @@ -3801,9 +3670,6 @@ namespace Mono.Documentation public static void MakeAttributes (XmlElement root, IEnumerable<string> attributes, FrameworkEntry fx, FrameworkTypeEntry typeEntry, string assemblyName=null) { XmlElement e = (XmlElement)root.SelectSingleNode ("Attributes"); - bool noAttributes = attributes.Any (); - bool currentlyHasAttributes = e != null && e.ChildNodes.Count > 0; - if (e == null) e = root.OwnerDocument.CreateElement ("Attributes"); @@ -3922,59 +3788,6 @@ namespace Mono.Documentation return; } - public static string MakeAttributesValueString (object v, TypeReference valueType) - { - var formatters = new[] { - new AttributeValueFormatter (), - new ApplePlatformEnumFormatter (), - new StandardFlagsEnumFormatter (), - new DefaultAttributeValueFormatter (), - }; - - ResolvedTypeInfo type = new ResolvedTypeInfo (valueType); - - if (valueType is ArrayType && v is CustomAttributeArgument[]) - { - ArrayType atype = valueType as ArrayType; - CustomAttributeArgument[] args = v as CustomAttributeArgument[]; - var returnvalue = $"new {atype.FullName}{(atype.FullName.EndsWith ("[]") ? "" : "[]")} {{ { string.Join (", ", args.Select (a => MakeAttributesValueString (a.Value, a.Type)).ToArray ()) } }}"; - return returnvalue; - } - - foreach (var formatter in formatters) - { - string formattedValue; - if (formatter.TryFormatValue (v, type, out formattedValue)) - { - return formattedValue; - } - } - - // this should never occur because the DefaultAttributeValueFormatter will always - // successfully format the value ... but this is needed to satisfy the compiler :) - throw new InvalidDataException (string.Format ("Unable to format attribute value ({0})", v.ToString ())); - } - - internal static IDictionary<long, string> GetEnumerationValues (TypeDefinition type) - { - var values = new Dictionary<long, string> (); - foreach (var f in - (from f in type.Fields - where !(f.IsRuntimeSpecialName || f.IsSpecialName) - select f)) - { - values[ToInt64 (f.Constant)] = f.Name; - } - return values; - } - - internal static long ToInt64 (object value) - { - if (value is ulong) - return (long)(ulong)value; - return Convert.ToInt64 (value); - } - public void MakeParameters (XmlElement root, MemberReference member, IList<ParameterDefinition> parameters, FrameworkTypeEntry typeEntry, ref bool fxAlternateTriggered, bool shouldDuplicateWithNew = false) { if (typeEntry.TimesProcessed > 1) @@ -4012,7 +3825,7 @@ namespace Mono.Documentation //if (addfx) pe.SetAttribute (Consts.FrameworkAlternate, fx); - MakeAttributes (pe, GetCustomAttributes (param.CustomAttributes, ""), typeEntry.Framework, typeEntry); + MakeAttributes (pe, attributeFormatter.GetCustomAttributes(param.CustomAttributes, ""), typeEntry.Framework, typeEntry); }; /// addFXAttributes, adds the index attribute to all existing elements. /// Used when we first detect the scenario which requires this. @@ -4225,7 +4038,7 @@ namespace Mono.Documentation XmlElement pe = root.OwnerDocument.CreateElement ("TypeParameter"); e.AppendChild (pe); pe.SetAttribute ("Name", t.Name); - MakeAttributes (pe, GetCustomAttributes (t.CustomAttributes, ""), entry.Framework, entry); + MakeAttributes (pe, attributeFormatter.GetCustomAttributes(t.CustomAttributes, ""), entry.Framework, entry); XmlElement ce = (XmlElement)e.SelectSingleNode ("Constraints"); if (attrs == GenericParameterAttributes.NonVariant && constraints.Count == 0) { @@ -4348,7 +4161,7 @@ namespace Mono.Documentation {
var newNode = WriteElementText(e, "ReturnType", valueToUse, forceNewElement: true);
if (attributes != null)
- MakeAttributes(e, GetCustomAttributes(attributes, ""), typeEntry.Framework, typeEntry);
+ MakeAttributes(e, attributeFormatter.GetCustomAttributes(attributes, ""), typeEntry.Framework, typeEntry);
return newNode;
}); diff --git a/mdoc/Mono.Documentation/Updater/Formatters/ApplePlatformEnumFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/ApplePlatformEnumFormatter.cs index ec3485df..55dd508f 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/ApplePlatformEnumFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/ApplePlatformEnumFormatter.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using Mono.Cecil; -
+ namespace Mono.Documentation.Updater -{
+{ /// <summary>A custom formatter for the ObjCRuntime.Platform enumeration.</summary> class ApplePlatformEnumFormatter : AttributeValueFormatter { @@ -17,8 +17,8 @@ namespace Mono.Documentation.Updater if (typename.Contains ("ObjCRuntime.Platform") && valueDef.CustomAttributes.Any (ca => ca.AttributeType.FullName == "System.FlagsAttribute")) { - var values = MDocUpdater.GetEnumerationValues (valueDef); - long c = MDocUpdater.ToInt64 (v); + var values = GetEnumerationValues (valueDef); + long c = ToInt64 (v); returnvalue = Format (c, values, typename); return true; diff --git a/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/AttributeFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/AttributeFormatter.cs new file mode 100644 index 00000000..a0200d0d --- /dev/null +++ b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/AttributeFormatter.cs @@ -0,0 +1,157 @@ +using Mono.Cecil; +using Mono.Documentation.Util; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Mono.Documentation.Updater.Formatters +{ + public class AttributeFormatter + { + public IEnumerable<string> GetCustomAttributes(MemberReference mi) + { + IEnumerable<string> attrs = Enumerable.Empty<string>(); + + ICustomAttributeProvider p = mi as ICustomAttributeProvider; + if (p != null) + attrs = attrs.Concat(GetCustomAttributes(p.CustomAttributes, "")); + + TypeDefinition typeDefinition = mi as TypeDefinition; + if (typeDefinition != null && typeDefinition.IsSerializable) + { + attrs = attrs.Concat(new[] { "System.Serializable" }); + } + + PropertyDefinition pd = mi as PropertyDefinition; + if (pd != null) + { + if (pd.GetMethod != null) + attrs = attrs.Concat(GetCustomAttributes(pd.GetMethod.CustomAttributes, "get: ")); + if (pd.SetMethod != null) + attrs = attrs.Concat(GetCustomAttributes(pd.SetMethod.CustomAttributes, "set: ")); + } + + EventDefinition ed = mi as EventDefinition; + if (ed != null) + { + if (ed.AddMethod != null) + attrs = attrs.Concat(GetCustomAttributes(ed.AddMethod.CustomAttributes, "add: ")); + if (ed.RemoveMethod != null) + attrs = attrs.Concat(GetCustomAttributes(ed.RemoveMethod.CustomAttributes, "remove: ")); + } + + return attrs; + } + + public IEnumerable<string> GetCustomAttributes(IList<CustomAttribute> attributes, string prefix) + { + foreach (CustomAttribute attribute in attributes.OrderBy(ca => ca.AttributeType.FullName).Where(i => !IsIgnoredAttribute(i))) + { + TypeDefinition attrType = attribute.AttributeType as TypeDefinition; + if (attrType != null && !DocUtils.IsPublic(attrType)) + continue; + if (FormatterManager.SlashdocFormatter.GetName(attribute.AttributeType) == null) + continue; + + if (Array.IndexOf(IgnorableAttributes, attribute.AttributeType.FullName) >= 0) + continue; + + var fields = new List<string>(); + + for (int i = 0; i < attribute.ConstructorArguments.Count; ++i) + { + CustomAttributeArgument argument = attribute.ConstructorArguments[i]; + fields.Add(MakeAttributesValueString( + argument.Value, + argument.Type)); + } + var namedArgs = + (from namedArg in attribute.Fields + select new { Type = namedArg.Argument.Type, Name = namedArg.Name, Value = namedArg.Argument.Value }) + .Concat( + (from namedArg in attribute.Properties + select new { Type = namedArg.Argument.Type, Name = namedArg.Name, Value = namedArg.Argument.Value })) + .OrderBy(v => v.Name); + foreach (var d in namedArgs) + fields.Add(string.Format("{0}={1}", d.Name, + MakeAttributesValueString(d.Value, d.Type))); + + string a2 = String.Join(", ", fields.ToArray()); + if (a2 != "") a2 = "(" + a2 + ")"; + + string name = attribute.GetDeclaringType(); + if (name.EndsWith("Attribute")) name = name.Substring(0, name.Length - "Attribute".Length); + yield return prefix + name + a2; + } + } + + public static string MakeAttributesValueString(object v, TypeReference valueType) + { + var formatters = new[] { + new AttributeValueFormatter (), + new ApplePlatformEnumFormatter (), + new StandardFlagsEnumFormatter (), + new DefaultAttributeValueFormatter (), + }; + + ResolvedTypeInfo type = new ResolvedTypeInfo(valueType); + + if (valueType is ArrayType && v is CustomAttributeArgument[]) + { + ArrayType atype = valueType as ArrayType; + CustomAttributeArgument[] args = v as CustomAttributeArgument[]; + var returnvalue = $"new {atype.FullName}{(atype.FullName.EndsWith("[]") ? "" : "[]")} {{ { string.Join(", ", args.Select(a => MakeAttributesValueString(a.Value, a.Type)).ToArray()) } }}"; + return returnvalue; + } + + foreach (var formatter in formatters) + { + string formattedValue; + if (formatter.TryFormatValue(v, type, out formattedValue)) + { + return formattedValue; + } + } + + // this should never occur because the DefaultAttributeValueFormatter will always + // successfully format the value ... but this is needed to satisfy the compiler :) + throw new InvalidDataException(string.Format("Unable to format attribute value ({0})", v.ToString())); + } + + private bool IsIgnoredAttribute(CustomAttribute customAttribute) + { + // An Obsolete attribute with a known string is added to all ref-like structs + // https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/span-safety.md#metadata-representation-or-ref-like-structs + return customAttribute.AttributeType.FullName == typeof(ObsoleteAttribute).FullName + && customAttribute.HasConstructorArguments + && customAttribute.ConstructorArguments.First().Value.ToString() == Consts.RefTypeObsoleteString; + } + + // FIXME: get TypeReferences instead of string comparison? + private static string[] IgnorableAttributes = { + // Security related attributes + "System.Reflection.AssemblyKeyFileAttribute", + "System.Reflection.AssemblyDelaySignAttribute", + // Present in @RefType + "System.Runtime.InteropServices.OutAttribute", + // For naming the indexer to use when not using indexers + "System.Reflection.DefaultMemberAttribute", + // for decimal constants + "System.Runtime.CompilerServices.DecimalConstantAttribute", + // compiler generated code + Consts.CompilerGeneratedAttribute, + // more compiler generated code, e.g. iterator methods + "System.Diagnostics.DebuggerHiddenAttribute", + "System.Runtime.CompilerServices.FixedBufferAttribute", + "System.Runtime.CompilerServices.UnsafeValueTypeAttribute", + "System.Runtime.CompilerServices.AsyncStateMachineAttribute", + // extension methods + "System.Runtime.CompilerServices.ExtensionAttribute", + // Used to differentiate 'object' from C#4 'dynamic' + "System.Runtime.CompilerServices.DynamicAttribute", + // F# compiler attribute + "Microsoft.FSharp.Core.CompilationMapping", + }; + } +} diff --git a/mdoc/Mono.Documentation/Updater/Formatters/AttributeValueFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/AttributeValueFormatter.cs index adefc633..e937e21d 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/AttributeValueFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/AttributeValueFormatter.cs @@ -1,11 +1,12 @@ using System; - +using System.Collections.Generic; +using System.Linq; using Mono.Cecil; using Mono.Documentation.Util; -
+ namespace Mono.Documentation.Updater -{
+{ /// <summary>Formats attribute values. Should return true if it is able to format the value.</summary> class AttributeValueFormatter { @@ -51,8 +52,8 @@ namespace Mono.Documentation.Updater } string typename = MDocUpdater.GetDocTypeFullName (valueType); - var values = MDocUpdater.GetEnumerationValues (valueDef); - long c = MDocUpdater.ToInt64 (v); + var values = GetEnumerationValues (valueDef); + long c = ToInt64 (v); if (values.ContainsKey (c)) { returnvalue = typename + "." + values[c]; @@ -62,5 +63,25 @@ namespace Mono.Documentation.Updater returnvalue = null; return false; } + + internal static IDictionary<long, string> GetEnumerationValues(TypeDefinition type) + { + var values = new Dictionary<long, string>(); + foreach (var f in + (from f in type.Fields + where !(f.IsRuntimeSpecialName || f.IsSpecialName) + select f)) + { + values[ToInt64(f.Constant)] = f.Name; + } + return values; + } + + internal static long ToInt64(object value) + { + if (value is ulong) + return (long)(ulong)value; + return Convert.ToInt64(value); + } } }
\ No newline at end of file diff --git a/mdoc/Mono.Documentation/Updater/Formatters/DefaultAttributeValueFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/DefaultAttributeValueFormatter.cs index f120b315..09c640a2 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/DefaultAttributeValueFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/DefaultAttributeValueFormatter.cs @@ -1,5 +1,5 @@ namespace Mono.Documentation.Updater -{
+{ /// <summary>The final value formatter in the pipeline ... if no other formatter formats the value, /// then this one will serve as the default implementation.</summary> class DefaultAttributeValueFormatter : AttributeValueFormatter diff --git a/mdoc/Mono.Documentation/Updater/Formatters/StandardFlagsEnumFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/StandardFlagsEnumFormatter.cs index 337b6877..16a1ebe0 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/StandardFlagsEnumFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/AttributeFormatters/StandardFlagsEnumFormatter.cs @@ -1,9 +1,9 @@ using System.Linq; using Mono.Cecil; -
+ namespace Mono.Documentation.Updater -{
+{ /// <summary>Flags enum formatter that assumes powers of two values.</summary> /// <remarks>As described here: https://msdn.microsoft.com/en-us/library/vstudio/ms229062(v=vs.100).aspx</remarks> class StandardFlagsEnumFormatter : AttributeValueFormatter @@ -16,8 +16,8 @@ namespace Mono.Documentation.Updater { string typename = MDocUpdater.GetDocTypeFullName (valueType); - var values = MDocUpdater.GetEnumerationValues (valueDef); - long c = MDocUpdater.ToInt64 (v); + var values = GetEnumerationValues (valueDef); + long c = ToInt64 (v); returnvalue = string.Join (" | ", (from i in values.Keys where (c & i) == i && i != 0 diff --git a/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs index dff0099d..e63529bd 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/CSharpFullMemberFormatter.cs @@ -5,10 +5,9 @@ using System.Linq; using System.Text; using Mono.Cecil; - using Mono.Documentation.Util; -namespace Mono.Documentation.Updater +namespace Mono.Documentation.Updater.Formatters { public class CSharpFullMemberFormatter : MemberFormatter { @@ -542,7 +541,7 @@ namespace Mono.Documentation.Updater buf.Append (parameter.Name); if (parameter.HasDefault && parameter.IsOptional && parameter.HasConstant) { - var ReturnVal = MDocUpdater.MakeAttributesValueString(parameter.Constant, parameter.ParameterType); + var ReturnVal = AttributeFormatter.MakeAttributesValueString(parameter.Constant, parameter.ParameterType); buf.AppendFormat (" = {0}", ReturnVal == "null" ? "default" : ReturnVal); } return buf; diff --git a/mdoc/Mono.Documentation/Updater/Formatters/CSharpMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/CSharpMemberFormatter.cs index aa0bc31c..2c118281 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/CSharpMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/CSharpMemberFormatter.cs @@ -2,7 +2,7 @@ using Mono.Cecil; -namespace Mono.Documentation.Updater +namespace Mono.Documentation.Updater.Formatters {
public class CSharpMemberFormatter : CSharpFullMemberFormatter { diff --git a/mdoc/Mono.Documentation/Updater/Formatters/CSharpNativeTypeMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/CSharpNativeTypeMemberFormatter.cs index 9d8c8bbb..a37f9848 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/CSharpNativeTypeMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/CSharpNativeTypeMemberFormatter.cs @@ -1,4 +1,4 @@ -namespace Mono.Documentation.Updater +namespace Mono.Documentation.Updater.Formatters {
class CSharpNativeTypeMemberFormatter : CSharpFullMemberFormatter { diff --git a/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppWinRtFullMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppWinRtFullMemberFormatter.cs index 08c2da19..c0316671 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppWinRtFullMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppWinRtFullMemberFormatter.cs @@ -103,7 +103,7 @@ namespace Mono.Documentation.Updater.Formatters.CppFormatters if (parameter.HasDefault && parameter.IsOptional && parameter.HasConstant) { - buf.AppendFormat(" = {0}", MDocUpdater.MakeAttributesValueString(parameter.Constant, parameter.ParameterType)); + buf.AppendFormat(" = {0}", AttributeFormatter.MakeAttributesValueString(parameter.Constant, parameter.ParameterType)); } return buf; diff --git a/mdoc/Mono.Documentation/Updater/Formatters/FormatterManager.cs b/mdoc/Mono.Documentation/Updater/Formatters/FormatterManager.cs index 1969eb77..f47663d3 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/FormatterManager.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/FormatterManager.cs @@ -19,6 +19,8 @@ namespace Mono.Documentation.Updater.Formatters public static DocIdFormatter DocIdFormatter { get; private set; } = new DocIdFormatter(MDocUpdater.Instance.TypeMap); + public static MemberFormatter SlashdocFormatter { get; private set; } = new SlashDocMemberFormatter(MDocUpdater.Instance.TypeMap); + public static void AddFormatter(string langId) { MemberFormatter memberFormatter; @@ -62,5 +64,13 @@ namespace Mono.Documentation.Updater.Formatters TypeFormatters.Add(typeFormatter); MemberFormatters.Add(memberFormatter); } + + public static void UpdateTypeMap(TypeMap typeMap) + { + DocIdFormatter.TypeMap = typeMap; + SlashdocFormatter.TypeMap = typeMap; + foreach (var f in TypeFormatters.Union(MemberFormatters)) + f.TypeMap = typeMap; + } } } diff --git a/mdoc/Mono.Documentation/Updater/Formatters/ILFullMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/ILFullMemberFormatter.cs index 965355fa..4718f560 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/ILFullMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/ILFullMemberFormatter.cs @@ -8,7 +8,7 @@ using Mono.Cecil; using Mono.Documentation.Util; -namespace Mono.Documentation.Updater +namespace Mono.Documentation.Updater.Formatters { public class ILFullMemberFormatter : MemberFormatter { @@ -184,7 +184,7 @@ namespace Mono.Documentation.Updater buf.Append (full.GetName (type.BaseType).Substring ("class ".Length)); } bool first = true; - foreach (var name in type.Interfaces.Where (i => MDocUpdater.IsPublic (i.InterfaceType.Resolve ())) + foreach (var name in type.Interfaces.Where (i => DocUtils.IsPublic (i.InterfaceType.Resolve ())) .Select (i => full.GetName (i.InterfaceType)) .OrderBy (n => n)) { diff --git a/mdoc/Mono.Documentation/Updater/Formatters/ILMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/ILMemberFormatter.cs index a6a902dc..673334ea 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/ILMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/ILMemberFormatter.cs @@ -2,7 +2,7 @@ using Mono.Cecil; -namespace Mono.Documentation.Updater +namespace Mono.Documentation.Updater.Formatters {
public class ILMemberFormatter : ILFullMemberFormatter { diff --git a/mdoc/Mono.Documentation/Updater/Formatters/ILNativeTypeMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/ILNativeTypeMemberFormatter.cs index 053aa496..fa80db03 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/ILNativeTypeMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/ILNativeTypeMemberFormatter.cs @@ -1,4 +1,4 @@ -namespace Mono.Documentation.Updater +namespace Mono.Documentation.Updater.Formatters {
class ILNativeTypeMemberFormatter : ILFullMemberFormatter { diff --git a/mdoc/Mono.Documentation/Updater/Formatters/VBFullMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/VBFullMemberFormatter.cs index cfa69406..35cd4762 100644 --- a/mdoc/Mono.Documentation/Updater/Formatters/VBFullMemberFormatter.cs +++ b/mdoc/Mono.Documentation/Updater/Formatters/VBFullMemberFormatter.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Linq; using System.Text; using Mono.Cecil; +using Mono.Documentation.Updater.Formatters; using Mono.Documentation.Util; namespace Mono.Documentation.Updater @@ -583,7 +584,7 @@ namespace Mono.Documentation.Updater buf.Append(GetTypeName(parameter.ParameterType, new DynamicParserContext(parameter))); if (parameter.HasDefault && parameter.IsOptional && parameter.HasConstant) { - var parameterValue = MDocUpdater.MakeAttributesValueString(parameter.Constant, parameter.ParameterType); + var parameterValue = AttributeFormatter.MakeAttributesValueString(parameter.Constant, parameter.ParameterType); buf.AppendFormat(" = {0}", parameterValue == "null" ? "Nothing" : parameterValue); } return buf; diff --git a/mdoc/Mono.Documentation/Updater/Frameworks/FrameworkTypeEntry.cs b/mdoc/Mono.Documentation/Updater/Frameworks/FrameworkTypeEntry.cs index 12418e6f..204e0fd0 100644 --- a/mdoc/Mono.Documentation/Updater/Frameworks/FrameworkTypeEntry.cs +++ b/mdoc/Mono.Documentation/Updater/Frameworks/FrameworkTypeEntry.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using Mono.Cecil; -using Mono.Cecil.Rocks; +using Mono.Documentation.Updater.Formatters; namespace Mono.Documentation.Updater.Frameworks { @@ -12,7 +12,6 @@ namespace Mono.Documentation.Updater.Frameworks Dictionary<string, bool> sigDocMap = new Dictionary<string, bool>(); ILFullMemberFormatter formatterField; - DocIdFormatter docidFormatterField; ILFullMemberFormatter formatter { get diff --git a/mdoc/mdoc.Test/Enumeration/AttachedEntityTests.cs b/mdoc/mdoc.Test/Enumeration/AttachedEntityTests.cs index 44219f48..ca88d48d 100644 --- a/mdoc/mdoc.Test/Enumeration/AttachedEntityTests.cs +++ b/mdoc/mdoc.Test/Enumeration/AttachedEntityTests.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Mono.Documentation.Util; using Windows.UI.Xaml; using Mono.Documentation.Updater; +using Mono.Documentation.Updater.Formatters; namespace mdoc.Test.Enumeration { diff --git a/mdoc/mdoc.Test/FormatterTests.cs b/mdoc/mdoc.Test/FormatterTests.cs index f14612e6..439d9767 100644 --- a/mdoc/mdoc.Test/FormatterTests.cs +++ b/mdoc/mdoc.Test/FormatterTests.cs @@ -7,8 +7,7 @@ using mdoc.Test.SampleClasses; using Mono.Documentation.Updater; using Mono.Documentation; using Mono.Documentation.Updater.Formatters.CppFormatters; - - +using Mono.Documentation.Updater.Formatters; namespace mdoc.Test { diff --git a/mdoc/mdoc.Test/MDocUpdaterTests.cs b/mdoc/mdoc.Test/MDocUpdaterTests.cs index fbce4f32..ae93a6fc 100644 --- a/mdoc/mdoc.Test/MDocUpdaterTests.cs +++ b/mdoc/mdoc.Test/MDocUpdaterTests.cs @@ -8,6 +8,7 @@ using Mono.Cecil.Rocks; using Mono.Collections.Generic; using Mono.Documentation; using Mono.Documentation.Updater; +using Mono.Documentation.Updater.Formatters; using Mono.Documentation.Updater.Frameworks; using NUnit.Framework; using Cpp = Mono_DocTest_Generic; @@ -18,14 +19,14 @@ namespace mdoc.Test public class MDocUpdaterTests : BasicTests { readonly MDocUpdater updater = new MDocUpdater(); - + readonly AttributeFormatter formatter = new AttributeFormatter(); [Test] public void Test_GetCustomAttributes_IgnoredObsoleteAttribute() { TypeDefinition testType = GetType(typeof(MDocUpdaterTests).Module.FullyQualifiedName, "System.Span`1"); Collection<CustomAttribute> attributes = testType.CustomAttributes; - IEnumerable<string> customAttributes = updater.GetCustomAttributes(attributes, ""); + IEnumerable<string> customAttributes = formatter.GetCustomAttributes(attributes, ""); Assert.AreEqual(1, attributes.Count); Assert.IsEmpty(customAttributes); diff --git a/mdoc/mdoc.Test/TypeMapTests.cs b/mdoc/mdoc.Test/TypeMapTests.cs index 15f01f60..2c6ae7a7 100644 --- a/mdoc/mdoc.Test/TypeMapTests.cs +++ b/mdoc/mdoc.Test/TypeMapTests.cs @@ -8,8 +8,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; -using Windows.Foundation; using Mono.Documentation.Updater.Formatters.CppFormatters; +using Mono.Documentation.Updater.Formatters; namespace mdoc.Test { diff --git a/mdoc/mdoc.csproj b/mdoc/mdoc.csproj index 3020a52e..bf132680 100644 --- a/mdoc/mdoc.csproj +++ b/mdoc/mdoc.csproj @@ -56,7 +56,8 @@ <Compile Include="Mono.Documentation\Framework\FrameworkIndexHelper.cs" />
<Compile Include="Mono.Documentation\Framework\FrameworkTypeModel.cs" />
<Compile Include="Mono.Documentation\Framework\FrameworkNamespaceModel.cs" />
- <Compile Include="Mono.Documentation\Updater\Formatters\ApplePlatformEnumFormatter.cs" />
+ <Compile Include="Mono.Documentation\Updater\Formatters\AttributeFormatters\ApplePlatformEnumFormatter.cs" />
+ <Compile Include="Mono.Documentation\Updater\Formatters\AttributeFormatters\AttributeFormatter.cs" />
<Compile Include="Mono.Documentation\Updater\Formatters\CppFormatters\CppWinRtMemberFormatter.cs" />
<Compile Include="Mono.Documentation\Updater\Formatters\FormatterManager.cs" />
<Compile Include="Mono.Documentation\Updater\Formatters\FSharpFormatter.cs" />
@@ -73,9 +74,9 @@ <Compile Include="Mono.Documentation\Updater\Formatters\CSharpMemberFormatter.cs" />
<Compile Include="Mono.Documentation\Updater\Formatters\SlashDocCSharpMemberFormatter.cs" />
<Compile Include="Mono.Documentation\Updater\Formatters\MsxdocSlashDocMemberFormatter.cs" />
- <Compile Include="Mono.Documentation\Updater\Formatters\StandardFlagsEnumFormatter.cs" />
- <Compile Include="Mono.Documentation\Updater\Formatters\DefaultAttributeValueFormatter.cs" />
- <Compile Include="Mono.Documentation\Updater\Formatters\AttributeValueFormatter.cs" />
+ <Compile Include="Mono.Documentation\Updater\Formatters\AttributeFormatters\StandardFlagsEnumFormatter.cs" />
+ <Compile Include="Mono.Documentation\Updater\Formatters\AttributeFormatters\DefaultAttributeValueFormatter.cs" />
+ <Compile Include="Mono.Documentation\Updater\Formatters\AttributeFormatters\AttributeValueFormatter.cs" />
<Compile Include="Mono.Documentation\Updater\Formatters\VBFullMemberFormatter.cs" />
<Compile Include="Mono.Documentation\Updater\Formatters\VBMemberFormatter.cs" />
<Compile Include="Mono.Documentation\Updater\ResolvedTypeInfo.cs" />
|