/// <summary> /// Writes elements belonging to the class declaration that may or may not be neccessary (e.g. parent classes or interfaces). /// </summary> /// <param name="sb"> Currently used StringBuilder. </param> private void writeBeginning_appendElements(StringBuilder sb, UML_Class umlClass) { // Determine presence of parent / implemented interfaces bool parentPresent = umlClass.parent != null; bool implementedInterfacesPresent = umlClass.implementedInterfaces.Count > 0; bool aditionalElementsPresent = parentPresent || implementedInterfacesPresent; // Append colon if (aditionalElementsPresent) { sb.Append(" : "); } // Append parents if (parentPresent) { sb.Append(umlClass.parent.name); if (implementedInterfacesPresent) { sb.Append(", "); } } // Append interfaces if (implementedInterfacesPresent) { foreach (UML_Interface implementedInterface in umlClass.implementedInterfaces) { sb.Append($"{implementedInterface.name}, "); } // Delete last comma sb.Length -= 2; } }
public void CanGetMultipleValueOfAnalyzeNode() { // Arrange string workingDirectory = Environment.CurrentDirectory; string filepath = Directory.GetParent(workingDirectory).Parent.FullName + "/Ressources/classdiagram.graphml"; List <UML_Base> classes = new List <UML_Base>(); UML_Class expectedClass = new UML_Class("Employee", "n0"); UML_Class expectedClass2 = new UML_Class("User", "n1"); classes.Add(expectedClass); classes.Add(expectedClass2); // Act Reader.Reader instanceForDatamodel = new Reader.Reader(filepath); List <UML_Base> listOfClasses = instanceForDatamodel.AnalyzeNode(); // Assert Assert.Equal(classes, listOfClasses); }
public void checkClass() { // Arrange string workingDirectory = Environment.CurrentDirectory; string filepath = Directory.GetParent(workingDirectory).Parent.FullName + "/Ressources/classdiagram.graphml"; UML_Class expectedClass = new UML_Class("Employee", "n0"); // Act Reader.Reader instanceForDatamodel = new Reader.Reader(filepath); List <UML_Base> baseModel = instanceForDatamodel.AnalyzeNode(); // Assert foreach (var @class in baseModel) { Assert.Equal(@class.GetType(), expectedClass.GetType()); } }
/// <summary> /// Providing the correct relationship between inherited objects /// </summary> /// <param name="baseModelList"> Containing all parsed Classes and Interfaces</param> /// <param name="source"> Soruce Id from graphml file </param> /// <param name="target"> Target Id from graphml file </param> void getInheritance(List <UML_Base> baseModelList, string source, string target) { var sourceId = source; var targetId = target; if (baseModelList.Find(x => x.id == targetId).GetType() == typeof(UML_Interface)) { UML_Class classParent = (UML_Class)baseModelList.Find(y => y.id == sourceId); UML_Interface implementedInterface = (UML_Interface)baseModelList.Find(y => y.id == targetId); List <UML_Interface> implementedInterfaceList = new List <UML_Interface>(); implementedInterfaceList.Add(implementedInterface); classParent.implementedInterfaces = implementedInterfaceList; } if (baseModelList.Find(x => x.id == targetId).GetType() == typeof(UML_Class)) { UML_Class classParent = (UML_Class)baseModelList.Find(y => y.id == sourceId); UML_Class implementedClass = (UML_Class)baseModelList.Find(y => y.id == targetId); classParent.parent = implementedClass; } }
public void CanGetValueOfAnalyzeNode() { // Arrange string workingDirectory = Environment.CurrentDirectory; string filepath = Directory.GetParent(workingDirectory).Parent.FullName + "/Ressources/classdiagram.graphml"; List <UML_Base> expectedClassList = new List <UML_Base>(); UML_Class expectedClass = new UML_Class("Employee", "n0"); expectedClassList.Add(expectedClass); // Act XmlReader reader = new XmlTextReader(filepath); Reader.Reader instanceForDatamodel = new Reader.Reader(filepath); List <UML_Base> baseModelList = instanceForDatamodel.AnalyzeNode(); // Assert Assert.Equal <UML_Base>(expectedClassList, baseModelList); }
/// <summary> /// Main Method for determine each existing Element if they are a Class or a Interface /// </summary> /// <typeparam name="T"> Generic - Either UML_Class Object or UML_Interface Object </typeparam> /// <param name="nodeId"> Containing information about the associated id values from yEd </param> /// <param name="name"> Containing Information about the names of the Class or Interface </param> /// <param name="fontStyle"> Containing Information about the font style </param> /// <param name="attributes"> Containing information about existing attributes of each object</param> /// <param name="methods"> Containign information about existing methods of each object </param> /// <returns> UML_Class object or UML_Interface object </returns> public T AnalyzeNodeLabel <T>(string nodeId, string name, string fontStyle, string attributes, string methods) where T : CodeGenerator.Datamodel.UML_Base { string modifierPublic = "public"; string modifierPrivate = "private"; string modifierProtected = "protected"; string abstractKey = "abstract"; if (checkModelInterface(name)) { string interfaceName = name.Replace("<<interface>>", "").Replace("\n", ""); if (name.StartsWith("+")) { UML_Interface interfaceModel = new UML_Interface(interfaceName, nodeId); interfaceModel.accessModifier = modifierPublic; interfaceModel.umlAttributes = AnalyzeAttributeLabel(attributes); return((T)Convert.ChangeType(interfaceModel, typeof(UML_Interface))); } if (name.StartsWith("-")) { UML_Interface interfaceModel = new UML_Interface(interfaceName, nodeId); interfaceModel.accessModifier = modifierPrivate; interfaceModel.umlAttributes = AnalyzeAttributeLabel(attributes); return((T)Convert.ChangeType(interfaceModel, typeof(UML_Interface))); } if (name.StartsWith("#")) { UML_Interface interfaceModel = new UML_Interface(interfaceName, nodeId); interfaceModel.accessModifier = modifierProtected; interfaceModel.umlAttributes = AnalyzeAttributeLabel(attributes); return((T)Convert.ChangeType(interfaceModel, typeof(UML_Interface))); } else { UML_Interface interfaceModel = new UML_Interface(interfaceName, nodeId); interfaceModel.umlAttributes = AnalyzeAttributeLabel(attributes); interfaceModel.umlMethods = AnalyzeMethodLabel(methods); return((T)Convert.ChangeType(interfaceModel, typeof(UML_Interface))); } } if (checkModelClass(name)) { if (name.StartsWith("+")) { UML_Class classModel = new UML_Class(name, nodeId); if (checkAbstractClass(fontStyle)) { classModel.extraKeyword = abstractKey; } classModel.accessModifier = modifierPublic; classModel.umlAttributes = AnalyzeAttributeLabel(attributes); return((T)Convert.ChangeType(classModel, typeof(UML_Class))); } if (name.StartsWith("-")) { UML_Class classModel = new UML_Class(name, nodeId); if (checkAbstractClass(fontStyle)) { classModel.extraKeyword = abstractKey; } classModel.accessModifier = modifierPrivate; classModel.umlAttributes = AnalyzeAttributeLabel(attributes); return((T)Convert.ChangeType(classModel, typeof(UML_Class))); } if (name.StartsWith("#")) { UML_Class classModel = new UML_Class(name, nodeId); if (checkAbstractClass(fontStyle)) { classModel.extraKeyword = abstractKey; } classModel.accessModifier = modifierProtected; classModel.umlAttributes = AnalyzeAttributeLabel(attributes); return((T)Convert.ChangeType(classModel, typeof(UML_Class))); } else { UML_Class classModel = new UML_Class(name, nodeId); if (checkAbstractClass(fontStyle)) { classModel.extraKeyword = abstractKey; } classModel.umlAttributes = AnalyzeAttributeLabel(attributes); classModel.umlMethods = AnalyzeMethodLabel(methods); return((T)Convert.ChangeType(classModel, typeof(UML_Class))); } } return(null); }