r607 - in trunk/eugene/src/main/java/org/nuiton/eugene: . models/object/xml
Author: tchemit Date: 2009-08-22 17:03:00 +0200 (Sat, 22 Aug 2009) New Revision: 607 Modified: trunk/eugene/src/main/java/org/nuiton/eugene/ChildGenerator.java trunk/eugene/src/main/java/org/nuiton/eugene/Generator.java trunk/eugene/src/main/java/org/nuiton/eugene/ImportsManager.java trunk/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassImpl.java Log: improve code : javadoc, override annotation, format,... Modified: trunk/eugene/src/main/java/org/nuiton/eugene/ChildGenerator.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/ChildGenerator.java 2009-08-21 13:23:16 UTC (rev 606) +++ trunk/eugene/src/main/java/org/nuiton/eugene/ChildGenerator.java 2009-08-22 15:03:00 UTC (rev 607) @@ -53,13 +53,13 @@ @Override public boolean getOverwrite() { - boolean overwrite; + boolean result; if (parent == null) { - overwrite = super.getOverwrite(); + result = super.getOverwrite(); } else { - overwrite = parent.getOverwrite(); + result = parent.getOverwrite(); } - return overwrite; + return result; } @Override Modified: trunk/eugene/src/main/java/org/nuiton/eugene/Generator.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-08-21 13:23:16 UTC (rev 606) +++ trunk/eugene/src/main/java/org/nuiton/eugene/Generator.java 2009-08-22 15:03:00 UTC (rev 607) @@ -28,8 +28,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.eugene.models.object.ObjectModelClassifier; -import org.nuiton.eugene.models.object.ObjectModelElement; /** * Generator. Modified: trunk/eugene/src/main/java/org/nuiton/eugene/ImportsManager.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/ImportsManager.java 2009-08-21 13:23:16 UTC (rev 606) +++ trunk/eugene/src/main/java/org/nuiton/eugene/ImportsManager.java 2009-08-22 15:03:00 UTC (rev 607) @@ -17,11 +17,12 @@ */ public class ImportsManager { - private static Set<String> primitiveTypes; - static { - primitiveTypes = new HashSet<String>(); + private static Set<String> primitiveTypes; - primitiveTypes.add("byte"); + static { + primitiveTypes = new HashSet<String>(); + + primitiveTypes.add("byte"); primitiveTypes.add("Byte"); primitiveTypes.add("short"); primitiveTypes.add("Short"); @@ -43,115 +44,114 @@ primitiveTypes.add("void"); - } + } + private Map<String, String> imports = new HashMap<String, String>(); + private State state = State.FILLING; - private Map<String, String> imports = new HashMap<String, String>(); - private State state = State.FILLING; + /** + * From the given class, add it to the imports list. + * @param clazz the class to import + * @return true if import add was successful + * @see ImportsManager#addImport(String) + */ + public boolean addImport(Class<?> clazz) { + return addImport(clazz.getName()); + } - /** - * From the given class, add it to the imports list. - * @param clazz the class to import - * @return true if import add was successful - * @see ImportsManager#addImport(String) - */ - public boolean addImport(Class<?> clazz) { - return addImport(clazz.getName()); - } - - /** - * From the given fqn (fully qualified name), add it to the imports list. + /** + * From the given fqn (fully qualified name), add it to the imports list. * If there is a conflict adding this import, will return false. - * If reading of the imports has started, this method will return false, - * unless type does not need to be imported. - * @param fqn the fully qualified name to import - * @return true if import add was successful - */ - public boolean addImport(String fqn) { + * If reading of the imports has started, this method will return false, + * unless type does not need to be imported. + * @param fqn the fully qualified name to import + * @return true if import add was successful + */ + public boolean addImport(String fqn) { // if no package don't include it if (fqn.indexOf(".") == -1) { return true; } - // Exclude java.lang classes - if (fqn == null || "".equals(fqn.trim())|| - (fqn.startsWith("java.lang.") && fqn.lastIndexOf(".") == 9)) { - return true; - } - // Exclude primitive types - if (primitiveTypes.contains(fqn)) { - return true; - } - // Reject generics - if (fqn.indexOf("<") != -1 || fqn.indexOf(">") != -1) { - return false; - } - String name = fqn.substring(fqn.lastIndexOf(".") + 1); - String inPlaceFqn = imports.get(name); - if (inPlaceFqn == null) { - // Someone has started to read imports, impossible to add some more - if (state == State.READING) { - return false; - } else { - imports.put(name, fqn); - return true; - } - } - // if fqn is not the same, return false. Otherwise, no need to override. - return inPlaceFqn.equals(fqn); - } + // Exclude java.lang classes + if (fqn == null || fqn.trim().isEmpty() || + (fqn.startsWith("java.lang.") && fqn.lastIndexOf(".") == 9)) { + return true; + } + // Exclude primitive types + if (primitiveTypes.contains(fqn)) { + return true; + } + // Reject generics + if (fqn.indexOf("<") != -1 || fqn.indexOf(">") != -1) { + return false; + } + String name = fqn.substring(fqn.lastIndexOf(".") + 1); + String inPlaceFqn = imports.get(name); + if (inPlaceFqn == null) { + // Someone has started to read imports, impossible to add some more + if (state == State.READING) { + return false; + } else { + imports.put(name, fqn); + return true; + } + } + // if fqn is not the same, return false. Otherwise, no need to override. + return inPlaceFqn.equals(fqn); + } - /** - * Accorging to the already added types, returns the type to write in file. - * If there is a conflict, returns the fully qualified name, otherwise - * returns the simple name - * @param fqn the fully qualified name to add - * @return the fqn or simple name according to in-place imports - */ - public String getType(String fqn) { - boolean importResult = addImport(fqn); - if (!importResult) { - // There is a conflict, do not use simple name - return fqn; - } else { - // No conflict, use simple name - int packageEndIndex = fqn.lastIndexOf("."); - if (packageEndIndex == -1) { - return fqn; - } else { - return fqn.substring(packageEndIndex + 1); - } - } - } + /** + * Accorging to the already added types, returns the type to write in file. + * If there is a conflict, returns the fully qualified name, otherwise + * returns the simple name + * @param fqn the fully qualified name to add + * @return the fqn or simple name according to in-place imports + */ + public String getType(String fqn) { + boolean importResult = addImport(fqn); + if (!importResult) { + // There is a conflict, do not use simple name + return fqn; + } else { + // No conflict, use simple name + int packageEndIndex = fqn.lastIndexOf("."); + if (packageEndIndex == -1) { + return fqn; + } else { + return fqn.substring(packageEndIndex + 1); + } + } + } - /** - * List the imports. This method will remove the useless imports according - * to the given packageName (no need to import a class in the same package) - * @param packageName the current package name (to avoid useless imports) - * @return the imports alphabeticaly sorted - */ - public List<String> getImports(String packageName) { - state = State.READING; - List<String> result = new ArrayList<String>(); - for (String fqn : imports.values()) { - if (!(fqn.lastIndexOf(".") == packageName.length() && fqn - .startsWith(packageName + "."))) { - result.add(fqn); - } - } - Collections.sort(result); - return result; - } + /** + * List the imports. This method will remove the useless imports according + * to the given packageName (no need to import a class in the same package) + * @param packageName the current package name (to avoid useless imports) + * @return the imports alphabeticaly sorted + */ + public List<String> getImports(String packageName) { + state = State.READING; + List<String> result = new ArrayList<String>(); + for (String fqn : imports.values()) { + if (!(fqn.lastIndexOf(".") == packageName.length() && fqn.startsWith(packageName + "."))) { + result.add(fqn); + } + } + Collections.sort(result); + return result; + } - /** - * Method to reset imports list. If imports has been listed, it becomes back - * possible to add imports. - */ - public void clearImports() { - imports.clear(); - state = State.FILLING; - } + /** + * Method to reset imports list. If imports has been listed, it becomes back + * possible to add imports. + */ + public void clearImports() { + imports.clear(); + state = State.FILLING; + } - private enum State { - FILLING, READING - } + private enum State { + + FILLING, READING + } } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java 2009-08-21 13:23:16 UTC (rev 606) +++ trunk/eugene/src/main/java/org/nuiton/eugene/UIModelGenerator.java 2009-08-22 15:03:00 UTC (rev 607) @@ -137,6 +137,7 @@ * Par defaut cette methode retourne le getName du model. Si l'on souhaite * utiliser la methode generateFromUIModel il vaut mieux surcharger cette * methode + * @param model le modele a utiliser * @return le getName du model */ public String getFilenameForUIModel(UIModel model) { Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassImpl.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassImpl.java 2009-08-21 13:23:16 UTC (rev 606) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/xml/ObjectModelClassImpl.java 2009-08-22 15:03:00 UTC (rev 607) @@ -80,10 +80,11 @@ this.abstractz = abstractz; } + @Override public Collection<ObjectModelClass> getSuperclasses() { if (superclasses == null) { superclasses = new ArrayList<ObjectModelClass>(); - Iterator i = superclassesRefs.iterator(); + Iterator<?> i = superclassesRefs.iterator(); while (i.hasNext()) { ObjectModelImplSuperClassRef ref = (ObjectModelImplSuperClassRef) i .next(); @@ -103,6 +104,7 @@ * @return the discriminator for the given superclass as a String if it * exists, null otherwise. */ + @Override public String getDiscriminator(ObjectModelClass superclass) { return superclassesDiscriminators.get(superclass); } @@ -115,10 +117,11 @@ * @return a Collection containing all known direct specialized * ObjectModelClass for this class. */ + @Override public Collection<ObjectModelClass> getSpecialisations() { if (specialisations == null) { specialisations = new ArrayList<ObjectModelClass>(); - for (Iterator i = objectModelImpl.getClasses().iterator(); i + for (Iterator<?> i = objectModelImpl.getClasses().iterator(); i .hasNext();) { ObjectModelClass candidateClass = (ObjectModelClass) i.next(); if (candidateClass.getSuperclasses().contains(this)) { @@ -138,6 +141,7 @@ * @return a Collection containing all known specialized ObjectModelClass * for this class for the specified discriminator. */ + @Override public Collection<ObjectModelClass> getSpecialisations(String discriminator) { List<ObjectModelClass> discriminatedSpecialisations = new ArrayList<ObjectModelClass>(); for (Iterator<ObjectModelClass> i = getSpecialisations().iterator(); i @@ -150,6 +154,7 @@ return discriminatedSpecialisations; } + @Override public Collection<ObjectModelAttribute> getAttributes() { return orderedAttributes; } @@ -161,9 +166,9 @@ * @return the ObjectModelAttribute of the found attribute, or null if the * class contains no attribute for this name. */ + @Override public ObjectModelAttribute getAttribute(String attributeName) { - return (attributeName == null ? null - : (ObjectModelAttribute) attributes.get(attributeName)); + return (attributeName == null ? null : attributes.get(attributeName)); } /** @@ -171,10 +176,12 @@ * * @return a boolean indicating whether this class is abstract or not. */ + @Override public boolean isAbstract() { return abstractz; } + @Override public Collection<ObjectModelOperation> getAllOtherOperations( boolean distinct) { Collection<ObjectModelOperation> result = getAllInterfaceOperations(distinct); @@ -182,6 +189,7 @@ return result; } + @Override public Collection<ObjectModelOperation> getAllSuperclassOperations( boolean distinct) { Collection<ObjectModelOperation> result = null; @@ -196,7 +204,7 @@ protected Collection<ObjectModelOperation> getAllSuperclassOperations( Collection<ObjectModelOperation> result) { - for (Iterator i = getSuperclasses().iterator(); i.hasNext();) { + for (Iterator<?> i = getSuperclasses().iterator(); i.hasNext();) { ObjectModelClassImpl clazz = (ObjectModelClassImpl) i.next(); result.addAll(clazz.getOperations()); clazz.getAllSuperclassOperations(result); @@ -205,6 +213,7 @@ return result; } + @Override public Collection<ObjectModelAttribute> getAllOtherAttributes() { Collection<ObjectModelAttribute> result = new LinkedList<ObjectModelAttribute>(); getAllOtherAttributes(result); @@ -213,7 +222,7 @@ protected Collection<ObjectModelAttribute> getAllOtherAttributes( Collection<ObjectModelAttribute> result) { - for (Iterator i = getSuperclasses().iterator(); i.hasNext();) { + for (Iterator<?> i = getSuperclasses().iterator(); i.hasNext();) { ObjectModelClassImpl clazz = (ObjectModelClassImpl) i.next(); result.addAll(clazz.getAttributes()); clazz.getAllOtherAttributes(result); @@ -221,19 +230,20 @@ return result; } + @Override public String toString() { StringBuffer result = new StringBuffer(); result.append("class " + getQualifiedName() + "<<" + getStereotypes() + ">> tagvalue: " + getTagValues() + " "); result.append("extends "); - for (Iterator i = getSuperclasses().iterator(); i.hasNext();) { + for (Iterator<?> i = getSuperclasses().iterator(); i.hasNext();) { result.append(((ObjectModelClassifier) i.next()).getName()); if (i.hasNext()) { result.append(", "); } } result.append("implements "); - for (Iterator i = getInterfaces().iterator(); i.hasNext();) { + for (Iterator<?> i = getInterfaces().iterator(); i.hasNext();) { result.append(((ObjectModelClassifier) i.next()).getName()); if (i.hasNext()) { result.append(", "); @@ -249,6 +259,7 @@ * * @return a boolean indicating whether this classifier is a class or not. */ + @Override public boolean isClass() { return true; } @@ -261,6 +272,7 @@ * @return a boolean indicating whether this classifier is an interface or * not. */ + @Override public boolean isInterface() { return false; }
participants (1)
-
tchemit@users.nuiton.org