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

ToDoAssembly.cs « corcompare « tools « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d95c0a427835641ad9af5373daa65d1913f00d41 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Mono.Util.CorCompare.ToDoAssembly
//
// Author(s):
//   Nick Drochak (ndrochak@gol.com)
//
// (C) 2001-2002 Nick Drochak

using System;
using System.Reflection;
using System.Collections;
using System.IO;
using System.Text;
using System.Xml;

namespace Mono.Util.CorCompare {

	/// <summary>
	/// 	Represents an assembly that has missing or MonoTODO classes
	/// </summary>
	/// <remarks>
	/// 	created by - Nick
	/// 	created on - 2/20/2002 10:43:57 PM
	/// </remarks>
	class ToDoAssembly : MissingBase
	{
		// these types are in mono corlib, but not in the dll we are going to examine.
		ArrayList MissingTypes = new ArrayList();
		ArrayList rgNamespaces = new ArrayList();
		string strName;
		Assembly assMono;
		Assembly assMS;
		Type [] rgTypesMono;
		Type [] rgTypesMS;

		protected static Hashtable htGhostTypes;
		private static string[] rgstrGhostTypes = {"System.Object", "System.ValueType", "System.Delegate", "System.Enum"};


		static ToDoAssembly ()
		{
			htGhostTypes = new Hashtable ();

			foreach (string strGhostType in rgstrGhostTypes)
			{
				htGhostTypes.Add (strGhostType, null);
			}
		}

		public static ToDoAssembly Load (string strFileMono, string strName, string strNameMS)
		{
			Assembly assemblyMono = Assembly.LoadFrom (strFileMono);
			Assembly assemblyMS = Assembly.LoadWithPartialName (strNameMS);

			return new ToDoAssembly (strName, assemblyMono, assemblyMS);
		}

		public ToDoAssembly (string _strName, Assembly _assMono, Assembly _assMS)
		{
			strName = _strName;
			assMono = _assMono;
			assMS = _assMS;

			rgTypesMono = assMono.GetTypes ();
			rgTypesMS = assMS.GetTypes ();
			m_nodeStatus = new NodeStatus (_assMono, _assMS);
		}

		public override string Name {
			get {
				return strName;
			}
		}

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

		private Hashtable GetNamespaceMap (Type [] rgTypes)
		{
			Hashtable mapTypes = new Hashtable ();
			foreach (Type t in rgTypes)
			{
				if (t != null)
				{
					string strName = t.FullName;
					string strNamespace = t.Namespace;
					if (strNamespace != null && strNamespace.Length > 0 &&
						strName != null && strName.Length > 0 &&
						!strNamespace.StartsWith ("Microsoft.") &&
						!htGhostTypes.Contains (strName))
					{
						ArrayList rgContainedTypes = (ArrayList) mapTypes [strNamespace];
						if (rgContainedTypes == null)
						{
							rgContainedTypes = new ArrayList ();
							mapTypes [strNamespace] = rgContainedTypes;
						}
						rgContainedTypes.Add (t);
					}
				}
			}
			return mapTypes;
		}

		public override NodeStatus Analyze ()
		{
			Hashtable mapTypesMono = GetNamespaceMap (rgTypesMono);
			Hashtable mapTypesMS = GetNamespaceMap (rgTypesMS);

			foreach (string strNamespaceMS in mapTypesMS.Keys)
			{
				if (strNamespaceMS != null)
				{
					ArrayList rgContainedTypesMS = (ArrayList) mapTypesMS [strNamespaceMS];
					ArrayList rgContainedTypesMono = (ArrayList) mapTypesMono [strNamespaceMS];
					MissingNameSpace mns = new MissingNameSpace (strNamespaceMS, rgContainedTypesMono, rgContainedTypesMS);
					NodeStatus nsNamespace = mns.Analyze ();
					m_nodeStatus.AddChildren (nsNamespace);
					if (rgTypesMono != null)
						mapTypesMono.Remove (strNamespaceMS);
					rgNamespaces.Add (mns);
				}
			}
			foreach (string strNamespaceMono in mapTypesMono.Keys)
			{
				if (strNamespaceMono != null)
				{
					ArrayList rgContainedTypesMono = (ArrayList) mapTypesMono [strNamespaceMono];
					MissingNameSpace mns = new MissingNameSpace (strNamespaceMono, rgContainedTypesMono, null);
					NodeStatus nsNamespace = mns.Analyze ();
					m_nodeStatus.AddChildren (nsNamespace);
					rgNamespaces.Add (mns);
				}
			}

			rgAttributes = new ArrayList ();
			NodeStatus nsAttributes = MissingAttribute.AnalyzeAttributes (
				assMono.GetCustomAttributes (true),
				assMS.GetCustomAttributes (true),
				rgAttributes);
			m_nodeStatus.Add (nsAttributes);

			return m_nodeStatus;
		}


		public string CreateClassListReport() {
			Analyze ();
			if (rgNamespaces.Count == 0) return "";

			StringBuilder output = new StringBuilder();
			foreach (MissingNameSpace ns in rgNamespaces)
			{
				string[] missingTypes = ns.MissingTypeNames(true);
				if (missingTypes != null && missingTypes.Length > 0) {
					string joinedNames = String.Join("\n", missingTypes);
					output.Append(joinedNames + "\n");
				}
			}
			return output.ToString();
		}

		public override XmlElement CreateXML (XmlDocument doc)
		{
			XmlElement assemblyElem = base.CreateXML (doc);

			if (rgNamespaces.Count > 0)
			{
				XmlElement eltNamespaces = doc.CreateElement ("namespaces");
				assemblyElem.AppendChild (eltNamespaces);

				foreach (MissingNameSpace ns in rgNamespaces)
				{
					XmlElement eltNameSpace = ns.CreateXML (doc);
					if (eltNameSpace != null)
						eltNamespaces.AppendChild (eltNameSpace);
				}
			}
			return assemblyElem;
		}

		public void CreateXMLReport(string filename) {
			Analyze();

			XmlDocument outDoc;
			outDoc = new XmlDocument();
			outDoc.AppendChild(outDoc.CreateXmlDeclaration("1.0", null, null));

			XmlElement assembliesElem = outDoc.CreateElement("assemblies");
			outDoc.AppendChild(assembliesElem);

			XmlElement assemblyElem = CreateXML (outDoc);
			assembliesElem.AppendChild(assemblyElem);

			outDoc.Save(filename);
		}
	}
}