/// <summary> /// Prints the members of the supplied <see cref="NRSingleInheritanceType"/>. /// </summary> /// <param name="nrSingleInheritanceType">The members of this <see cref="NRSingleInheritanceType"/> are printed.</param> private void PrintMembers(NRSingleInheritanceType nrSingleInheritanceType) { PrintMembers((NRCompositeType)nrSingleInheritanceType); OutputLine("BaseType: "); indent++; nrSingleInheritanceType.BaseType.Accept(this); indent--; nrSingleInheritanceType.Constructors.ForEach(nrConstructor => nrConstructor.Accept(this)); nrSingleInheritanceType.Fields.ForEach(nrField => nrField.Accept(this)); nrSingleInheritanceType.Operators.ForEach(nrOperator => nrOperator.Accept(this)); }
/// <summary> /// Prints the base type and all implemented interfaces of the given <see cref="NRSingleInheritanceType"/>. /// </summary> /// <param name="nrSingleInheritanceType">An <see cref="NRSingleInheritanceType"/> to take the base type and interfaces from.</param> private void PrintBaseTypeAndInterfaces(NRSingleInheritanceType nrSingleInheritanceType) { if (nrSingleInheritanceType.BaseType == null && nrSingleInheritanceType.ImplementedInterfaces.Count == 0) { return; } Output(" : "); if (nrSingleInheritanceType.BaseType != null) { Output(ToString(nrSingleInheritanceType.BaseType)); } foreach (NRTypeUsage implementedInterface in nrSingleInheritanceType.ImplementedInterfaces) { Output(", " + implementedInterface.Name); } }
/// <summary> /// Gets the base type and all implemented interfaces of the given <see cref="NRSingleInheritanceType" />. /// </summary> /// <param name="nrSingleInheritanceType"> /// An <see cref="NRSingleInheritanceType" /> to take the base type and interfaces /// from. /// </param> private static string GetBaseTypeAndInterfaces(NRSingleInheritanceType nrSingleInheritanceType) { if ((nrSingleInheritanceType.BaseType == null) && (nrSingleInheritanceType.ImplementedInterfaces.Count == 0)) { return(""); } StringBuilder result = new StringBuilder(" : "); if (nrSingleInheritanceType.BaseType != null) { result.Append(nrSingleInheritanceType.BaseType.Declaration( ) + ", "); } foreach (NRTypeUsage implementedInterface in nrSingleInheritanceType.ImplementedInterfaces) { result.Append(implementedInterface.Declaration( ) + ", "); } result.Length -= 2; return(result.ToString( )); }
/// <summary> /// Initializes a new instance of <see cref="NRRealization" />. /// </summary> /// <param name="baseType">The base type of the generalization.</param> /// <param name="implementingType">The implementing type of the realization.</param> public NRRealization(NRInterface baseType, NRSingleInheritanceType implementingType) { BaseType = baseType; ImplementingType = implementingType; }
/// <summary> /// Initializes a new instance of <see cref="NRNesting" />. /// </summary> /// <param name="parentType">The parent type of the nesting relationship.</param> /// <param name="innerType">The inner type of the nesting relationship.</param> public NRNesting(NRSingleInheritanceType parentType, NRTypeBase innerType) { ParentType = parentType; InnerType = innerType; }
// ======================================================================== // Methods #region === Methods /// <summary> /// Extracts the relationships between the types of <paramref name="nrAssembly"/>. /// </summary> /// <param name="nrAssembly">The relationships are extracted from the types within /// this <see cref="NRAssembly"/>.</param> /// <param name="createNesting">Set to <c>true</c> to create nesting relationships.</param> /// <param name="createGeneralization">Set to <c>true</c> to create generalization relationships.</param> /// <param name="createRealization">Set to <c>true</c> to create realization relationships.</param> /// <param name="createAssociation">Set to <c>true</c> to create association relationships.</param> /// <returns>The extracted relationships.</returns> public NRRelationships CreateRelationships(NRAssembly nrAssembly, bool createNesting = true, bool createGeneralization = true, bool createRealization = true, bool createAssociation = true) { NRRelationships nrRelationships = new NRRelationships(); Dictionary <string, NRTypeBase> entities = nrAssembly.Types.ToDictionary(nrTypeBase => nrTypeBase.FullName); //Create the nesting relationships if (createNesting) { foreach (NRTypeBase nrTypeBase in entities.Values) { if (!String.IsNullOrWhiteSpace(nrTypeBase.DeclaringTypeFullName)) { if (entities.ContainsKey(nrTypeBase.DeclaringTypeFullName)) { NRSingleInheritanceType parent = entities[nrTypeBase.DeclaringTypeFullName] as NRSingleInheritanceType; if (parent != null) { nrRelationships.Nestings.Add(new NRNesting(parent, nrTypeBase)); } } } } } //Create the generalization relationships if (createGeneralization) { foreach (NRSingleInheritanceType derivedType in nrAssembly.SingleInheritanceTypes) { if (derivedType.BaseType != null && derivedType.BaseType.FullName != null) { if (entities.ContainsKey(derivedType.BaseType.FullName)) { NRSingleInheritanceType baseType = entities[derivedType.BaseType.FullName] as NRSingleInheritanceType; if (baseType != null) { nrRelationships.Generalizations.Add(new NRGeneralization(baseType, derivedType)); } } } } // Interfaces may derive from other interfaces as well. foreach (NRInterface derivedInterface in nrAssembly.Interfaces) { foreach (NRTypeUsage implementedInterface in derivedInterface.ImplementedInterfaces) { if (entities.ContainsKey(implementedInterface.FullName)) { NRInterface nrInterface = entities[implementedInterface.FullName] as NRInterface; if (nrInterface != null) { nrRelationships.Generalizations.Add(new NRGeneralization(nrInterface, derivedInterface)); } } } } } //Create the realization relationships if (createRealization) { foreach (NRSingleInheritanceType implementingType in nrAssembly.SingleInheritanceTypes) { foreach (NRTypeUsage implementedInterface in implementingType.ImplementedInterfaces) { if (entities.ContainsKey(implementedInterface.FullName)) { NRInterface nrInterface = entities[implementedInterface.FullName] as NRInterface; if (nrInterface != null) { nrRelationships.Realizations.Add(new NRRealization(nrInterface, implementingType)); } } } } } //Create the association relationships if (createAssociation) { foreach (NRSingleInheritanceType startType in nrAssembly.SingleInheritanceTypes) { foreach (NRField nrField in startType.Fields) { string fullName = nrField.TypeFullName; bool array = false; if (fullName.EndsWith("[]")) { //Array! fullName = fullName.Substring(0, fullName.IndexOf('[')); array = true; } if (fullName.Contains("[")) { //Generic! fullName = fullName.Substring(0, fullName.IndexOf('[')); } if (entities.ContainsKey(fullName)) { NRTypeBase endType = entities[fullName]; NRAssociation association = new NRAssociation { StartType = startType, EndMultiplicity = array ? "*" : "1", StartRole = nrField.Name, EndType = endType }; nrRelationships.Associations.Add(association); } } } } return(nrRelationships); }