public void displayClass() { System.out.println("############################################"); System.out.println("(" + this.getClassName() + ")"); if (this.getExtendsFrom() != null && this.getExtendsFrom().size() != 0) { System.out.println("__________________"); System.out.print("extends from "); for (String string : this.getExtendsFrom()) { System.out.println(string); } } if (this.getClassAttributes() != null && this.getClassAttributes().size() != 0) { System.out.println("________Attributes________"); for (ClassAttribute attribute : this.getClassAttributes()) { System.out.println( attribute.getAccessModifier() + attribute.getAttributeName() + ":" + attribute.getAttributeType()); } } if (this.getClassMethods() != null && this.getClassMethods().size() != 0) { System.out.println("_________Methods_________"); String parameterStr = ""; for (ClassMethod classMethod : this.getClassMethods()) { ArrayList<MethodParameter> parameters = classMethod.getRealParameters(); if (parameters != null && parameters.size() != 0) { for (MethodParameter parameter : parameters) { parameterStr += parameter.getParameterName() + ":" + parameter.getParameterType() + ", "; } parameterStr = parameterStr.substring(0, parameterStr.length() - 1 - 1); } System.out.println( classMethod.getMethodModifier() + classMethod.getMethodName() + " : " + classMethod.getMethodReturnType() + " (" + parameterStr + ")"); } } if (this.getClassRelations() != null && this.getClassRelations().size() != 0) { System.out.println( "_________Relations__________" + this.getRelationList().getRelations().size()); for (ClassRelation relation : this.getRelationList().getRelations()) { System.out.println(className + relation.getRelationship() + relation.getTargetClass()); } } }
public void convertUMLClassDetail() { setUMLClassDetail("["); if (UMLClassName == "") { return; } if (isInterface) { setUMLClassDetail(getUMLClassDetail() + "%C2%ABInterface%C2%BB;"); } setUMLClassDetail(getUMLClassDetail() + this.className); // add attributes if (this.classAttributes != null && this.classAttributes.size() != 0) { setUMLClassDetail(getUMLClassDetail() + "|"); for (ClassAttribute classAttribute : classAttributes) { String attributeStr = ""; attributeStr = classAttribute.getAccessModifier() + classAttribute.getAttributeName() + ":" + classAttribute.getAttributeType() + ";"; setUMLClassDetail(getUMLClassDetail() + attributeStr); } } // add methods if (this.classMethods != null && this.classMethods.size() != 0) { setUMLClassDetail(getUMLClassDetail() + "|"); for (ClassMethod method : classMethods) { String methodStr = ""; String methodAttriStr = ""; if (method.getRealParameters() != null && method.getRealParameters().size() != 0) { for (MethodParameter methodParameter : method.getRealParameters()) { String methodPara = methodParameter.getParameterType(); // If parameter's type is array, it will be changed into (*) if (methodPara.toString().contains("[]")) { methodAttriStr += methodParameter.getParameterName() + ":" + methodPara.substring(0, methodPara.indexOf('[')) + "(*)"; } else { methodAttriStr += methodParameter.getParameterName() + ":" + methodParameter.getParameterType(); } } methodStr = method.getMethodModifier() + method.getMethodName() + "(" + methodAttriStr + ")" + ":" + method.getMethodReturnType() + ";"; setUMLClassDetail(getUMLClassDetail() + methodStr); } else { methodStr = method.getMethodModifier() + method.getMethodName() + "(" + methodAttriStr + ")" + ":" + method.getMethodReturnType() + ";"; setUMLClassDetail(getUMLClassDetail() + methodStr); } } } setUMLClassDetail(getUMLClassDetail() + "],"); }
/** * Looking for dependencies in attributes * * @param allClasses */ public void alterAttributeList(ArrayList<RealClass> allClasses) { if (this.classAttributes == null || this.classAttributes.size() == 0) { return; } ClassRelation relation = null; ClassAttribute classAttribute = null; ArrayList<Integer> removeMethodIndex = new ArrayList<Integer>(); ArrayList<Integer> removeAttributeIndex = new ArrayList<Integer>(); for (int i = 0; i < classAttributes.size(); i++) { classAttribute = classAttributes.get(i); String type = classAttribute.getAttributeType(); // Do nothing when type is primitive type or String type // Add relation into classRelations and delete this attribute when type contains Collection<> Pattern pattern = Pattern.compile("Collection<.*>", Pattern.CASE_INSENSITIVE); Matcher m = pattern.matcher(type); if (m.matches()) { int beginIndex = type.indexOf('<'); // Get the type out of string int endIndex = type.indexOf('>'); String tempType = type.substring(beginIndex + 1, endIndex); // under the requirement, no need for checking if type is in the class list relation = new ClassRelation(this.getClassName(), tempType, RelatinType.OneToMany); this.classRelations.add(relation); // Delete the attribute removeAttributeIndex.add(i); relation = null; } // Arrays: [] --> (*) else if (type.contains("[]")) { int openIndex = type.indexOf('['); type = type.substring(0, openIndex); type += "(*)"; classAttribute.setAttributeType(type); } // Other situation(simple declaration) else if (classList.contains(type)) { relation = new ClassRelation(this.getClassName(), type, RelatinType.OneToOne); this.classRelations.add(relation); // Attributes can not be deleted during the loop removeAttributeIndex.add(i); relation = null; } // If Getter and Setter of a attribute are found // This attribute should become public // Getter and Setter should be deleted else if (classAttribute.getAccessModifier() == "-") { String getter = "get" + classAttribute.getAttributeName(); String setter = "set" + classAttribute.getAttributeName(); // Find the indexes of getter and setter in method list int getterIndex = -1; int setterIndex = -1; for (int index = 0; index < this.classMethods.size(); index++) { if (this.classMethods.get(index).getMethodName().toLowerCase().contentEquals(getter)) { getterIndex = index; } else if (this.classMethods .get(index) .getMethodName() .toLowerCase() .contentEquals(setter)) { setterIndex = index; } } // Can not delete method within this loop // Mark the indexes, delete them after loop is end if (getterIndex != -1 && setterIndex != -1) { removeMethodIndex.add(getterIndex); removeMethodIndex.add(setterIndex); classAttribute.setAccessModifier("+"); } } // If it's protected, remove it else if (classAttribute.getAccessModifier() == "#") { removeAttributeIndex.add(i); } } // Delete those attributes for (int j = removeAttributeIndex.size() - 1; j >= 0; j--) { classAttributes.remove((int) removeAttributeIndex.get(j)); } // Delete the getter and setter for (int j = removeMethodIndex.size() - 1; j >= 0; j--) { classMethods.remove((int) removeMethodIndex.get(j)); } }