This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / tools / corcompare / MissingAttribute.cs
1 // Mono.Util.CorCompare.MissingAttribute
2 //
3 // Author(s):
4 //   Piers Haken (piersh@friskit.com)
5 //
6 // (C) 2001-2002 Piers Haken
7 using System;
8 using System.Xml;
9 using System.Reflection;
10 using System.Collections;
11
12 namespace Mono.Util.CorCompare
13 {
14
15         /// <summary>
16         ///     Represents an Attribute that is completely missing
17         /// </summary>
18         /// <remarks>
19         ///     created by - Piersh
20         ///     created on - 3/2/2002 9:47:00 pm
21         /// </remarks>
22         class MissingAttribute : MissingBase
23         {
24                 // e.g. <attribute name="Equals" status="missing"/>
25                 Object attributeMono;
26                 Object attributeMS;
27                 static Hashtable htIgnore;
28
29                 static MissingAttribute ()
30                 {
31                         htIgnore = new Hashtable ();
32                         htIgnore.Add ("System.Runtime.InteropServices.ClassInterfaceAttribute", null);
33                         htIgnore.Add ("System.Diagnostics.DebuggerHiddenAttribute", null);
34                         htIgnore.Add ("System.Diagnostics.DebuggerStepThroughAttribute", null);
35                         htIgnore.Add ("System.Runtime.InteropServices.GuidAttribute", null);
36                         htIgnore.Add ("System.Runtime.InteropServices.InterfaceTypeAttribute", null);
37                         htIgnore.Add ("System.Runtime.InteropServices.ComVisibleAttribute", null);
38                 }
39
40                 public MissingAttribute (Object _attributeMono, Object _attributeMS) 
41                 {
42                         attributeMono = _attributeMono;
43                         attributeMS = _attributeMS;
44                         m_nodeStatus = new NodeStatus (attributeMono, attributeMS);
45                 }
46
47                 public override string Name 
48                 {
49                         get { return Attribute.ToString (); }
50                 }
51
52                 public override string Type
53                 {
54                         get { return "attribute"; }
55                 }
56
57                 public override NodeStatus Analyze ()
58                 {
59                         return m_nodeStatus;
60                 }
61
62
63                 public Object Attribute
64                 {
65                         get { return (attributeMono != null) ? attributeMono : attributeMS; }
66                 }
67
68                 /// <summary>
69                 /// creates a map from a list of attributes
70                 /// the hashtable maps from name to attribute
71                 /// </summary>
72                 /// <param name="rgAttributes">the list of attributes</param>
73                 /// <returns>a map</returns>
74                 public static Hashtable GetAttributeMap (Object [] rgAttributes)
75                 {
76                         Hashtable map = new Hashtable ();
77                         foreach (Object attribute in rgAttributes)
78                         {
79                                 if (attribute != null)
80                                 {
81                                         string strName = attribute.ToString ();
82                                         if (!map.Contains (strName) && !htIgnore.Contains (strName))
83                                                 map.Add (strName, attribute);
84                                 }
85                         }
86                         return map;
87                 }
88
89                 /// <summary>
90                 /// analyzes two sets of reflected attributes, generates a list
91                 /// of MissingAttributes according to the completion of the first set wrt the second.
92                 /// </summary>
93                 /// <param name="rgAttributesMono">mono attributes</param>
94                 /// <param name="rgAttributesMS">microsoft attributes</param>
95                 /// <param name="rgAttributes">where the results are put</param>
96                 /// <returns>completion info for the whole set</returns>
97                 public static NodeStatus AnalyzeAttributes (Object [] rgAttributesMono, Object [] rgAttributesMS, ArrayList rgAttributes)
98                 {
99                         NodeStatus nodeStatus = new NodeStatus ();
100
101                         Hashtable mapAttributesMono = (rgAttributesMono == null) ? new Hashtable () : MissingAttribute.GetAttributeMap (rgAttributesMono);
102                         Hashtable mapAttributesMS   = (rgAttributesMS   == null) ? new Hashtable () : MissingAttribute.GetAttributeMap (rgAttributesMS);
103
104                         foreach (Object attribute in mapAttributesMS.Values)
105                         {
106                                 string strAttribute = attribute.ToString ();
107                                 Object attributeMono = mapAttributesMono [strAttribute];
108                                 MissingAttribute ma = new MissingAttribute (attributeMono, attribute);
109                                 rgAttributes.Add (ma);
110                                 NodeStatus nsAttribute = ma.Analyze ();
111                                 nodeStatus.AddChildren (nsAttribute);
112
113                                 if (attributeMono != null)
114                                         mapAttributesMono.Remove (strAttribute);
115                         }
116                         foreach (Object attribute in mapAttributesMono.Values)
117                         {
118                                 if (attribute.ToString ().EndsWith ("MonoTODOAttribute"))
119                                 {
120                                         nodeStatus.SetError (ErrorTypes.Todo);
121                                         //nodeStatus.statusCountsChildren.errorCounts.Add (ErrorTypes.Todo);
122                                         //nodeStatus.statusCountsTotal.errorCounts.Add (ErrorTypes.Todo);
123                                         //nodeStatus.cTodo ++;  // this is where ALL the 'todo's come from
124                                 }
125                                 else
126                                 {
127                                         MissingAttribute ma = new MissingAttribute (attribute, null);
128                                         rgAttributes.Add (ma);
129                                         NodeStatus nsAttribute = ma.Analyze ();
130                                         nodeStatus.AddChildren (nsAttribute);
131                                 }
132                         }
133                         return nodeStatus;
134                 }
135         }
136 }