Debian Codegraph @

external/api-doc-tools/mdoc/Mono.Documentation/Updater/EcmaDocumentationImporter.cs

raw
1 using System;
2 using System.Xml;
3
4 using StringList = System.Collections.Generic.List<string>;
5
6 namespace Mono.Documentation.Updater
7 {
8 class EcmaDocumentationImporter : DocumentationImporter
9 {
10
11 XmlReader ecmadocs;
12
13 public EcmaDocumentationImporter (XmlReader ecmaDocs)
14 {
15 this.ecmadocs = ecmaDocs;
16 }
17
18 public override void ImportDocumentation (DocsNodeInfo info)
19 {
20 if (!ecmadocs.IsStartElement ("Docs"))
21 {
22 return;
23 }
24
25 XmlElement e = info.Node;
26
27 int depth = ecmadocs.Depth;
28 ecmadocs.ReadStartElement ("Docs");
29 while (ecmadocs.Read ())
30 {
31 if (ecmadocs.Name == "Docs")
32 {
33 if (ecmadocs.Depth == depth && ecmadocs.NodeType == XmlNodeType.EndElement)
34 break;
35 else
36 throw new InvalidOperationException ("Skipped past current <Docs/> element!");
37 }
38 if (!ecmadocs.IsStartElement ())
39 continue;
40 switch (ecmadocs.Name)
41 {
42 case "param":
43 case "typeparam":
44 {
45 string name = ecmadocs.GetAttribute ("name");
46 if (name == null)
47 break;
48 XmlNode doc = e.SelectSingleNode (
49 ecmadocs.Name + "[@name='" + name + "']");
50 string value = ecmadocs.ReadInnerXml ();
51 if (doc != null)
52 doc.InnerXml = value.Replace ("\r", "");
53 break;
54 }
55 case "altmember":
56 case "exception":
57 case "permission":
58 case "seealso":
59 {
60 string name = ecmadocs.Name;
61 string cref = ecmadocs.GetAttribute ("cref");
62 if (cref == null)
63 break;
64 XmlNode doc = e.SelectSingleNode (
65 ecmadocs.Name + "[@cref='" + cref + "']");
66 string value = ecmadocs.ReadInnerXml ().Replace ("\r", "");
67 if (doc != null)
68 doc.InnerXml = value;
69 else
70 {
71 XmlElement n = e.OwnerDocument.CreateElement (name);
72 n.SetAttribute ("cref", cref);
73 n.InnerXml = value;
74 e.AppendChild (n);
75 }
76 break;
77 }
78 default:
79 {
80 string name = ecmadocs.Name;
81 string xpath = ecmadocs.Name;
82 StringList attributes = new StringList (ecmadocs.AttributeCount);
83 if (ecmadocs.MoveToFirstAttribute ())
84 {
85 do
86 {
87 attributes.Add ("@" + ecmadocs.Name + "=\"" + ecmadocs.Value + "\"");
88 } while (ecmadocs.MoveToNextAttribute ());
89 ecmadocs.MoveToContent ();
90 }
91 if (attributes.Count > 0)
92 {
93 xpath += "[" + string.Join (" and ", attributes.ToArray ()) + "]";
94 }
95 XmlNode doc = e.SelectSingleNode (xpath);
96 string value = ecmadocs.ReadInnerXml ().Replace ("\r", "");
97 if (doc != null)
98 {
99 doc.InnerXml = value;
100 }
101 else
102 {
103 XmlElement n = e.OwnerDocument.CreateElement (name);
104 n.InnerXml = value;
105 foreach (string a in attributes)
106 {
107 int eq = a.IndexOf ('=');
108 n.SetAttribute (a.Substring (1, eq - 1), a.Substring (eq + 2, a.Length - eq - 3));
109 }
110 e.AppendChild (n);
111 }
112 break;
113 }
114 }
115 }
116 }
117 }
118 }