Merge pull request #1659 from alexanderkyte/stringbuilder-referencesource
[mono.git] / mcs / tools / mdoc / Mono.Documentation / monodocer.cs
index 09763096e5592bb4d1ab98594760c1f2d95e9bea..8cdf5e7e519470d8bab0ee646a7c8b18984068b4 100644 (file)
@@ -980,7 +980,7 @@ class MDocUpdater : MDocCommand
                throw new ArgumentException ("Unknown kind for type: " + type.FullName);
        }
 
-       private static bool IsPublic (TypeDefinition type)
+       public static bool IsPublic (TypeDefinition type)
        {
                TypeDefinition decl = type;
                while (decl != null) {
@@ -1164,6 +1164,27 @@ class MDocUpdater : MDocCommand
                                                string sig = memberFormatters [0].GetDeclaration (m);
                                                if (sig == null) return false;
                                                if (seenmembers.ContainsKey(sig)) return false;
+
+                                               // Verify that the member isn't an explicitly implemented 
+                                               // member of an internal interface, in which case we shouldn't return true.
+                                               MethodDefinition methdef = null;
+                                               if (m is MethodDefinition) 
+                                                       methdef = m as MethodDefinition;
+                                               else if (m is PropertyDefinition) {
+                                                       var prop = m as PropertyDefinition;
+                                                       methdef = prop.GetMethod ?? prop.SetMethod;
+                                               }
+
+                                               if (methdef != null) {
+                                                       TypeReference iface;
+                                                       MethodReference imethod;
+
+                                                       if (methdef.Overrides.Count == 1) {
+                                                               DocUtils.GetInfoForExplicitlyImplementedMethod (methdef, out iface, out imethod);
+                                                               if (!IsPublic (iface.Resolve ())) return false;
+                                                       }
+                                               }
+
                                                return true;
                                        })
                                        .ToArray();
@@ -3023,7 +3044,7 @@ static class DocUtils {
                        if (!inheritedInterfaces.Contains (GetQualifiedTypeName (lookup)))
                                userInterfaces.Add (iface);
                }
-               return userInterfaces;
+               return userInterfaces.Where (i => MDocUpdater.IsPublic (i.Resolve ()));
        }
 
        private static string GetQualifiedTypeName (TypeReference type)
@@ -3209,16 +3230,21 @@ class DocumentationEnumerator {
                        if (mi is MethodDefinition) {
                                MethodDefinition mb = (MethodDefinition) mi;
                                pis = mb.Parameters;
-                               if (docTypeParams != null && mb.IsGenericMethod ()) {
+                               if (mb.IsGenericMethod ()) {
                                        IList<GenericParameter> args = mb.GenericParameters;
-                                       if (args.Count == docTypeParams.Length) {
-                                               typeParams = args.Select (p => p.Name).ToArray ();
-                                       }
+                                       typeParams = args.Select (p => p.Name).ToArray ();
                                }
                        }
                        else if (mi is PropertyDefinition)
                                pis = ((PropertyDefinition)mi).Parameters;
-                       
+                               
+                       // check type parameters
+                       int methodTcount = member.TypeParameters == null ? 0 : member.TypeParameters.Count;
+                       int reflectionTcount = typeParams == null ? 0 : typeParams.Length;
+                       if (methodTcount != reflectionTcount) 
+                               continue;
+
+                       // check member parameters
                        int mcount = member.Parameters == null ? 0 : member.Parameters.Count;
                        int pcount = pis == null ? 0 : pis.Count;
                        if (mcount != pcount)
@@ -3772,6 +3798,7 @@ class DocumentationMember {
        public StringToStringMap MemberSignatures = new StringToStringMap ();
        public string ReturnType;
        public StringList Parameters;
+       public StringList TypeParameters;
        public string MemberName;
        public string MemberType;
 
@@ -3781,6 +3808,7 @@ class DocumentationMember {
                int depth = reader.Depth;
                bool go = true;
                StringList p = new StringList ();
+               StringList tp = new StringList ();
                do {
                        if (reader.NodeType != XmlNodeType.Element)
                                continue;
@@ -3808,6 +3836,10 @@ class DocumentationMember {
                                        if (reader.Depth == depth + 2 && shouldUse)
                                                p.Add (reader.GetAttribute ("Type"));
                                        break;
+                               case "TypeParameter":
+                                       if (reader.Depth == depth + 2 && shouldUse)
+                                               tp.Add (reader.GetAttribute ("Name"));
+                                       break;
                                case "Docs":
                                        if (reader.Depth == depth + 1)
                                                go = false;
@@ -3817,6 +3849,11 @@ class DocumentationMember {
                if (p.Count > 0) {
                        Parameters = p;
                }
+               if (tp.Count > 0) {
+                       TypeParameters = tp;
+               } else {
+                       DiscernTypeParameters ();
+               }
        }
 
        public DocumentationMember (XmlNode node)
@@ -3840,6 +3877,27 @@ class DocumentationMember {
                        for (int i = 0; i < p.Count; ++i)
                                Parameters.Add (p [i].Attributes ["Type"].Value);
                }
+               XmlNodeList tp = node.SelectNodes ("TypeParameters/TypeParameter[not(@apistyle) or @apistyle='classic']");
+               if (tp.Count > 0) {
+                       TypeParameters = new StringList (tp.Count);
+                       for (int i = 0; i < tp.Count; ++i)
+                               TypeParameters.Add (tp [i].Attributes ["Name"].Value);
+               }
+               else {
+                       DiscernTypeParameters ();
+               }
+       }
+
+       void DiscernTypeParameters ()
+       {
+               // see if we can discern the param list from the name
+               if (MemberName.Contains ("<") && MemberName.EndsWith (">")) {
+                       var starti = MemberName.IndexOf ("<") + 1;
+                       var endi = MemberName.LastIndexOf (">");
+                       var paramlist = MemberName.Substring (starti, endi - starti);
+                       var tparams = paramlist.Split (new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
+                       TypeParameters = new StringList (tparams);
+               }
        }
 }
 
@@ -4351,7 +4409,7 @@ class ILFullMemberFormatter : MemberFormatter {
                                buf.Append (full.GetName (type.BaseType).Substring ("class ".Length));
                }
                bool first = true;
-               foreach (var name in type.Interfaces
+               foreach (var name in type.Interfaces.Where (i => MDocUpdater.IsPublic (i.Resolve ()))
                                .Select (i => full.GetName (i))
                                .OrderBy (n => n)) {
                        if (first) {