2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / tools / corcompare / MissingNameSpace.cs
1 // Mono.Util.CorCompare.MissingNameSpace
2 //
3 // Author(s):
4 //   Nick Drochak (ndrochak@gol.com)
5 //
6 // (C) 2001-2002 Nick Drochak
7
8 using System;
9 using System.Collections;
10 using System.Reflection;
11 using System.Xml;
12
13 namespace Mono.Util.CorCompare {
14
15         /// <summary>
16         ///     Represents a namespace that has missing and/or MonoTODO classes.
17         /// </summary>
18         /// <remarks>
19         ///     created by - Nick
20         ///     created on - 2/20/2002 10:43:57 PM
21         /// </remarks>
22         class MissingNameSpace : MissingBase
23         {
24                 // e.g. <namespace name="System" missing="267" todo="453" complete="21">
25                 protected ArrayList rgTypesMono, rgTypesMS;
26                 string strNamespace;
27                 ArrayList rgTypes = new ArrayList ();
28                 protected static Hashtable htGhostTypes;
29                 static string[] rgstrGhostTypes = {"System.Object", "System.ValueType", "System.Delegate", "System.Enum"};
30
31
32                 static MissingNameSpace ()
33                 {
34                         htGhostTypes = new Hashtable ();
35
36                         foreach (string strGhostType in rgstrGhostTypes)
37                         {
38                                 htGhostTypes.Add (strGhostType, null);
39                         }
40                 }
41
42                 public MissingNameSpace(string nameSpace, ArrayList _rgTypesMono, ArrayList _rgTypesMS)
43                 {
44                         strNamespace = nameSpace;
45                         rgTypesMono = _rgTypesMono;
46                         rgTypesMS = _rgTypesMS;
47                         m_nodeStatus = new NodeStatus (_rgTypesMono, _rgTypesMS);
48                 }
49
50                 public virtual string [] MissingTypeNames (bool f)
51                 {
52                         return null;
53                 }
54
55                 public virtual ArrayList ToDoTypeNames
56                 {
57                         get { return null; }
58                 }
59
60                 public override string Name 
61                 {
62                         get { return strNamespace; }
63                 }
64                 public override string Type
65                 {
66                         get { return "namespace"; }
67                 }
68
69
70                 /// <summary>
71                 /// first we go through all the microsoft types adding any mono types that match, or missing types otherwise
72                 /// then we go through the unmatched mono types adding those
73                 /// uses a hashtable to speed up lookups
74                 /// </summary>
75                 /// <returns></returns>
76                 public override NodeStatus Analyze ()
77                 {
78                         Hashtable htMono = new Hashtable ();
79                         if (rgTypesMono != null)
80                         {
81                                 foreach (Type t in rgTypesMono)
82                                 {
83                                         htMono.Add (t.FullName, t);
84                                 }
85                         }
86                         if (rgTypesMS != null)
87                         {
88                                 foreach (Type t in rgTypesMS)
89                                 {
90                                         Type tMono = (Type) htMono [t.FullName];
91                                         MissingType mt = null;
92                                         if (tMono == null)
93                                         {
94                                                 if (t.IsPublic && !htGhostTypes.Contains (t.FullName))
95                                                         mt = new MissingType (null, t);
96                                         }
97                                         else
98                                         {
99                                                 if (t.IsPublic)
100                                                 {
101                                                         htMono.Remove (t.FullName);
102                                                         mt = new MissingType (tMono, t);
103                                                 }
104                                         }
105                                         if (mt != null)
106                                         {
107                                                 NodeStatus nsType = mt.Analyze ();
108                                                 m_nodeStatus.AddChildren (nsType);
109                                                 rgTypes.Add (mt);
110                                         }
111                                 }
112                         }
113                         // do any mono types that aren't in microsoft's namespace
114                         foreach (Type tMono in htMono.Values)
115                         {
116                                 if (tMono.IsPublic)
117                                 {
118                                         MissingType tdt = new MissingType (tMono, null);
119                                         NodeStatus nsType = tdt.Analyze ();
120                                         m_nodeStatus.AddChildren (nsType);
121                                         rgTypes.Add (tdt);
122                                 }
123                         }
124                         return m_nodeStatus;
125                 }
126
127                 public override XmlElement CreateXML (XmlDocument doc)
128                 {
129                         XmlElement eltNameSpace = base.CreateXML (doc);
130
131                         // TODO: include complete namespaces?
132 //                      if (m_nodeStatus.statusCountsTotal.cMissing > 0 || m_nodeStatus.statusCountsTotal.cTodo > 0)
133                         {
134                                 XmlElement eltClasses = doc.CreateElement("classes");
135                                 eltNameSpace.AppendChild (eltClasses);
136
137                                 foreach (MissingType type in rgTypes) 
138                                 {
139                                         XmlElement eltClass = type.CreateXML (doc);
140                                         if (eltClass != null)
141                                                 eltClasses.AppendChild (eltClass);
142                                 }
143                         }
144                         return eltNameSpace;
145                 }
146
147
148                 public static ArrayList GetNamespaces(Type[] types) 
149                 {
150                         ArrayList nsList = new ArrayList();
151                         foreach (Type t in types) 
152                         {
153                                 if (!nsList.Contains(t.Namespace)) 
154                                 {
155                                         nsList.Add(t.Namespace);
156                                 }
157                         }
158                         return nsList;
159                 }
160         }
161 }
162