void CompareNestedTypes (ComparisonNode parent, ICompTypeContainer reference_container, ICompTypeContainer target_container) { CompareTypeLists (parent, reference_container.GetNestedInterfaces(), target_container.GetNestedInterfaces()); CompareTypeLists (parent, reference_container.GetNestedClasses(), target_container.GetNestedClasses()); CompareTypeLists (parent, reference_container.GetNestedStructs(), target_container.GetNestedStructs()); CompareTypeLists (parent, reference_container.GetNestedEnums(), target_container.GetNestedEnums()); CompareTypeLists (parent, reference_container.GetNestedDelegates(), target_container.GetNestedDelegates()); }
void CompareMemberLists(ComparisonNode parent, List<CompNamed> reference_list, List<CompNamed> target_list) { int m = 0, a = 0; UnityProfilesDocumentation.State state = profile_documentation.CurrentState; reference_list.Sort (CompNamed.Compare); target_list.Sort (CompNamed.Compare); while (m < reference_list.Count || a < target_list.Count) { if (m == reference_list.Count) { AddExtra (parent, target_list[a]); a++; continue; } else if (a == target_list.Count) { AddMissing (parent, reference_list[m]); m++; continue; } int c = String.Compare (reference_list[m].Name, target_list[a].Name); comparisons_performed ++; if (c == 0) { DocumentedMember currentMember; switch (reference_list[m].Type) { case CompType.Field: currentMember = profile_documentation.AddReferenceField (reference_list[m].Name); break; case CompType.Method: currentMember = profile_documentation.AddReferenceMethod (reference_list[m].Name); break; case CompType.Property: currentMember = profile_documentation.AddReferenceProperty (reference_list[m].Name); break; default: profile_documentation.CurrentMember = null; currentMember = null; break; } if (currentMember != null) { currentMember.AddSupportedProfile (target_profile); //Console.WriteLine ("\t\t\t\tAdded member {0} in profile {1}", reference_list[m].Name, target_profile); } /* the names match, further investigation is required */ // Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name); ComparisonNode comparison = target_list[a].GetComparisonNode(); parent.AddChild (comparison); if (reference_list[m] is CompMember && target_list[a] is CompMember) { string reference_type = ((CompMember)reference_list[m]).GetMemberType(); string target_type = ((CompMember)target_list[a]).GetMemberType(); if (reference_type != target_type) { HandleError (comparison, String.Format ("reference type is <i>{0}</i>, target type is <i>{1}</i>", reference_type, target_type)); } string reference_access = ((CompMember)reference_list[m]).GetMemberAccess(); string target_access = ((CompMember)target_list[a]).GetMemberAccess(); if (reference_access != target_access) { // Try to give some hints to the developer, best we can do with // strings. string extra_msg = ""; if (reference_access.IndexOf ("Public, Final, Virtual, HideBySig") != -1 && target_access.IndexOf ("Public, HideBySig") != -1){ extra_msg = "\n\t\t<b>Hint:</b> reference uses an implicit interface implementation, target doesn't"; } HandleError (comparison, String.Format ("reference access is '<i>{0}</i>', target access is '<i>{1}</i>'{2}", reference_access, target_access, extra_msg)); comparison.Status = ComparisonStatus.Error; } } if (reference_list[m] is CompMethod) { if (((CompMethod)target_list[a]).ThrowsNotImplementedException () && !((CompMethod)reference_list[m]).ThrowsNotImplementedException ()) { comparison.ThrowsNIE = true; } } if (reference_list[m] is CompField) { if (((CompField)reference_list[m]).GetLiteralValue() != ((CompField)target_list[a]).GetLiteralValue()) { HandleError (comparison, String.Format ("reference field has value {0}, target field has value {1}", ((CompField)reference_list[m]).GetLiteralValue(), ((CompField)target_list[a]).GetLiteralValue())); comparison.Status = ComparisonStatus.Error; } } if (reference_list[m] is ICompAttributeContainer) { //Console.WriteLine ("Comparing attributes for {0}", reference_list[m].Name); CompareAttributes (comparison, (ICompAttributeContainer)reference_list[m], (ICompAttributeContainer)target_list[a]); } if (reference_list[m] is ICompMemberContainer) { CompareMembers (comparison, (ICompMemberContainer)reference_list[m], (ICompMemberContainer)target_list[a]); } //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]); m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing (parent, reference_list[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra (parent, target_list[a]); a++; } } profile_documentation.CurrentState = state; }
void CompareTypeLists(ComparisonNode parent, List<CompNamed> reference_list, List<CompNamed> target_list) { int m = 0, a = 0; UnityProfilesDocumentation.State state = profile_documentation.CurrentState; reference_list.Sort (CompNamed.Compare); target_list.Sort (CompNamed.Compare); while (m < reference_list.Count || a < target_list.Count) { if (m == reference_list.Count) { AddExtra (parent, target_list[a]); a++; continue; } else if (a == target_list.Count) { AddMissing (parent, reference_list[m]); m++; continue; } int c = String.Compare (reference_list[m].Name, target_list[a].Name); comparisons_performed ++; //Console.WriteLine ("\t\t\t\tWorking on item {0} [type {1}] in profile {2}", reference_list[m].Name, reference_list[m].Type, target_profile); if (c == 0) { ProgressChange ((double)comparisons_performed / total_comparisons * 100.0, String.Format ("Comparing {0} {1}", reference_list[m].Type, reference_list[m].Name)); switch (reference_list[m].Type) { case CompType.Namespace: profile_documentation.AddReferenceNamespace (reference_list[m].Name); profile_documentation.CurrentClass = null; //Console.WriteLine ("\t\t\t\tAdding namespace {0} in profile {1}", reference_list[m].Name, target_profile); break; case CompType.Class: profile_documentation.AddReferenceClass (reference_list[m].Name); profile_documentation.CurrentClass.AddSupportedProfile (target_profile); //Console.WriteLine ("\t\t\t\tAdding class {0} in profile {1}", reference_list[m].Name, target_profile); break; default: break; } /* the names match, further investigation is required */ ComparisonNode comparison = target_list[a].GetComparisonNode(); parent.AddChild (comparison); // compare base types if (reference_list[m] is ICompHasBaseType && target_list[a] is ICompHasBaseType) { CompareBaseTypes (comparison, (ICompHasBaseType)reference_list[m], (ICompHasBaseType)target_list[a]); } // compares generic type parameters if (reference_list[m] is ICompGenericParameter && target_list[a] is ICompGenericParameter) { CompareTypeParameters (comparison, (ICompGenericParameter)reference_list[m], (ICompGenericParameter)target_list[a]); } // compare nested types if (reference_list[m] is ICompTypeContainer && target_list[a] is ICompTypeContainer) { CompareNestedTypes (comparison, (ICompTypeContainer)reference_list[m], (ICompTypeContainer)target_list[a]); } if (reference_list[m] is ICompMemberContainer && target_list[a] is ICompMemberContainer) { CompareMembers (comparison, (ICompMemberContainer)reference_list[m], (ICompMemberContainer)target_list[a]); } if (reference_list[m] is ICompAttributeContainer && target_list[a] is ICompAttributeContainer) { CompareAttributes (comparison, (ICompAttributeContainer)reference_list[m], (ICompAttributeContainer)target_list[a]); } m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing (parent, reference_list[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra (parent, target_list[a]); a++; } } profile_documentation.CurrentState = state; }
static string GetTodo(ComparisonNode cn) { StringBuilder sb = new StringBuilder (); foreach (string s in cn.Todos){ int idx = s.IndexOf ('('); string clean = s; if (idx != 0) { int end = clean.LastIndexOf (')'); int l = end - idx - 1; if (l >= 0) clean = clean.Substring (idx + 1, end - idx - 1); } if (clean == "") { sb.Append ("Flagged with TODO"); } else { sb.Append ("<b>TODO Comment:</b> "); sb.Append (clean); sb.Append ("<br>"); } } return sb.ToString (); }
void CompareTypeParameters (ComparisonNode parent, ICompGenericParameter reference, ICompGenericParameter target) { var r = reference.GetTypeParameters (); var t = target.GetTypeParameters (); if (r == null && t == null || (r == null && t != null) || (r != null && t == null)) return; for (int i = 0; i < r.Count; ++i) { var r_i = r [i]; var t_i = t [i]; if (r_i.GenericAttributes != t_i.GenericAttributes) { parent.AddError (string.Format ("Expected type parameter {2} with {0} generic attributes but found type parameter {3} with {1} generic attributes", CompGenericParameter.GetGenericAttributeDesc (r_i.GenericAttributes), CompGenericParameter.GetGenericAttributeDesc (t_i.GenericAttributes), r_i.Name, t_i.Name)); } // TODO: Compare constraints properly if (r_i.HasConstraints != t_i.HasConstraints) { parent.AddError (string.Format ("Type parameter `{0}' constraints mismatch", r_i.Name)); } CompareAttributes (parent, r_i, t_i); } }
void CompareMembers (ComparisonNode parent, ICompMemberContainer reference_container, ICompMemberContainer target_container) { CompareMemberLists (parent, reference_container.GetInterfaces(), target_container.GetInterfaces()); CompareMemberLists (parent, reference_container.GetConstructors(), target_container.GetConstructors()); CompareMemberLists (parent, reference_container.GetMethods(), target_container.GetMethods()); CompareMemberLists (parent, reference_container.GetProperties(), target_container.GetProperties()); CompareMemberLists (parent, reference_container.GetFields(), target_container.GetFields()); CompareMemberLists (parent, reference_container.GetEvents(), target_container.GetEvents()); }
public void AddChild(ComparisonNode node) { Children.Add(node); node.Parent = this; }
void CompareMemberLists(ComparisonNode parent, List <CompNamed> reference_list, List <CompNamed> target_list) { int m = 0, a = 0; UnityProfilesDocumentation.State state = profile_documentation.CurrentState; reference_list.Sort(CompNamed.Compare); target_list.Sort(CompNamed.Compare); while (m < reference_list.Count || a < target_list.Count) { if (m == reference_list.Count) { AddExtra(parent, target_list[a]); a++; continue; } else if (a == target_list.Count) { AddMissing(parent, reference_list[m]); m++; continue; } int c = String.Compare(reference_list[m].Name, target_list[a].Name); comparisons_performed++; if (c == 0) { DocumentedMember currentMember; switch (reference_list[m].Type) { case CompType.Field: currentMember = profile_documentation.AddReferenceField(reference_list[m].Name); break; case CompType.Method: currentMember = profile_documentation.AddReferenceMethod(reference_list[m].Name); break; case CompType.Property: currentMember = profile_documentation.AddReferenceProperty(reference_list[m].Name); break; default: profile_documentation.CurrentMember = null; currentMember = null; break; } if (currentMember != null) { currentMember.AddSupportedProfile(target_profile); //Console.WriteLine ("\t\t\t\tAdded member {0} in profile {1}", reference_list[m].Name, target_profile); } /* the names match, further investigation is required */ // Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name); ComparisonNode comparison = target_list[a].GetComparisonNode(); parent.AddChild(comparison); if (reference_list[m] is CompMember && target_list[a] is CompMember) { string reference_type = ((CompMember)reference_list[m]).GetMemberType(); string target_type = ((CompMember)target_list[a]).GetMemberType(); if (reference_type != target_type) { HandleError(comparison, String.Format("reference type is <i>{0}</i>, target type is <i>{1}</i>", reference_type, target_type)); } string reference_access = ((CompMember)reference_list[m]).GetMemberAccess(); string target_access = ((CompMember)target_list[a]).GetMemberAccess(); if (reference_access != target_access) { // Try to give some hints to the developer, best we can do with // strings. string extra_msg = ""; if (reference_access.IndexOf("Public, Final, Virtual, HideBySig") != -1 && target_access.IndexOf("Public, HideBySig") != -1) { extra_msg = "\n\t\t<b>Hint:</b> reference uses an implicit interface implementation, target doesn't"; } HandleError(comparison, String.Format("reference access is '<i>{0}</i>', target access is '<i>{1}</i>'{2}", reference_access, target_access, extra_msg)); comparison.Status = ComparisonStatus.Error; } } if (reference_list[m] is CompMethod) { if (((CompMethod)target_list[a]).ThrowsNotImplementedException() && !((CompMethod)reference_list[m]).ThrowsNotImplementedException()) { comparison.ThrowsNIE = true; } } if (reference_list[m] is CompField) { if (((CompField)reference_list[m]).GetLiteralValue() != ((CompField)target_list[a]).GetLiteralValue()) { HandleError(comparison, String.Format("reference field has value {0}, target field has value {1}", ((CompField)reference_list[m]).GetLiteralValue(), ((CompField)target_list[a]).GetLiteralValue())); comparison.Status = ComparisonStatus.Error; } } if (reference_list[m] is ICompAttributeContainer) { //Console.WriteLine ("Comparing attributes for {0}", reference_list[m].Name); CompareAttributes(comparison, (ICompAttributeContainer)reference_list[m], (ICompAttributeContainer)target_list[a]); } if (reference_list[m] is ICompMemberContainer) { CompareMembers(comparison, (ICompMemberContainer)reference_list[m], (ICompMemberContainer)target_list[a]); } //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]); m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing(parent, reference_list[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra(parent, target_list[a]); a++; } } profile_documentation.CurrentState = state; }
void AddMissing(ComparisonNode parent, CompNamed item) { ComparisonNode node = item.GetComparisonNode(); parent.AddChild(node); node.Status = ComparisonStatus.Missing; comparisons_performed++; if (item is ICompHasBaseType) { string baseTypeName = ((ICompHasBaseType)item).GetBaseType(); if (!string.IsNullOrEmpty(baseTypeName)) { ComparisonNode baseTypeNode = new ComparisonNode(CompType.Class, string.Format("BaseType: {0}", baseTypeName), baseTypeName); baseTypeNode.Status = ComparisonStatus.Missing; node.AddChild(baseTypeNode); } } if (item is ICompTypeContainer) { ICompTypeContainer c = (ICompTypeContainer)item; foreach (CompNamed ifc in c.GetNestedInterfaces()) { AddMissing(node, ifc); } foreach (CompNamed cls in c.GetNestedClasses()) { AddMissing(node, cls); } foreach (CompNamed cls in c.GetNestedStructs()) { AddMissing(node, cls); } foreach (CompNamed en in c.GetNestedEnums()) { AddMissing(node, en); } } if (item is ICompMemberContainer) { ICompMemberContainer c = (ICompMemberContainer)item; foreach (CompNamed ifc in c.GetInterfaces()) { AddMissing(node, ifc); } foreach (CompNamed m in c.GetConstructors()) { AddMissing(node, m); } foreach (CompNamed m in c.GetMethods()) { AddMissing(node, m); } foreach (CompNamed p in c.GetProperties()) { AddMissing(node, p); } foreach (CompNamed f in c.GetFields()) { AddMissing(node, f); } foreach (CompNamed e in c.GetEvents()) { AddMissing(node, e); } } if (item is ICompAttributeContainer) { ICompAttributeContainer c = (ICompAttributeContainer)item; foreach (CompNamed attr in c.GetAttributes()) { AddMissing(node, attr); } } }
void CompareMemberLists(ComparisonNode parent, List <CompNamed> reference_list, List <CompNamed> target_list, bool isSealed) { int m = 0, a = 0; reference_list.Sort(CompNamed.Compare); target_list.Sort(CompNamed.Compare); while (m < reference_list.Count || a < target_list.Count) { if (m == reference_list.Count) { AddExtra(parent, target_list[a]); a++; continue; } else if (a == target_list.Count) { AddMissing(parent, reference_list[m]); m++; continue; } int c = CompNamed.Compare(reference_list[m], target_list[a]); comparisons_performed++; if (c == 0) { /* the names match, further investigation is required */ // Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name); ComparisonNode comparison = target_list[a].GetComparisonNode(); parent.AddChild(comparison); if (reference_list[m] is CompMember && target_list[a] is CompMember) { string reference_type = ((CompMember)reference_list[m]).GetMemberType(); string target_type = ((CompMember)target_list[a]).GetMemberType(); if (reference_type != target_type) { comparison.AddError(String.Format("reference type is <i>{0}</i>, target type is <i>{1}</i>", reference_type, target_type)); } string reference_access = ((CompMember)reference_list[m]).GetMemberAccess(); string target_access = ((CompMember)target_list[a]).GetMemberAccess(); if (reference_access != target_access) { // Try to give some hints to the developer, best we can do with // strings. string extra_msg = ""; if (reference_access.IndexOf("Private, Final, Virtual, HideBySig") != -1 && target_access.IndexOf("Public, HideBySig") != -1) { extra_msg = "\n\t\t<b>Hint:</b> reference uses an explicit interface implementation, target doesn't"; } comparison.AddError(String.Format("reference access is '<i>{0}</i>', target access is '<i>{1}</i>'{2}", reference_access, target_access, extra_msg)); comparison.Status = ComparisonStatus.Error; } } var r_method = reference_list[m] as CompMethod; if (r_method != null) { var t_method = (CompMethod)target_list[a]; if (t_method.ThrowsNotImplementedException() && !r_method.ThrowsNotImplementedException()) { comparison.ThrowsNIE = true; } CompareTypeParameters(comparison, r_method, t_method); CompareParameters(comparison, r_method, t_method); } else if (reference_list[m] is CompProperty) { var m1 = ((CompProperty)reference_list[m]).GetMethods(); var m2 = ((CompProperty)target_list[a]).GetMethods(); if (m1.Count != m2.Count) { comparison.AddError(String.Format("Expected {0} accessors but found {1}", m1.Count, m2.Count)); comparison.Status = ComparisonStatus.Error; } else { for (int i = 0; i < m1.Count; ++i) { string reference_access = ((CompMember)m1[i]).GetMemberAccess(); string target_access = ((CompMember)m2[i]).GetMemberAccess(); if (reference_access != target_access) { // Try to give some hints to the developer, best we can do with // strings. string extra_msg = ""; if (reference_access.IndexOf("Private, Final, Virtual, HideBySig") != -1 && target_access.IndexOf("Public, HideBySig") != -1) { extra_msg = "\n\t\t<b>Hint:</b> reference uses an explicit interface implementation, target doesn't"; } comparison.AddError(String.Format("reference access is '<i>{0}</i>', target access is '<i>{1}</i>'{2}", reference_access, target_access, extra_msg)); comparison.Status = ComparisonStatus.Error; break; } } if (m1[0].Name[0] == m2[0].Name[0]) { CompareAttributes(comparison, (ICompAttributeContainer)m1[0], (ICompAttributeContainer)m2[0]); if (m1.Count > 1) { CompareAttributes(comparison, (ICompAttributeContainer)m1[1], (ICompAttributeContainer)m2[1]); } } else { CompareAttributes(comparison, (ICompAttributeContainer)m1[0], (ICompAttributeContainer)m2[1]); if (m1.Count > 1) { CompareAttributes(comparison, (ICompAttributeContainer)m1[1], (ICompAttributeContainer)m2[0]); } } } // Compare indexer parameters if (m1.Count == m2.Count) { CompareParameters(comparison, (ICompParameters)m1[0], (ICompParameters)m2[0]); } } if (reference_list[m] is CompField) { var v_ref = ((CompField)reference_list[m]).GetLiteralValue(); var v_tar = ((CompField)target_list[a]).GetLiteralValue(); if (v_ref != v_tar) { comparison.AddError(String.Format("Expected field value {0} but found value {1}", v_ref, v_tar)); comparison.Status = ComparisonStatus.Error; } } if (reference_list[m] is ICompAttributeContainer) { //Console.WriteLine ("Comparing attributes for {0}", reference_list[m].Name); CompareAttributes(comparison, (ICompAttributeContainer)reference_list[m], (ICompAttributeContainer)target_list[a]); } if (reference_list[m] is ICompMemberContainer) { CompareMembers(comparison, (ICompMemberContainer)reference_list[m], (ICompMemberContainer)target_list[a]); } //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]); m++; a++; } else if (c < 0) { if (isSealed && reference_list[m].Name.Contains("~")) { // Ignore finalizer differences in sealed classes } else { /* reference name is before target name, reference name is missing from target */ AddMissing(parent, reference_list[m]); } m++; } else { if (isSealed && target_list[a].Name.Contains("~")) { // Ignore finalizer differences in sealed classes } else { /* reference name is after target name, target name is extra */ AddExtra(parent, target_list[a]); } a++; } } }
void CompareTypeLists(ComparisonNode parent, List <CompNamed> reference_list, List <CompNamed> target_list) { int m = 0, a = 0; UnityProfilesDocumentation.State state = profile_documentation.CurrentState; reference_list.Sort(CompNamed.Compare); target_list.Sort(CompNamed.Compare); while (m < reference_list.Count || a < target_list.Count) { if (m == reference_list.Count) { AddExtra(parent, target_list[a]); a++; continue; } else if (a == target_list.Count) { AddMissing(parent, reference_list[m]); m++; continue; } int c = String.Compare(reference_list[m].Name, target_list[a].Name); comparisons_performed++; //Console.WriteLine ("\t\t\t\tWorking on item {0} [type {1}] in profile {2}", reference_list[m].Name, reference_list[m].Type, target_profile); if (c == 0) { ProgressChange((double)comparisons_performed / total_comparisons * 100.0, String.Format("Comparing {0} {1}", reference_list[m].Type, reference_list[m].Name)); switch (reference_list[m].Type) { case CompType.Namespace: profile_documentation.AddReferenceNamespace(reference_list[m].Name); profile_documentation.CurrentClass = null; //Console.WriteLine ("\t\t\t\tAdding namespace {0} in profile {1}", reference_list[m].Name, target_profile); break; case CompType.Class: profile_documentation.AddReferenceClass(reference_list[m].Name); profile_documentation.CurrentClass.AddSupportedProfile(target_profile); //Console.WriteLine ("\t\t\t\tAdding class {0} in profile {1}", reference_list[m].Name, target_profile); break; default: break; } /* the names match, further investigation is required */ ComparisonNode comparison = target_list[a].GetComparisonNode(); parent.AddChild(comparison); // compare base types if (reference_list[m] is ICompHasBaseType && target_list[a] is ICompHasBaseType) { CompareBaseTypes(comparison, (ICompHasBaseType)reference_list[m], (ICompHasBaseType)target_list[a]); } // compares generic type parameters if (reference_list[m] is ICompGenericParameter && target_list[a] is ICompGenericParameter) { CompareTypeParameters(comparison, (ICompGenericParameter)reference_list[m], (ICompGenericParameter)target_list[a]); } // compare nested types if (reference_list[m] is ICompTypeContainer && target_list[a] is ICompTypeContainer) { CompareNestedTypes(comparison, (ICompTypeContainer)reference_list[m], (ICompTypeContainer)target_list[a]); } if (reference_list[m] is ICompMemberContainer && target_list[a] is ICompMemberContainer) { CompareMembers(comparison, (ICompMemberContainer)reference_list[m], (ICompMemberContainer)target_list[a]); } if (reference_list[m] is ICompAttributeContainer && target_list[a] is ICompAttributeContainer) { CompareAttributes(comparison, (ICompAttributeContainer)reference_list[m], (ICompAttributeContainer)target_list[a]); } m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing(parent, reference_list[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra(parent, target_list[a]); a++; } } profile_documentation.CurrentState = state; }
void CompareAttributeArguments(ComparisonNode parent, CompAttribute referenceAttribute, CompAttribute actualAttribute) { // Ignore all parameter differences for some attributes switch (referenceAttribute.Name) { case "System.Diagnostics.DebuggerDisplayAttribute": case "System.Diagnostics.DebuggerTypeProxyAttribute": case "System.Runtime.CompilerServices.CompilationRelaxationsAttribute": case "System.Reflection.AssemblyFileVersionAttribute": case "System.Reflection.AssemblyCompanyAttribute": case "System.Reflection.AssemblyCopyrightAttribute": case "System.Reflection.AssemblyProductAttribute": case "System.Reflection.AssemblyTrademarkAttribute": case "System.Reflection.AssemblyInformationalVersionAttribute": case "System.Reflection.AssemblyKeyFileAttribute": // Don't care about these for now case "System.ComponentModel.EditorAttribute": case "System.ComponentModel.DesignerAttribute": return; } foreach (var entry in referenceAttribute.Properties) { if (!actualAttribute.Properties.ContainsKey(entry.Key)) { // // Ignore missing value difference for default values // switch (referenceAttribute.Name) { case "System.AttributeUsageAttribute": // AllowMultiple defaults to false if (entry.Key == "AllowMultiple" && entry.Value == "False") { continue; } // Inherited defaults to true if (entry.Key == "Inherited" && entry.Value == "True") { continue; } break; case "System.ObsoleteAttribute": if (entry.Key == "IsError" && entry.Value == "False") { continue; } if (entry.Key == "Message") { continue; } break; } parent.AddError(String.Format("Property `{0}' value is not set. Expected value: {1}", entry.Key, entry.Value)); parent.Status = ComparisonStatus.Error; continue; } var target_value = actualAttribute.Properties[entry.Key]; switch (referenceAttribute.Name) { case "System.Runtime.CompilerServices.TypeForwardedFromAttribute": if (entry.Key == "AssemblyFullName") { target_value = target_value.Replace("neutral", "Neutral"); } break; case "System.Runtime.InteropServices.GuidAttribute": if (entry.Key == "Value") { target_value = target_value.ToUpperInvariant(); } break; case "System.ObsoleteAttribute": if (entry.Key == "Message") { continue; } break; } if (target_value != entry.Value) { parent.AddError(String.Format("Expected value `{0}' for attribute property `{1}' but found `{2}'", entry.Value, entry.Key, target_value)); parent.Status = ComparisonStatus.Error; } } if (referenceAttribute.Properties.Count != actualAttribute.Properties.Count) { foreach (var entry in actualAttribute.Properties) { if (!referenceAttribute.Properties.ContainsKey(entry.Key)) { parent.AddError(String.Format("Property `{0}' should not be set", entry.Key)); parent.Status = ComparisonStatus.Error; break; } } } return; }
void CompareAttributes(ComparisonNode parent, ICompAttributeContainer reference_container, ICompAttributeContainer target_container) { int m = 0, a = 0; List <CompNamed> reference_attrs = reference_container.GetAttributes(); List <CompNamed> target_attrs = target_container.GetAttributes(); Comparison <CompNamed> comp = (x, y) => { var r = CompNamed.Compare(x, y); if (r != 0) { return(r); } var xa = ((CompAttribute)x).Properties.Values.ToList(); var ya = ((CompAttribute)y).Properties.Values.ToList(); for (int i = 0; i < Math.Min(xa.Count, ya.Count); ++i) { r = xa[i].CompareTo(ya[i]); if (r != 0) { return(r); } } return(0); }; reference_attrs.Sort(comp); target_attrs.Sort(comp); while (m < reference_attrs.Count || a < target_attrs.Count) { if (m == reference_attrs.Count) { switch (target_attrs[a].Name) { case "System.Diagnostics.DebuggerDisplayAttribute": case "System.Runtime.CompilerServices.AsyncStateMachineAttribute": case "System.Runtime.CompilerServices.IteratorStateMachineAttribute": case "System.Diagnostics.DebuggerBrowsableAttribute": // Ignore extra attributes in Mono source code break; default: AddExtra(parent, target_attrs[a]); break; } a++; continue; } else if (a == target_attrs.Count) { AddMissing(parent, reference_attrs[m]); m++; continue; } int c = String.Compare(reference_attrs[m].Name, target_attrs[a].Name); comparisons_performed++; if (c == 0) { /* the names match, further investigation is required */ ComparisonNode comparison = target_attrs[a].GetComparisonNode(); parent.AddChild(comparison); CompareAttributeArguments(comparison, (CompAttribute)reference_attrs[m], (CompAttribute)target_attrs[a]); m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing(parent, reference_attrs[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra(parent, target_attrs[a]); a++; } } }
void CompareTypeLists(ComparisonNode parent, List <CompNamed> reference_list, List <CompNamed> target_list) { int m = 0, a = 0; reference_list.Sort(CompNamed.Compare); target_list.Sort(CompNamed.Compare); while (m < reference_list.Count || a < target_list.Count) { if (m == reference_list.Count) { AddExtra(parent, target_list[a]); a++; continue; } else if (a == target_list.Count) { AddMissing(parent, reference_list[m]); m++; continue; } int c = String.Compare(reference_list[m].Name, target_list[a].Name); comparisons_performed++; if (c == 0) { ProgressChange((double)comparisons_performed / total_comparisons * 100.0, String.Format("Comparing {0} {1}", reference_list[m].Type, reference_list[m].Name)); /* the names match, further investigation is required */ ComparisonNode comparison = target_list[a].GetComparisonNode(); parent.AddChild(comparison); // compare base types if (reference_list[m] is ICompHasBaseType && target_list[a] is ICompHasBaseType) { CompareBaseTypes(comparison, (ICompHasBaseType)reference_list[m], (ICompHasBaseType)target_list[a]); } // compares generic type parameters if (reference_list[m] is ICompGenericParameter && target_list[a] is ICompGenericParameter) { CompareTypeParameters(comparison, (ICompGenericParameter)reference_list[m], (ICompGenericParameter)target_list[a]); } // compare nested types if (reference_list[m] is ICompTypeContainer && target_list[a] is ICompTypeContainer) { CompareNestedTypes(comparison, (ICompTypeContainer)reference_list[m], (ICompTypeContainer)target_list[a]); } if (reference_list[m] is ICompMemberContainer && target_list[a] is ICompMemberContainer) { CompareMembers(comparison, (ICompMemberContainer)reference_list[m], (ICompMemberContainer)target_list[a]); } if (reference_list[m] is ICompAttributeContainer && target_list[a] is ICompAttributeContainer) { CompareAttributes(comparison, (ICompAttributeContainer)reference_list[m], (ICompAttributeContainer)target_list[a]); } m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing(parent, reference_list[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra(parent, target_list[a]); a++; } } }
void CompareParameters (ComparisonNode parent, ICompParameters reference, ICompParameters target) { var r = reference.GetParameters (); var t = target.GetParameters (); if (r.Count != t.Count) { throw new NotImplementedException (string.Format ("Should never happen with valid data ({0} != {1})", r.Count, t.Count)); } for (int i = 0; i < r.Count; ++i) { var r_i = r [i]; var t_i = t [i]; if (r_i.TypeReference != t_i.TypeReference) { parent.AddError (string.Format ("Parameter `{0}' type mismatch", t_i.Name)); } if (r_i.Name != t_i.Name) { parent.AddError (string.Format ("Parameter name `{0}' should be `{1}'", t_i.Name, r_i.Name)); } if (r_i.IsOptional != t_i.IsOptional) { if (r_i.IsOptional) parent.AddError (string.Format ("Parameter `{0}' is missing a default value", t_i.Name)); else parent.AddError (string.Format ("Parameter `{0}' should not have a default value", t_i.Name)); } CompareAttributes (parent, r_i, t_i); } }
void HandleError(ComparisonNode node, string message) { node.AddError(message); profile_documentation.AddError(message); }
void CompareTypeLists (ComparisonNode parent, List<CompNamed> reference_list, List<CompNamed> target_list) { int m = 0, a = 0; reference_list.Sort (CompNamed.Compare); target_list.Sort (CompNamed.Compare); while (m < reference_list.Count || a < target_list.Count) { if (m == reference_list.Count) { AddExtra (parent, target_list[a]); a++; continue; } else if (a == target_list.Count) { AddMissing (parent, reference_list[m]); m++; continue; } int c = String.Compare (reference_list[m].Name, target_list[a].Name); comparisons_performed ++; if (c == 0) { ProgressChange ((double)comparisons_performed / total_comparisons * 100.0, String.Format ("Comparing {0} {1}", reference_list[m].Type, reference_list[m].Name)); /* the names match, further investigation is required */ ComparisonNode comparison = target_list[a].GetComparisonNode(); parent.AddChild (comparison); // compare base types if (reference_list[m] is ICompHasBaseType && target_list[a] is ICompHasBaseType) { CompareBaseTypes (comparison, (ICompHasBaseType)reference_list[m], (ICompHasBaseType)target_list[a]); } // compares generic type parameters if (reference_list[m] is ICompGenericParameter && target_list[a] is ICompGenericParameter) { CompareTypeParameters (comparison, (ICompGenericParameter)reference_list[m], (ICompGenericParameter)target_list[a]); } // compare nested types if (reference_list[m] is ICompTypeContainer && target_list[a] is ICompTypeContainer) { CompareNestedTypes (comparison, (ICompTypeContainer)reference_list[m], (ICompTypeContainer)target_list[a]); } if (reference_list[m] is ICompMemberContainer && target_list[a] is ICompMemberContainer) { CompareMembers (comparison, (ICompMemberContainer)reference_list[m], (ICompMemberContainer)target_list[a]); } if (reference_list[m] is ICompAttributeContainer && target_list[a] is ICompAttributeContainer) { CompareAttributes (comparison, (ICompAttributeContainer)reference_list[m], (ICompAttributeContainer)target_list[a]); } m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing (parent, reference_list[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra (parent, target_list[a]); a++; } } }
public ComparisonNode GetNodeByName(string node_name, bool get_children, bool get_messages) { if (String.IsNullOrEmpty (node_name)) node_name = "0"; ComparisonNode node = null; using (IDbConnection cnc = GetConnection ()) { IDbCommand cmd = GetCommandForProcedure (cnc, "get_node_by_name"); AddParameter (cmd, "master_id", MasterID); AddParameter (cmd, "nodename", node_name); //Console.WriteLine ("call get_node_by_name ('{0}')", node_name); using (IDataReader reader = cmd.ExecuteReader ()) { if (reader.Read ()) { CompType comp_type = (CompType) reader ["comparison_type"]; string display_name = reader ["name"] as string; string type_name = reader ["typename"] as string; node = new ComparisonNode (comp_type, display_name, type_name); SetValuesFromReader (reader, node); } } if (node != null) { // Get only this node's messages before calling GetChildren if (get_messages) GetMessagesForNodeRecursive (cnc, node); if (get_children) GetChildren (node); } } return node; }
void AddExtra (ComparisonNode parent, CompNamed item) { ComparisonNode node = item.GetComparisonNode (); parent.AddChild (node); node.Status = ComparisonStatus.Extra; if (item is ICompTypeContainer) { ICompTypeContainer c = (ICompTypeContainer)item; foreach (CompNamed ifc in c.GetNestedInterfaces ()) AddExtra (node, ifc); foreach (CompNamed cls in c.GetNestedClasses()) AddExtra (node, cls); foreach (CompNamed cls in c.GetNestedStructs()) AddExtra (node, cls); foreach (CompNamed en in c.GetNestedEnums()) AddExtra (node, en); } }
static void SetValuesFromReader(IDataReader reader, ComparisonNode node) { node.InternalID = reader ["node_name"]; node.Status = (ComparisonStatus) reader ["status"]; node.ThrowsNIE = (bool) reader ["throwsnie"]; node.Extra = (int) reader ["extras"]; node.Missing = (int) reader ["missing"]; node.Present = (int) reader ["present"]; node.Warning = (int) reader ["warning"]; node.Todo = (int) reader ["todo"]; node.Niex = (int) reader ["niex"]; node.HasChildren = (bool) reader ["has_children"]; node.HasMessages = (bool) reader ["has_messages"]; }
static Control GetStatusImage(ComparisonNode n, bool is_container) { WebControl img = new WebControl (HtmlTextWriterTag.Span); img.Controls.Add (new Literal () { Text = " "} ); img.CssClass = "icons "; switch (n.Status) { case ComparisonStatus.Missing: img.CssClass += "stmiss"; break; case ComparisonStatus.Extra: img.CssClass += "stextra"; break; case ComparisonStatus.Error: img.CssClass += "sterror"; break; case ComparisonStatus.None: if (!is_container && n.Niex > 0) img.CssClass += "stniex"; else if (n.Todos.Count > 0) img.CssClass += "sttodo"; else img.CssClass += "stnone"; break; } return img; }
void GetMessagesForNodeRecursive(IDbConnection cnc, ComparisonNode node) { if (node.HasMessages) { IDbCommand cmd = GetCommandForProcedure (cnc, "get_messages"); AddParameter (cmd, "master_id", MasterID); AddParameter (cmd, "nodename", node.InternalID); //Console.WriteLine ("call get_messages('{0}')", node.InternalID); using (IDataReader reader = cmd.ExecuteReader ()) { while (reader.Read ()) { bool is_todo = Convert.ToBoolean (reader ["is_todo"]); object t = reader ["message"]; if (t != null && t != DBNull.Value) { List<string> list = (is_todo) ? node.Todos : node.Messages; list.Add ((string) t); } } } } // Callers will not have the entire tree populated, just 1 node and its direct children foreach (ComparisonNode child in node.Children) GetMessagesForNodeRecursive (cnc, child); }
public void AddChild (ComparisonNode node) { Children.Add (node); node.Parent = this; }
void CompareAttributes (ComparisonNode parent, ICompAttributeContainer reference_container, ICompAttributeContainer target_container) { int m = 0, a = 0; List<CompNamed> reference_attrs = reference_container.GetAttributes (); List<CompNamed> target_attrs = target_container.GetAttributes (); reference_attrs.Sort (CompNamed.Compare); target_attrs.Sort (CompNamed.Compare); while (m < reference_attrs.Count || a < target_attrs.Count) { if (m == reference_attrs.Count) { switch (target_attrs[a].Name) { case "System.Diagnostics.DebuggerDisplayAttribute": case "System.Runtime.CompilerServices.AsyncStateMachineAttribute": case "System.Runtime.CompilerServices.IteratorStateMachineAttribute": // Ignore extra attributes in Mono source code break; default: AddExtra (parent, target_attrs[a]); break; } a++; continue; } else if (a == target_attrs.Count) { AddMissing (parent, reference_attrs[m]); m++; continue; } int c = String.Compare (reference_attrs[m].Name, target_attrs[a].Name); comparisons_performed ++; if (c == 0) { /* the names match, further investigation is required */ // Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name); ComparisonNode comparison = target_attrs[a].GetComparisonNode(); parent.AddChild (comparison); //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]); m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing (parent, reference_attrs[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra (parent, target_attrs[a]); a++; } } }
void AddExtra(ComparisonNode parent, CompNamed item) { ComparisonNode node = item.GetComparisonNode (); parent.AddChild (node); node.Status = ComparisonStatus.Extra; profile_documentation.AddError (String.Format ("Extra contents \"{0}\" in \"{1}\"", item.DisplayName, parent.Name)); if (item is ICompTypeContainer) { ICompTypeContainer c = (ICompTypeContainer)item; foreach (CompNamed ifc in c.GetNestedInterfaces ()) AddExtra (node, ifc); foreach (CompNamed cls in c.GetNestedClasses()) AddExtra (node, cls); foreach (CompNamed cls in c.GetNestedStructs()) AddExtra (node, cls); foreach (CompNamed en in c.GetNestedEnums()) AddExtra (node, en); } }
void CompareAttributes (ComparisonNode parent, ICompAttributeContainer reference_container, ICompAttributeContainer target_container) { int m = 0, a = 0; List<CompNamed> reference_attrs = reference_container.GetAttributes (); List<CompNamed> target_attrs = target_container.GetAttributes (); Comparison<CompNamed> comp = (x, y) => { var r = CompNamed.Compare (x, y); if (r != 0) return r; var xa = ((CompAttribute)x).Properties.Values.ToList (); var ya = ((CompAttribute)y).Properties.Values.ToList (); for (int i = 0; i < Math.Min (xa.Count, ya.Count); ++i) { r = xa[i].CompareTo (ya[i]); if (r != 0) return r; } return 0; }; reference_attrs.Sort (comp); target_attrs.Sort (comp); while (m < reference_attrs.Count || a < target_attrs.Count) { if (m == reference_attrs.Count) { switch (target_attrs[a].Name) { case "System.Diagnostics.DebuggerDisplayAttribute": case "System.Runtime.CompilerServices.AsyncStateMachineAttribute": case "System.Runtime.CompilerServices.IteratorStateMachineAttribute": case "System.Diagnostics.DebuggerBrowsableAttribute": // Ignore extra attributes in Mono source code break; default: AddExtra (parent, target_attrs[a]); break; } a++; continue; } else if (a == target_attrs.Count) { AddMissing (parent, reference_attrs[m]); m++; continue; } int c = String.Compare (reference_attrs[m].Name, target_attrs[a].Name); comparisons_performed ++; if (c == 0) { /* the names match, further investigation is required */ ComparisonNode comparison = target_attrs[a].GetComparisonNode(); parent.AddChild (comparison); CompareAttributeArguments (comparison, (CompAttribute)reference_attrs[m], (CompAttribute)target_attrs[a]); m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing (parent, reference_attrs[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra (parent, target_attrs[a]); a++; } } }
void CompareThread() { try { ProgressChange (Double.NaN, "Loading reference..."); if (!TryLoad (ref reference, reference_loader)) return; ProgressChange (Double.NaN, "Loading target..."); if (!TryLoad (ref target, target_loader)) return; ProgressChange (0.0, "Comparing..."); comparison = target.GetComparisonNode (); List<CompNamed> ref_namespaces = reference.GetNamespaces(); total_comparisons = CountComparisons (ref_namespaces); comparisons_performed = 0; CompareTypeLists (comparison, reference.GetNamespaces(), target.GetNamespaces()); CompareAttributes (comparison, reference, target); } catch (Exception exc) { OnError (exc.Message); } finally { Finish (); } }
void CompareAttributeArguments (ComparisonNode parent, CompAttribute referenceAttribute, CompAttribute actualAttribute) { // Ignore all parameter differences for some attributes switch (referenceAttribute.Name) { case "System.Diagnostics.DebuggerDisplayAttribute": case "System.Diagnostics.DebuggerTypeProxyAttribute": case "System.Runtime.CompilerServices.CompilationRelaxationsAttribute": case "System.Reflection.AssemblyFileVersionAttribute": case "System.Reflection.AssemblyCompanyAttribute": case "System.Reflection.AssemblyCopyrightAttribute": case "System.Reflection.AssemblyProductAttribute": case "System.Reflection.AssemblyTrademarkAttribute": case "System.Reflection.AssemblyInformationalVersionAttribute": case "System.Reflection.AssemblyKeyFileAttribute": // Don't care about these for now case "System.ComponentModel.EditorAttribute": case "System.ComponentModel.DesignerAttribute": return; } foreach (var entry in referenceAttribute.Properties) { if (!actualAttribute.Properties.ContainsKey (entry.Key)) { // // Ignore missing value difference for default values // switch (referenceAttribute.Name) { case "System.AttributeUsageAttribute": // AllowMultiple defaults to false if (entry.Key == "AllowMultiple" && entry.Value == "False") continue; // Inherited defaults to true if (entry.Key == "Inherited" && entry.Value == "True") continue; break; case "System.ObsoleteAttribute": if (entry.Key == "IsError" && entry.Value == "False") continue; if (entry.Key == "Message") continue; break; } parent.AddError (String.Format ("Property `{0}' value is not set. Expected value: {1}", entry.Key, entry.Value)); parent.Status = ComparisonStatus.Error; continue; } var target_value = actualAttribute.Properties[entry.Key]; switch (referenceAttribute.Name) { case "System.Runtime.CompilerServices.TypeForwardedFromAttribute": if (entry.Key == "AssemblyFullName") target_value = target_value.Replace ("neutral", "Neutral"); break; case "System.Runtime.InteropServices.GuidAttribute": if (entry.Key == "Value") target_value = target_value.ToUpperInvariant (); break; case "System.ObsoleteAttribute": if (entry.Key == "Message") continue; break; } if (target_value != entry.Value) { parent.AddError (String.Format ("Expected value `{0}' for attribute property `{1}' but found `{2}'", entry.Value, entry.Key, target_value)); parent.Status = ComparisonStatus.Error; } } if (referenceAttribute.Properties.Count != actualAttribute.Properties.Count) { foreach (var entry in actualAttribute.Properties) { if (!referenceAttribute.Properties.ContainsKey (entry.Key)) { parent.AddError (String.Format ("Property `{0}' should not be set", entry.Key)); parent.Status = ComparisonStatus.Error; break; } } } return; }
void HandleError(ComparisonNode node, string message) { node.AddError (message); profile_documentation.AddError (message); }
static void AttachComments(TreeNode tn, ComparisonNode node) { if (node.Messages.Count != 0){ TreeNode m = new TreeNode (GetMessages (node)); m.SelectAction = TreeNodeSelectAction.None; tn.ChildNodes.AddAt (0, m); } if (node.Todos.Count != 0){ TreeNode m = new TreeNode (GetTodo (node)); m.SelectAction = TreeNodeSelectAction.None; tn.ChildNodes.AddAt (0, m); } }
void CompareBaseTypes (ComparisonNode parent, ICompHasBaseType reference_type, ICompHasBaseType target_type) { if (reference_type.GetBaseType() != target_type.GetBaseType()) { parent.AddError (String.Format ("reference has base class of {0}, target has base class of {1}", reference_type.GetBaseType(), target_type.GetBaseType())); } if (reference_type.IsAbstract != target_type.IsAbstract) { string ref_mod = (reference_type.IsAbstract && reference_type.IsSealed) ? "static" : "abstract"; string tar_mod = (target_type.IsAbstract && target_type.IsSealed) ? "static" : "abstract"; parent.AddError (String.Format ("reference is {0} {2}, target is {1} {3}", reference_type.IsAbstract ? null : "not", target_type.IsAbstract ? null : "not", ref_mod, tar_mod)); } else if (reference_type.IsSealed != target_type.IsSealed) { string ref_mod = (reference_type.IsAbstract && reference_type.IsSealed) ? "static" : "sealed"; string tar_mod = (target_type.IsAbstract && target_type.IsSealed) ? "static" : "sealed"; parent.AddError (String.Format ("reference is {0} {2}, target is {1} {3}", reference_type.IsSealed ? null : "not", target_type.IsSealed ? null : "not", ref_mod, tar_mod)); } }
// uses for class, struct, enum, interface static string GetFQN(ComparisonNode node) { if (node.Parent == null) return ""; string n = GetFQN (node.Parent); int p = node.Name.IndexOf (' '); string name = p == -1 ? node.Name : node.Name.Substring (p+1); p = name.IndexOf ('<'); if (p != -1) name = name.Substring (0, p); // remove generic parameters from URL return n == "" ? name : n + "." + name; }
void CompareTypeParameters (ComparisonNode parent, ICompGenericParameter reference, ICompGenericParameter target) { var r = reference.GetTypeParameters (); var t = target.GetTypeParameters (); if (r == null && t == null) return; if (r.Count != t.Count) { throw new NotImplementedException (string.Format ("Should never happen with valid data ({0} != {1})", r.Count, t.Count)); } for (int i = 0; i < r.Count; ++i) { var r_i = r [i]; var t_i = t [i]; if (r_i.GenericAttributes != t_i.GenericAttributes) { parent.AddError (string.Format ("reference type parameter {2} has {0} generic attributes, target type parameter {3} has {1} generic attributes", CompGenericParameter.GetGenericAttributeDesc (r_i.GenericAttributes), CompGenericParameter.GetGenericAttributeDesc (t_i.GenericAttributes), r_i.Name, t_i.Name)); } // TODO: Compare constraints properly if (r_i.HasConstraints != t_i.HasConstraints) { parent.AddError (string.Format ("Type parameter `{0}' constraints mismatch", r_i.Name)); } CompareAttributes (parent, r_i, t_i); } }
static string GetHtmlForNode(ComparisonNode n, bool is_container) { HtmlGenericControl ctrl = new HtmlGenericControl (); ctrl.Controls.Add (GetStatusImage (n, is_container)); ctrl.Controls.Add (GetTypeImage (n.Type)); bool completed = (n.Missing + n.Extra + n.Warning + n.Todo + n.Niex == 0); string status_class = null; if (completed && n.Status == ComparisonStatus.None) status_class = "full "; ctrl.Controls.Add (new Label () { Text = n.Name, CssClass = status_class + "cname" }); //if (is_container) { AddIconAndText (ctrl, "stmiss", n.Missing); AddIconAndText (ctrl, "stextra", n.Extra); AddIconAndText (ctrl, "sterror", n.Warning); AddIconAndText (ctrl, "sttodo", n.Todo); AddIconAndText (ctrl, "stniex", n.Niex); //} return GetHtmlFromControl (ctrl); }
void CompareAttributes (ComparisonNode parent, ICompAttributeContainer reference_container, ICompAttributeContainer target_container) { int m = 0, a = 0; List<CompNamed> reference_attrs = reference_container.GetAttributes (); List<CompNamed> target_attrs = target_container.GetAttributes (); reference_attrs.Sort (CompNamed.Compare); target_attrs.Sort (CompNamed.Compare); while (m < reference_attrs.Count || a < target_attrs.Count) { if (m == reference_attrs.Count) { AddExtra (parent, target_attrs[a]); a++; continue; } else if (a == target_attrs.Count) { AddMissing (parent, reference_attrs[m]); m++; continue; } int c = String.Compare (reference_attrs[m].Name, target_attrs[a].Name); comparisons_performed ++; if (c == 0) { /* the names match, further investigation is required */ // Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name); ComparisonNode comparison = target_attrs[a].GetComparisonNode(); parent.AddChild (comparison); //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]); m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing (parent, reference_attrs[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra (parent, target_attrs[a]); a++; } } }
static string GetMessages(ComparisonNode cn) { StringBuilder sb = new StringBuilder (); sb.Append ("<b>"); foreach (string s in cn.Messages){ sb.Append (s); sb.Append ("<br>"); } sb.Append ("</b>"); return sb.ToString (); }
void CompareMemberLists (ComparisonNode parent, List<CompNamed> reference_list, List<CompNamed> target_list) { int m = 0, a = 0; reference_list.Sort (CompNamed.Compare); target_list.Sort (CompNamed.Compare); while (m < reference_list.Count || a < target_list.Count) { if (m == reference_list.Count) { AddExtra (parent, target_list[a]); a++; continue; } else if (a == target_list.Count) { AddMissing (parent, reference_list[m]); m++; continue; } int c = CompNamed.Compare (reference_list[m], target_list[a]); comparisons_performed ++; if (c == 0) { /* the names match, further investigation is required */ // Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name); ComparisonNode comparison = target_list[a].GetComparisonNode(); parent.AddChild (comparison); if (reference_list[m] is CompMember && target_list[a] is CompMember) { string reference_type = ((CompMember)reference_list[m]).GetMemberType(); string target_type = ((CompMember)target_list[a]).GetMemberType(); if (reference_type != target_type) { comparison.AddError (String.Format ("reference type is <i>{0}</i>, target type is <i>{1}</i>", reference_type, target_type)); } string reference_access = ((CompMember)reference_list[m]).GetMemberAccess(); string target_access = ((CompMember)target_list[a]).GetMemberAccess(); if (reference_access != target_access) { // Try to give some hints to the developer, best we can do with // strings. string extra_msg = ""; if (reference_access.IndexOf ("Private, Final, Virtual, HideBySig") != -1 && target_access.IndexOf ("Public, HideBySig") != -1){ extra_msg = "\n\t\t<b>Hint:</b> reference uses an explicit interface implementation, target doesn't"; } comparison.AddError (String.Format ("reference access is '<i>{0}</i>', target access is '<i>{1}</i>'{2}", reference_access, target_access, extra_msg)); comparison.Status = ComparisonStatus.Error; } } var r_method = reference_list[m] as CompMethod; if (r_method != null) { var t_method = (CompMethod)target_list[a]; if (t_method.ThrowsNotImplementedException () && !r_method.ThrowsNotImplementedException ()) { comparison.ThrowsNIE = true; } CompareTypeParameters (comparison, r_method, t_method); CompareParameters (comparison, r_method, t_method); } if (reference_list[m] is CompField) { var v_ref = ((CompField)reference_list[m]).GetLiteralValue(); var v_tar = ((CompField)target_list[a]).GetLiteralValue(); if (v_ref != v_tar) { comparison.AddError (String.Format ("reference field has value {0}, target field has value {1}", v_ref, v_tar)); comparison.Status = ComparisonStatus.Error; } } if (reference_list[m] is ICompAttributeContainer) { //Console.WriteLine ("Comparing attributes for {0}", reference_list[m].Name); CompareAttributes (comparison, (ICompAttributeContainer)reference_list[m], (ICompAttributeContainer)target_list[a]); } if (reference_list[m] is ICompMemberContainer) { CompareMembers (comparison, (ICompMemberContainer)reference_list[m], (ICompMemberContainer)target_list[a]); } //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]); m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing (parent, reference_list[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra (parent, target_list[a]); a++; } } }
// used for methods static string GetMethodFQN(ComparisonNode node) { if (node.Parent == null) return ""; int p = node.Name.IndexOf ('('); int q = node.Name.IndexOf (' '); string name = p == -1 || q == -1 ? node.Name : node.Name.Substring (q+1, p-q-1); p = name.IndexOf ('<'); if (p != -1) name = name.Substring (0, p); // remove generic parameters from URL if (name == ".ctor") name = ""; string n = GetFQN (node.Parent); return n == "" ? name : n + (name == "" ? "" : "." + name); }
void AddMissing (ComparisonNode parent, CompNamed item) { ComparisonNode node = item.GetComparisonNode (); parent.AddChild (node); node.Status = ComparisonStatus.Missing; comparisons_performed ++; if (item is ICompHasBaseType) { string baseTypeName = ((ICompHasBaseType)item).GetBaseType(); if (!string.IsNullOrEmpty (baseTypeName)) { ComparisonNode baseTypeNode = new ComparisonNode (CompType.Class, string.Format ("BaseType: {0}", baseTypeName), baseTypeName); baseTypeNode.Status = ComparisonStatus.Missing; node.AddChild (baseTypeNode); } } if (item is ICompTypeContainer) { ICompTypeContainer c = (ICompTypeContainer)item; foreach (CompNamed ifc in c.GetNestedInterfaces ()) AddMissing (node, ifc); foreach (CompNamed cls in c.GetNestedClasses()) AddMissing (node, cls); foreach (CompNamed cls in c.GetNestedStructs()) AddMissing (node, cls); foreach (CompNamed en in c.GetNestedEnums()) AddMissing (node, en); } if (item is ICompMemberContainer) { ICompMemberContainer c = (ICompMemberContainer)item; foreach (CompNamed ifc in c.GetInterfaces()) AddMissing (node, ifc); foreach (CompNamed m in c.GetConstructors()) AddMissing (node, m); foreach (CompNamed m in c.GetMethods()) AddMissing (node, m); foreach (CompNamed p in c.GetProperties()) AddMissing (node, p); foreach (CompNamed f in c.GetFields()) AddMissing (node, f); foreach (CompNamed e in c.GetEvents()) AddMissing (node, e); } if (item is ICompAttributeContainer) { ICompAttributeContainer c = (ICompAttributeContainer)item; foreach (CompNamed attr in c.GetAttributes()) AddMissing (node, attr); } }
void CompareAttributes(ComparisonNode parent, ICompAttributeContainer reference_container, ICompAttributeContainer target_container) { int m = 0, a = 0; List <CompNamed> reference_attrs = reference_container.GetAttributes(); List <CompNamed> target_attrs = target_container.GetAttributes(); reference_attrs.Sort(CompNamed.Compare); target_attrs.Sort(CompNamed.Compare); while (m < reference_attrs.Count || a < target_attrs.Count) { if (m == reference_attrs.Count) { switch (target_attrs[a].Name) { case "System.Diagnostics.DebuggerDisplayAttribute": case "System.Runtime.CompilerServices.AsyncStateMachineAttribute": case "System.Runtime.CompilerServices.IteratorStateMachineAttribute": // Ignore extra attributes in Mono source code break; default: AddExtra(parent, target_attrs[a]); break; } a++; continue; } else if (a == target_attrs.Count) { AddMissing(parent, reference_attrs[m]); m++; continue; } int c = String.Compare(reference_attrs[m].Name, target_attrs[a].Name); comparisons_performed++; if (c == 0) { /* the names match, further investigation is required */ // Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name); ComparisonNode comparison = target_attrs[a].GetComparisonNode(); parent.AddChild(comparison); //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]); m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing(parent, reference_attrs[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra(parent, target_attrs[a]); a++; } } }