/// <summary> /// Fills in the attribute definition. /// </summary> /// <param name="umlAttribute"> Object containing information about the attribute. </param> /// <returns> Returns the string representing the UML_Attribute object. </returns> public override string writeAttribute_Specify(UML_Attribute umlAttribute) { StringBuilder sb = new StringBuilder(); // Overall attribute structure: Check access modifier if (umlAttribute.accessModifier != null) { sb.Append($"{umlAttribute.accessModifier} "); } // Overall attribute strucutre: extra keyword if (!umlAttribute.extraKeyword.Equals("")) { sb.Append($"{umlAttribute.extraKeyword} "); } // Overall attribute structure: rest sb.Append($"{umlAttribute.type} {umlAttribute.name}"); // Append respective information if (umlAttribute.autoGetterSetterSpecified) { sb.Append(" { get; set; }"); } else { sb.Append(";"); } // Return built string return(sb.ToString()); }
public void CanGetValueOfAnalyzeAttributeLabel() { // Arrange string workingDirectory = Environment.CurrentDirectory; string filepath = Directory.GetParent(workingDirectory).Parent.FullName + "/Ressources/classdiagram2.graphml"; XDocument doc = XDocument.Load(filepath); XNamespace yns = "http://www.yworks.com/xml/graphml"; List <string> attributeStringList = new List <string>(); foreach (var attributeLabel in doc.Descendants(yns + "AttributeLabel")) { attributeStringList.Add(attributeLabel.Value); } List <UML_Attribute> expectedAttributes = new List <UML_Attribute>(); UML_Attribute attribute1 = new UML_Attribute() { accessModifier = "public", name = "name", type = "string" }; UML_Attribute attribute2 = new UML_Attribute() { accessModifier = "public", name = "age", type = "int" }; expectedAttributes.Add(attribute1); expectedAttributes.Add(attribute2); // Act Reader.BaseReader instanceForAttributes = new Reader.BaseReader(filepath); List <UML_Attribute> classAttributes = new List <UML_Attribute>(); List <UML_Attribute> attributeList = new List <UML_Attribute>(); foreach (UML_Attribute item in classAttributes) { attributeList.Add(item); } // Assert Assert.Equal(expectedAttributes, attributeList); }
/// <summary> /// Fills in the attribute definition. /// </summary> /// <param name="umlAttribute"> Object containing information about the attribute. </param> /// <returns> Returns the string representing the UML_Attribute object. </returns> public override string writeAttribute_Specify(UML_Attribute umlAttribute) { // Overall attribute structure StringBuilder sb = new StringBuilder($"{umlAttribute.type} {umlAttribute.name}"); // Append respective information if (umlAttribute.autoGetterSetterSpecified) { sb.Append(" { get; set; }"); } else { sb.Append(";"); } // Return built string return(sb.ToString()); }
/// <summary> /// Method for handling the data about each existing attribute and storing these as a datamodel valid form into a List of objects /// </summary> /// <param name="attr"> Value containing parsed data of AttributeLabel </param> /// <returns></returns> public List <UML_Attribute> getAttribute(string attr) { // Possible accessmodifiers string modifierPublic = "public"; string modifierPrivate = "private"; string modifierProtected = "protected"; List <UML_Attribute> listAttributes = new List <UML_Attribute>(); List <string> readerValueArray = new List <string>(); // Splitting the string input at whitespaces readerValueArray = System.Text.RegularExpressions.Regex.Split(attr, "\\n").ToList <string>(); // Looping through all splitted string-elements foreach (string stringValue in readerValueArray) { if (checkListValue(stringValue)) { UML_Attribute attribute = new UML_Attribute(); // Separating name and type var kvp = stringValue.Split(':'); string staticKey = "static"; // Cutting of whitespaces string current = kvp[1].Trim(' ', '*'); // Checking for valid data // Checking current accessmodifier if (stringValue.StartsWith("+") == true && kvp[1] != null) { attribute.accessModifier = modifierPublic; attribute.name = kvp[0].Trim('+', ' ', '*'); attribute.type = current; if (checkStatic(stringValue)) { attribute.extraKeyword = staticKey; } attribute.autoGetterSetterSpecified = checkGetterSetter(stringValue); } if (stringValue.StartsWith("-") == true && kvp[1] != null) { attribute.accessModifier = modifierPrivate; attribute.name = kvp[0].Trim('-', ' ', '*'); attribute.type = current; if (checkStatic(stringValue)) { attribute.extraKeyword = staticKey; } attribute.autoGetterSetterSpecified = checkGetterSetter(stringValue); } if (stringValue.StartsWith("#") == true && kvp[1] != null) { attribute.accessModifier = modifierProtected; attribute.name = kvp[0].Trim('#', ' ', '*'); attribute.type = current; if (checkStatic(stringValue)) { attribute.extraKeyword = staticKey; } attribute.autoGetterSetterSpecified = checkGetterSetter(stringValue); } if (stringValue.StartsWith("+") == false && stringValue.StartsWith("-") == false && stringValue.StartsWith("#") == false && kvp[1] != null) { attribute.accessModifier = null; attribute.name = kvp[0].Trim(' ', '*'); attribute.type = current; if (checkStatic(stringValue)) { attribute.extraKeyword = staticKey; } attribute.autoGetterSetterSpecified = checkGetterSetter(stringValue); } // List of all existing attributes as objects listAttributes.Add(attribute); } } return(listAttributes); }
public virtual string writeAttribute_Specify(UML_Attribute umlAttribute) { return(""); }