Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MissingAttribute.cs « corcompare « tools « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f155a8764bde16a1fcbc41dd4ac2591754dd3ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Mono.Util.CorCompare.MissingAttribute
//
// Author(s):
//   Piers Haken (piersh@friskit.com)
//
// (C) 2001-2002 Piers Haken
using System;
using System.Xml;
using System.Reflection;
using System.Collections;

namespace Mono.Util.CorCompare
{

	/// <summary>
	/// 	Represents an Attribute that is completely missing
	/// </summary>
	/// <remarks>
	/// 	created by - Piersh
	/// 	created on - 3/2/2002 9:47:00 pm
	/// </remarks>
	class MissingAttribute : MissingBase
	{
		// e.g. <attribute name="Equals" status="missing"/>
		Object attributeMono;
		Object attributeMS;
		static Hashtable htIgnore;

		static MissingAttribute ()
		{
			htIgnore = new Hashtable ();
			htIgnore.Add ("System.Runtime.InteropServices.ClassInterfaceAttribute", null);
			htIgnore.Add ("System.Diagnostics.DebuggerHiddenAttribute", null);
			htIgnore.Add ("System.Diagnostics.DebuggerStepThroughAttribute", null);
			htIgnore.Add ("System.Runtime.InteropServices.GuidAttribute", null);
			htIgnore.Add ("System.Runtime.InteropServices.InterfaceTypeAttribute", null);
			htIgnore.Add ("System.Runtime.InteropServices.ComVisibleAttribute", null);
		}

		public MissingAttribute (Object _attributeMono, Object _attributeMS) 
		{
			attributeMono = _attributeMono;
			attributeMS = _attributeMS;
			m_nodeStatus = new NodeStatus (attributeMono, attributeMS);
		}

		public override string Name 
		{
			get { return Attribute.ToString (); }
		}

		public override string Type
		{
			get { return "attribute"; }
		}

		public override NodeStatus Analyze ()
		{
			return m_nodeStatus;
		}


		public Object Attribute
		{
			get { return (attributeMono != null) ? attributeMono : attributeMS; }
		}

		/// <summary>
		/// creates a map from a list of attributes
		/// the hashtable maps from name to attribute
		/// </summary>
		/// <param name="rgAttributes">the list of attributes</param>
		/// <returns>a map</returns>
		public static Hashtable GetAttributeMap (Object [] rgAttributes)
		{
			Hashtable map = new Hashtable ();
			foreach (Object attribute in rgAttributes)
			{
				if (attribute != null)
				{
					string strName = attribute.ToString ();
					if (!map.Contains (strName) && !htIgnore.Contains (strName))
						map.Add (strName, attribute);
				}
			}
			return map;
		}

		/// <summary>
		/// analyzes two sets of reflected attributes, generates a list
		/// of MissingAttributes according to the completion of the first set wrt the second.
		/// </summary>
		/// <param name="rgAttributesMono">mono attributes</param>
		/// <param name="rgAttributesMS">microsoft attributes</param>
		/// <param name="rgAttributes">where the results are put</param>
		/// <returns>completion info for the whole set</returns>
		public static NodeStatus AnalyzeAttributes (Object [] rgAttributesMono, Object [] rgAttributesMS, ArrayList rgAttributes)
		{
			NodeStatus nodeStatus = new NodeStatus ();

			Hashtable mapAttributesMono = (rgAttributesMono == null) ? new Hashtable () : MissingAttribute.GetAttributeMap (rgAttributesMono);
			Hashtable mapAttributesMS   = (rgAttributesMS   == null) ? new Hashtable () : MissingAttribute.GetAttributeMap (rgAttributesMS);

			foreach (Object attribute in mapAttributesMS.Values)
			{
				string strAttribute = attribute.ToString ();
				Object attributeMono = mapAttributesMono [strAttribute];
				MissingAttribute ma = new MissingAttribute (attributeMono, attribute);
				rgAttributes.Add (ma);
				NodeStatus nsAttribute = ma.Analyze ();
				nodeStatus.AddChildren (nsAttribute);

				if (attributeMono != null)
					mapAttributesMono.Remove (strAttribute);
			}
			foreach (Object attribute in mapAttributesMono.Values)
			{
				if (attribute.ToString ().EndsWith ("MonoTODOAttribute"))
				{
					nodeStatus.SetError (ErrorTypes.Todo);
					//nodeStatus.statusCountsChildren.errorCounts.Add (ErrorTypes.Todo);
					//nodeStatus.statusCountsTotal.errorCounts.Add (ErrorTypes.Todo);
					//nodeStatus.cTodo ++;	// this is where ALL the 'todo's come from
				}
				else
				{
					MissingAttribute ma = new MissingAttribute (attribute, null);
					rgAttributes.Add (ma);
					NodeStatus nsAttribute = ma.Analyze ();
					nodeStatus.AddChildren (nsAttribute);
				}
			}
			return nodeStatus;
		}
	}
}