public override bool CheckRemoveByMapping(DocsNodeInfo info, string xmlChildName)
        {
            XmlNode elem = GetDocs(info.Member ?? info.Type, MDocUpdater.csharpSlashdocFormatter) ??
                           GetDocs(info.Member ?? info.Type, MDocUpdater.msxdocxSlashdocFormatter);

            if (elem != null)
            {
                foreach (XmlNode child in elem.ChildNodes)
                {
                    if (child.Name == xmlChildName)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public override bool CheckRemoveByMapping(DocsNodeInfo info, string xmlChildName)
        {
            if (!ecmadocs.IsStartElement("Docs"))
            {
                return(false);
            }

            ecmadocs.ReadStartElement("Docs");
            while (ecmadocs.Read())
            {
                if (!ecmadocs.IsStartElement())
                {
                    continue;
                }
                if (ecmadocs.Name == xmlChildName)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 3
0
        public static bool CheckRemoveByImporter(DocsNodeInfo info, string keyName, List <DocumentationImporter> DocImports, IEnumerable <DocumentationImporter> SetImports)
        {
            foreach (DocumentationImporter i in DocImports)
            {
                if (i.CheckRemoveByMapping(info, keyName))
                {
                    return(true);
                }
            }

            if (SetImports != null)
            {
                foreach (var i in SetImports)
                {
                    if (i.CheckRemoveByMapping(info, keyName))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 4
0
        private IEnumerable <DocsNodeInfo> GetMembers(XmlDocument basefile, TypeDefinition type, FrameworkTypeEntry typeEntry)
        {
            while (ecmadocs.Name != "Members" && ecmadocs.Read())
            {
                // do nothing
            }
            if (ecmadocs.IsEmptyElement)
            {
                yield break;
            }

            int  membersDepth = ecmadocs.Depth;
            bool go           = true;

            while (go && ecmadocs.Read())
            {
                switch (ecmadocs.Name)
                {
                case "Member":
                {
                    if (membersDepth != ecmadocs.Depth - 1 || ecmadocs.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }
                    DocumentationMember dm = new DocumentationMember(ecmadocs);

                    string          xp        = MDocUpdater.GetXPathForMember(dm);
                    XmlElement      oldmember = (XmlElement)basefile.SelectSingleNode(xp);
                    MemberReference m;
                    if (oldmember == null)
                    {
                        m = GetMember(type, dm);
                        if (m == null)
                        {
                            app.Warning("Could not import ECMA docs for `{0}'s `{1}': Member not found.",
                                        type.FullName, dm.MemberSignatures["C#"]);
                            // SelectSingleNode (ecmaDocsMember, "MemberSignature[@Language=\"C#\"]/@Value").Value);
                            continue;
                        }
                        // oldmember lookup may have failed due to type parameter renames.
                        // Try again.
                        oldmember = (XmlElement)basefile.SelectSingleNode(MDocUpdater.GetXPathForMember(m));
                        if (oldmember == null)
                        {
                            XmlElement members = MDocUpdater.WriteElement(basefile.DocumentElement, "Members");
                            oldmember = basefile.CreateElement("Member");
                            oldmember.SetAttribute("MemberName", dm.MemberName);
                            members.AppendChild(oldmember);
                            foreach (string key in MDocUpdater.Sort(dm.MemberSignatures.Keys))
                            {
                                XmlElement ms = basefile.CreateElement("MemberSignature");
                                ms.SetAttribute("Language", key);
                                ms.SetAttribute("Value", (string)dm.MemberSignatures[key]);
                                oldmember.AppendChild(ms);
                            }
                            oldmember.SetAttribute("__monodocer-seen__", "true");
                            Console.WriteLine("Member Added: {0}", oldmember.SelectSingleNode("MemberSignature[@Language='C#']/@Value").InnerText);
                            app.additions++;
                        }
                    }
                    else
                    {
                        m = GetMember(type, new DocumentationMember(oldmember, typeEntry));
                        if (m == null)
                        {
                            app.Warning("Could not import ECMA docs for `{0}'s `{1}': Member not found.",
                                        type.FullName, dm.MemberSignatures["C#"]);
                            continue;
                        }
                        oldmember.SetAttribute("__monodocer-seen__", "true");
                    }
                    DocsNodeInfo node = new DocsNodeInfo(oldmember, m);
                    if (ecmadocs.Name != "Docs")
                    {
                        throw new InvalidOperationException("Found " + ecmadocs.Name + "; expected <Docs/>!");
                    }
                    yield return(node);

                    break;
                }

                case "Members":
                    if (membersDepth == ecmadocs.Depth && ecmadocs.NodeType == XmlNodeType.EndElement)
                    {
                        go = false;
                    }
                    break;
                }
            }
        }
        public override void ImportDocumentation(DocsNodeInfo info)
        {
            XmlNode elem = GetDocs(info.Member ?? info.Type);

            if (elem == null)
            {
                return;
            }

            XmlElement e = info.Node;

            if (elem.SelectSingleNode("summary") != null && DocUtils.NeedsOverwrite(e["summary"]))
            {
                MDocUpdater.ClearElement(e, "summary");
            }
            if (elem.SelectSingleNode("remarks") != null && DocUtils.NeedsOverwrite(e["remarks"]))
            {
                MDocUpdater.ClearElement(e, "remarks");
            }
            if (elem.SelectSingleNode("value") != null || elem.SelectSingleNode("returns") != null)
            {
                if (DocUtils.NeedsOverwrite(e["value"]))
                {
                    MDocUpdater.ClearElement(e, "value");
                }
                if (DocUtils.NeedsOverwrite(e["returns"]))
                {
                    MDocUpdater.ClearElement(e, "returns");
                }
            }



            foreach (XmlNode child in elem.ChildNodes)
            {
                switch (child.Name)
                {
                case "param":
                case "typeparam":
                {
                    XmlAttribute name = child.Attributes["name"];
                    if (name == null)
                    {
                        break;
                    }
                    XmlElement p2 = (XmlElement)e.SelectSingleNode(child.Name + "[@name='" + name.Value + "']");
                    if (DocUtils.NeedsOverwrite(p2))
                    {
                        p2.RemoveAttribute("overwrite");
                        p2.InnerXml = child.InnerXml;
                    }
                    break;
                }

                // Occasionally XML documentation will use <returns/> on
                // properties, so let's try to normalize things.
                case "value":
                case "returns":
                {
                    XmlElement v  = e.OwnerDocument.CreateElement(info.ReturnIsReturn ? "returns" : "value");
                    XmlElement p2 = (XmlElement)e.SelectSingleNode(child.Name);
                    if (p2 == null)
                    {
                        v.InnerXml = child.InnerXml;
                        e.AppendChild(v);
                    }
                    break;
                }

                case "altmember":
                case "exception":
                case "permission":
                {
                    XmlAttribute cref = child.Attributes["cref"] ?? child.Attributes["name"];
                    if (cref == null)
                    {
                        break;
                    }
                    XmlElement a = (XmlElement)e.SelectSingleNode(child.Name + "[@cref='" + cref.Value + "']");
                    if (a == null)
                    {
                        a = e.OwnerDocument.CreateElement(child.Name);
                        a.SetAttribute("cref", cref.Value);
                        e.AppendChild(a);
                    }
                    if (DocUtils.NeedsOverwrite(a))
                    {
                        a.InnerXml = child.InnerXml;
                    }
                    break;
                }

                case "seealso":
                {
                    XmlAttribute cref = child.Attributes["cref"];
                    if (cref == null)
                    {
                        break;
                    }
                    XmlElement a = (XmlElement)e.SelectSingleNode("altmember[@cref='" + cref.Value + "']");
                    if (a == null)
                    {
                        a = e.OwnerDocument.CreateElement("altmember");
                        a.SetAttribute("cref", cref.Value);
                        e.AppendChild(a);
                    }
                    break;
                }

                default:
                {
                    var targetNodes = e.ChildNodes.Cast <XmlNode> ()
                                      .Where(n => n.Name == child.Name)
                                      .Select(n => new
                        {
                            Xml       = n.OuterXml,
                            Overwrite = n.Attributes != null ? n.Attributes["overwrite"] : null
                        });
                    string sourceXml = child.OuterXml;

                    if (!targetNodes.Any(n => sourceXml.Equals(n.Xml) || n.Overwrite?.Value == "false"))
                    {
                        MDocUpdater.CopyNode(child, e);
                    }
                    break;
                }
                }
            }
        }
        public override void ImportDocumentation(DocsNodeInfo info)
        {
            if (!ecmadocs.IsStartElement("Docs"))
            {
                return;
            }

            XmlElement e = info.Node;

            int depth = ecmadocs.Depth;

            ecmadocs.ReadStartElement("Docs");
            while (ecmadocs.Read())
            {
                if (ecmadocs.Name == "Docs")
                {
                    if (ecmadocs.Depth == depth && ecmadocs.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                    else
                    {
                        throw new InvalidOperationException("Skipped past current <Docs/> element!");
                    }
                }
                if (!ecmadocs.IsStartElement())
                {
                    continue;
                }
                switch (ecmadocs.Name)
                {
                case "param":
                case "typeparam":
                {
                    string name = ecmadocs.GetAttribute("name");
                    if (name == null)
                    {
                        break;
                    }
                    XmlNode doc = e.SelectSingleNode(
                        ecmadocs.Name + "[@name='" + name + "']");
                    string value = ecmadocs.ReadInnerXml();
                    if (doc != null)
                    {
                        doc.InnerXml = value.Replace("\r", "");
                    }
                    break;
                }

                case "altmember":
                case "exception":
                case "permission":
                case "seealso":
                {
                    string name = ecmadocs.Name;
                    string cref = ecmadocs.GetAttribute("cref");
                    if (cref == null)
                    {
                        break;
                    }
                    XmlNode doc = e.SelectSingleNode(
                        ecmadocs.Name + "[@cref='" + cref + "']");
                    string value = ecmadocs.ReadInnerXml().Replace("\r", "");
                    if (doc != null)
                    {
                        doc.InnerXml = value;
                    }
                    else
                    {
                        XmlElement n = e.OwnerDocument.CreateElement(name);
                        n.SetAttribute("cref", cref);
                        n.InnerXml = value;
                        e.AppendChild(n);
                    }
                    break;
                }

                default:
                {
                    string     name       = ecmadocs.Name;
                    string     xpath      = ecmadocs.Name;
                    StringList attributes = new StringList(ecmadocs.AttributeCount);
                    if (ecmadocs.MoveToFirstAttribute())
                    {
                        do
                        {
                            attributes.Add("@" + ecmadocs.Name + "=\"" + ecmadocs.Value + "\"");
                        } while (ecmadocs.MoveToNextAttribute());
                        ecmadocs.MoveToContent();
                    }
                    if (attributes.Count > 0)
                    {
                        xpath += "[" + string.Join(" and ", attributes.ToArray()) + "]";
                    }
                    XmlNode doc   = e.SelectSingleNode(xpath);
                    string  value = ecmadocs.ReadInnerXml().Replace("\r", "");
                    if (doc != null)
                    {
                        doc.InnerXml = value;
                    }
                    else
                    {
                        XmlElement n = e.OwnerDocument.CreateElement(name);
                        n.InnerXml = value;
                        foreach (string a in attributes)
                        {
                            int eq = a.IndexOf('=');
                            n.SetAttribute(a.Substring(1, eq - 1), a.Substring(eq + 2, a.Length - eq - 3));
                        }
                        e.AppendChild(n);
                    }
                    break;
                }
                }
            }
        }
Esempio n. 7
0
        public override void ImportDocumentation(DocsNodeInfo info)
        {
            XmlNode elem = GetDocs(info.Member ?? info.Type);

            if (elem == null)
            {
                return;
            }

            XmlElement e = info.Node;

            if (elem.SelectSingleNode("summary") != null)
            {
                MDocUpdater.ClearElement(e, "summary");
            }
            if (elem.SelectSingleNode("remarks") != null)
            {
                MDocUpdater.ClearElement(e, "remarks");
            }
            if (elem.SelectSingleNode("value") != null || elem.SelectSingleNode("returns") != null)
            {
                MDocUpdater.ClearElement(e, "value");
                MDocUpdater.ClearElement(e, "returns");
            }

            foreach (XmlNode child in elem.ChildNodes)
            {
                switch (child.Name)
                {
                case "param":
                case "typeparam":
                {
                    XmlAttribute name = child.Attributes["name"];
                    if (name == null)
                    {
                        break;
                    }
                    XmlElement p2 = (XmlElement)e.SelectSingleNode(child.Name + "[@name='" + name.Value + "']");
                    if (p2 != null)
                    {
                        p2.InnerXml = child.InnerXml;
                    }
                    break;
                }

                // Occasionally XML documentation will use <returns/> on
                // properties, so let's try to normalize things.
                case "value":
                case "returns":
                {
                    XmlElement v = e.OwnerDocument.CreateElement(info.ReturnIsReturn ? "returns" : "value");
                    v.InnerXml = child.InnerXml;
                    e.AppendChild(v);
                    break;
                }

                case "altmember":
                case "exception":
                case "permission":
                {
                    XmlAttribute cref = child.Attributes["cref"] ?? child.Attributes["name"];
                    if (cref == null)
                    {
                        break;
                    }
                    XmlElement a = (XmlElement)e.SelectSingleNode(child.Name + "[@cref='" + cref.Value + "']");
                    if (a == null)
                    {
                        a = e.OwnerDocument.CreateElement(child.Name);
                        a.SetAttribute("cref", cref.Value);
                        e.AppendChild(a);
                    }
                    a.InnerXml = child.InnerXml;
                    break;
                }

                case "seealso":
                {
                    XmlAttribute cref = child.Attributes["cref"];
                    if (cref == null)
                    {
                        break;
                    }
                    XmlElement a = (XmlElement)e.SelectSingleNode("altmember[@cref='" + cref.Value + "']");
                    if (a == null)
                    {
                        a = e.OwnerDocument.CreateElement("altmember");
                        a.SetAttribute("cref", cref.Value);
                        e.AppendChild(a);
                    }
                    break;
                }

                default:
                {
                    bool add = true;
                    if (child.NodeType == XmlNodeType.Element &&
                        e.SelectNodes(child.Name).Cast <XmlElement> ().Any(n => n.OuterXml == child.OuterXml))
                    {
                        add = false;
                    }
                    if (add)
                    {
                        MDocUpdater.CopyNode(child, e);
                    }
                    break;
                }
                }
            }
        }
        public override void ImportDocumentation(DocsNodeInfo info)
        {
            //first try C# compiler docIds, next other languages
            XmlNode elem = GetDocs(info.Member ?? info.Type, MDocUpdater.csharpSlashdocFormatter) ??
                           GetDocs(info.Member ?? info.Type, MDocUpdater.msxdocxSlashdocFormatter);

            if (elem == null)
            {
                return;
            }

            XmlElement e = info.Node;

            if (e.SelectNodes("./*[@overwrite]").Count == 0)
            {
                // there are no overwrites in this node, just clear everything except for default nodes and nodes that don't have an incoming equivalent
                DocUtils.ClearNodesIfNotDefault(e, elem);
            }

            if (elem.SelectSingleNode("summary") != null && DocUtils.NeedsOverwrite(e["summary"]))
            {
                MDocUpdater.ClearElement(e, "summary");
            }
            if (elem.SelectSingleNode("remarks") != null && DocUtils.NeedsOverwrite(e["remarks"]))
            {
                MDocUpdater.ClearElement(e, "remarks");
            }
            if (elem.SelectSingleNode("value") != null || elem.SelectSingleNode("returns") != null)
            {
                if (DocUtils.NeedsOverwrite(e["value"]))
                {
                    MDocUpdater.ClearElement(e, "value");
                }
                if (DocUtils.NeedsOverwrite(e["returns"]))
                {
                    MDocUpdater.ClearElement(e, "returns");
                }
            }



            foreach (XmlNode child in elem.ChildNodes)
            {
                switch (child.Name)
                {
                case "param":
                case "typeparam":
                {
                    XmlAttribute name = child.Attributes["name"];
                    if (name == null)
                    {
                        break;
                    }
                    XmlElement p2 = (XmlElement)e.SelectSingleNode(child.Name + "[@name='" + name.Value + "']");
                    if (p2 == null)
                    {
                        p2 = e.OwnerDocument.CreateElement(child.Name);
                        var pname = e.OwnerDocument.CreateAttribute("name");
                        pname.Value = name.Value;

                        p2.Attributes.Append(pname);
                        e.AppendChild(p2);
                    }
                    if (DocUtils.NeedsOverwrite(p2))
                    {
                        p2.RemoveAttribute("overwrite");
                        p2.InnerXml = child.InnerXml;
                    }
                    break;
                }

                // Occasionally XML documentation will use <returns/> on
                // properties, so let's try to normalize things.
                case "value":
                case "returns":
                {
                    XmlElement v  = e.OwnerDocument.CreateElement(info.ReturnIsReturn ? "returns" : "value");
                    XmlElement p2 = (XmlElement)e.SelectSingleNode(child.Name);
                    if (p2 == null)
                    {
                        v.InnerXml = child.InnerXml;
                        e.AppendChild(v);
                    }
                    break;
                }

                case "altmember":
                case "exception":
                case "permission":
                {
                    XmlAttribute cref = child.Attributes["cref"] ?? child.Attributes["name"];
                    if (cref == null)
                    {
                        break;
                    }
                    XmlElement a = (XmlElement)e.SelectSingleNode(child.Name + "[@cref='" + cref.Value + "']");
                    if (a == null)
                    {
                        a = e.OwnerDocument.CreateElement(child.Name);
                        a.SetAttribute("cref", cref.Value);
                        e.AppendChild(a);
                    }
                    if (DocUtils.NeedsOverwrite(a))
                    {
                        a.InnerXml = child.InnerXml;
                    }
                    break;
                }

                case "seealso":
                {
                    XmlAttribute cref = child.Attributes["cref"];
                    if (cref == null)
                    {
                        break;
                    }
                    XmlElement a = (XmlElement)e.SelectSingleNode("altmember[@cref='" + cref.Value + "']");
                    if (a == null)
                    {
                        a = e.OwnerDocument.CreateElement("altmember");
                        a.SetAttribute("cref", cref.Value);
                        e.AppendChild(a);
                    }
                    break;
                }

                default:
                {
                    var targetNodes = e.ChildNodes.Cast <XmlNode> ()
                                      .Where(n => n.Name == child.Name)
                                      .Select(n => new
                        {
                            Xml       = n.OuterXml,
                            Overwrite = n.Attributes != null ? n.Attributes["overwrite"] : null
                        });
                    string sourceXml = child.OuterXml;

                    if (!targetNodes.Any(n => sourceXml.Equals(n.Xml) || n.Overwrite?.Value == "false"))
                    {
                        MDocUpdater.CopyNode(child, e);
                    }
                    break;
                }
                }
            }
        }