**** Merged from MCS ****
[mono-project.git] / mcs / tools / corcompare / MissingAttribute.cs
blobddd63d604703b56bb979ff113e7c596b66b6f366
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;
12 namespace Mono.Util.CorCompare
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
24 // e.g. <attribute name="Equals" status="missing"/>
25 Object attributeMono;
26 Object attributeMS;
27 static Hashtable htIgnore;
29 static MissingAttribute ()
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);
40 public MissingAttribute (Object _attributeMono, Object _attributeMS)
42 attributeMono = _attributeMono;
43 attributeMS = _attributeMS;
44 m_nodeStatus = new NodeStatus (attributeMono, attributeMS);
47 public override string Name
49 get { return Attribute.ToString (); }
52 public override string Type
54 get { return "attribute"; }
57 public override NodeStatus Analyze ()
59 return m_nodeStatus;
63 public Object Attribute
65 get { return (attributeMono != null) ? attributeMono : attributeMS; }
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)
76 Hashtable map = new Hashtable ();
77 foreach (Object attribute in rgAttributes)
79 if (attribute != null)
81 string strName = attribute.ToString ();
82 if (!map.Contains (strName) && !htIgnore.Contains (strName))
83 map.Add (strName, attribute);
86 return map;
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)
99 NodeStatus nodeStatus = new NodeStatus ();
101 Hashtable mapAttributesMono = (rgAttributesMono == null) ? new Hashtable () : MissingAttribute.GetAttributeMap (rgAttributesMono);
102 Hashtable mapAttributesMS = (rgAttributesMS == null) ? new Hashtable () : MissingAttribute.GetAttributeMap (rgAttributesMS);
104 foreach (Object attribute in mapAttributesMS.Values)
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);
113 if (attributeMono != null)
114 mapAttributesMono.Remove (strAttribute);
116 foreach (Object attribute in mapAttributesMono.Values)
118 if (attribute.ToString ().EndsWith ("MonoTODOAttribute"))
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
125 else if (attribute.ToString ().EndsWith ("DllImportAttribute") || attribute.ToString ().EndsWith ("PreserveSigAttribute")) {
126 // Ignore these
128 else
130 MissingAttribute ma = new MissingAttribute (attribute, null);
131 rgAttributes.Add (ma);
132 NodeStatus nsAttribute = ma.Analyze ();
133 nodeStatus.AddChildren (nsAttribute);
136 return nodeStatus;