Author: tchemit Date: 2010-01-29 21:08:21 +0100 (Fri, 29 Jan 2010) New Revision: 810 Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java Log: - improve attribute generation - reformat code (80 caracters maximum for a line) Modified: trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java 2010-01-29 17:42:17 UTC (rev 809) +++ trunk/eugene/src/main/java/org/nuiton/eugene/java/JavaGenerator.java 2010-01-29 20:08:21 UTC (rev 810) @@ -69,7 +69,8 @@ } @Override - public String getFilenameForEnumeration(ObjectModelEnumeration enumeration) { + public String getFilenameForEnumeration(ObjectModelEnumeration enumeration) + { return getFilenameForClassifier(enumeration); } @@ -91,7 +92,8 @@ * @throws IOException if any pb while writing file */ @Override - public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + public void generateFromClass(Writer output, ObjectModelClass clazz) + throws IOException { if (log.isDebugEnabled()) { log.debug(clazz.getQualifiedName()); @@ -112,16 +114,19 @@ } String implement = ""; - for (Iterator<ObjectModelInterface> i = clazz.getInterfaces().iterator(); i.hasNext();) { + for (Iterator<ObjectModelInterface> i = + clazz.getInterfaces().iterator(); i.hasNext();) { ObjectModelClassifier parentInterface = i.next(); - String interfaceName = GeneratorUtil.getSimpleName(parentInterface.getQualifiedName()); + String interfaceName = GeneratorUtil.getSimpleName( + parentInterface.getQualifiedName()); implement += interfaceName; if (i.hasNext()) { implement += ", "; } } if (log.isDebugEnabled()) { - log.debug(className+" : super : "+extend+", interfaces : "+implement); + log.debug(className+" : super : "+extend+", interfaces : " + + implement); } generateAnnotations(output, clazz, clazz); @@ -155,7 +160,9 @@ } @Override - public void generateFromInterface(Writer output, ObjectModelInterface interfacez) throws IOException { + public void generateFromInterface(Writer output, + ObjectModelInterface interfacez) + throws IOException { if (log.isDebugEnabled()) { log.debug(interfacez.getQualifiedName()); } @@ -196,8 +203,12 @@ }*/ } - public void generateAnnotations(Writer output,ObjectModelClassifier clazz, ObjectModelElement element) throws IOException { - AnnotationsManagerExtension managers = getModel().getExtension(AnnotationsManagerExtension.OBJECTMODEL_EXTENSION, + public void generateAnnotations(Writer output, + ObjectModelClassifier clazz, + ObjectModelElement element) + throws IOException { + AnnotationsManagerExtension managers = getModel().getExtension( + AnnotationsManagerExtension.OBJECTMODEL_EXTENSION, AnnotationsManagerExtension.class); String[] annotations = managers.getAnnotations(clazz,element); for (String annotation : annotations) { @@ -218,7 +229,8 @@ } @Override - public void generateFromEnum(Writer output, ObjectModelEnumeration enumz) throws IOException { + public void generateFromEnum(Writer output, ObjectModelEnumeration enumz) + throws IOException { if (log.isDebugEnabled()) { log.debug(enumz.getQualifiedName()); } @@ -265,7 +277,10 @@ }*/ } - public void generateInnerClassifiers(Writer output, Collection<ObjectModelClassifier> innerClassifiers) throws IOException { + public void generateInnerClassifiers(Writer output, + Collection<ObjectModelClassifier> + innerClassifiers) + throws IOException { if (innerClassifiers == null || innerClassifiers.isEmpty()) { return; } @@ -276,12 +291,14 @@ continue; } if (innerClassifier.isInterface()) { - generateFromInterface(output, (ObjectModelInterface) innerClassifier); + generateFromInterface(output, (ObjectModelInterface) + innerClassifier); innerLevel--; continue; } if (innerClassifier.isEnum()) { - generateFromEnum(output, (ObjectModelEnumeration) innerClassifier); + generateFromEnum(output, (ObjectModelEnumeration) + innerClassifier); innerLevel--; continue; } @@ -299,7 +316,8 @@ prefix = new String(tmp); } if (log.isDebugEnabled()) { - log.debug("prefix to use for classifier " + clazz.getName() + " : [" + prefix + "]"); + log.debug("prefix to use for classifier " + + clazz.getName() + " : [" + prefix + "]"); } } @@ -311,7 +329,9 @@ * @param classifier Classifier for generate header * @throws IOException if any pb while writing file */ - protected void generateHeader(Writer output, ObjectModelClassifier classifier) throws IOException { + protected void generateHeader(Writer output, + ObjectModelClassifier classifier) + throws IOException { if (classifier.isInner()) { return; } @@ -320,7 +340,8 @@ }*/ // potentiel crash si imports non defini -> IllegalArgumentException on "imports" - ImportsManagerExtension managers = getModel().getExtension(ImportsManagerExtension.OBJECTMODEL_EXTENSION, + ImportsManagerExtension managers = getModel().getExtension( + ImportsManagerExtension.OBJECTMODEL_EXTENSION, ImportsManagerExtension.class); for (String imports : managers.getImports(classifier)) { @@ -338,11 +359,17 @@ * @param attributes Collection of ObjectModelAttribute to generate * @throws IOException if any pb while writing file */ - protected void generateAttributes(Writer output,ObjectModelClassifier clazz, Collection<ObjectModelAttribute> attributes) throws IOException { - + protected void generateAttributes(Writer output,ObjectModelClassifier clazz, + Collection<ObjectModelAttribute> + attributes) + throws IOException { + if (!attributes.isEmpty()) { +/*{}*/ + } for (ObjectModelAttribute attr : attributes) { - if (attr.getDocumentation() != null && !attr.getDocumentation().isEmpty()) { + if (attr.getDocumentation() != null && + !attr.getDocumentation().isEmpty()) { /*{<%=prefix%> /** <%=prefix%> * <%=attr.getDocumentation()%> <%=prefix%> *) @@ -360,7 +387,8 @@ String attrType = GeneratorUtil.getSimpleName(attr.getType()); String attrStatic = attr.isStatic() ? " static" : ""; String attrFinal = attr.isFinal() ? " final" : ""; - String attrValue = attr.getDefaultValue() != null && !attr.getDefaultValue().isEmpty() ? + String attrValue = attr.getDefaultValue() != null && + !attr.getDefaultValue().isEmpty() ? " = " + GeneratorUtil.getSimpleName(attr.getDefaultValue()) : ""; /*{<%=prefix%> <%=attrVisibility%><%=attrStatic%><%=attrFinal%> <%=attrType%> <%=attrName%><%=attrValue%>; @@ -376,7 +404,9 @@ * @param operations Collection of ObjectModelOperation to generate * @throws IOException if any pb while writing file */ - protected void generateOperations(Writer output,ObjectModelClassifier clazz, Collection<ObjectModelOperation> operations) throws IOException { + protected void generateOperations(Writer output,ObjectModelClassifier clazz, + Collection<ObjectModelOperation> + operations) throws IOException { for (ObjectModelOperation op : operations) { String opName = op.getName(); if (opName == null) { @@ -386,7 +416,8 @@ /*{<%=prefix%> /** <%=prefix%> * <%=opName%> : <%=prefix%>}*/ - if (op.getDocumentation() != null && !op.getDocumentation().isEmpty()) { + if (op.getDocumentation() != null && + !op.getDocumentation().isEmpty()) { String opDocumentation = op.getDocumentation(); /*{<%=prefix%> * <%=opDocumentation%> }*/ @@ -408,7 +439,8 @@ ObjectModelParameter returnParam = op.getReturnParameter(); String opReturn = ""; if (returnParam != null) { - opReturn = GeneratorUtil.getSimpleName(returnParam.getType()) + " "; + opReturn = GeneratorUtil.getSimpleName( + returnParam.getType()) + " "; if (!opReturn.contains("void")) { String paramDocumentation = returnParam.getDocumentation(); if (paramDocumentation == null) { @@ -458,7 +490,8 @@ } } - protected void generateBlock(Writer output,ObjectModelClassifier clazz, ObjectModelOperation op) throws IOException { + protected void generateBlock(Writer output,ObjectModelClassifier clazz, + ObjectModelOperation op) throws IOException { String opStatic = op.isStatic() ? "static " : " "; /*{<%=prefix%><%=opStatic%>{