Index: topia/src/java/org/codelutin/topia/generators/DefaultObjectModelToJavaGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/DefaultObjectModelToJavaGenerator.java:1.1 topia/src/java/org/codelutin/topia/generators/DefaultObjectModelToJavaGenerator.java:1.2 --- topia/src/java/org/codelutin/topia/generators/DefaultObjectModelToJavaGenerator.java:1.1 Tue Jun 22 19:01:05 2004 +++ topia/src/java/org/codelutin/topia/generators/DefaultObjectModelToJavaGenerator.java Wed Jun 30 12:31:53 2004 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * - * Mise a jour: $Date: 2004/06/22 19:01:05 $ + * Mise a jour: $Date: 2004/06/30 12:31:53 $ * par : $Author: bpoussin $ */ @@ -112,19 +112,19 @@ // ------------- Operations declarations for(Iterator i=clazz.getOperations().iterator(); i.hasNext();){ ObjectModelOperation operation = (ObjectModelOperation) i.next(); - generateOperationDeclation(output, operation); + generateOperationDeclaration(output, operation); generateOperationBody(output, operation); } // parcours les operations des interfaces - for(Iterator i=clazz.getInterfaces().iterator(); i.hasNext();){ - ObjectModelInterface interfacez = (ObjectModelInterface) i.next(); - for(Iterator o=interfacez.getOperations().iterator(); o.hasNext();){ - ObjectModelOperation operation = (ObjectModelOperation) o.next(); - generateOperationDeclation(output, operation); - generateOperationBody(output, operation); - } - } +// for(Iterator i=clazz.getInterfaces().iterator(); i.hasNext();){ +// ObjectModelInterface interfacez = (ObjectModelInterface) i.next(); +// for(Iterator o=interfacez.getOperations().iterator(); o.hasNext();){ +// ObjectModelOperation operation = (ObjectModelOperation) o.next(); +// generateOperationDeclaration(output, operation); +// generateOperationBody(output, operation); +// } +// } // ---------------- All that framework used generateOther(output, clazz); @@ -167,7 +167,7 @@ // ------------- Operations declarations for(Iterator i=interfacez.getOperations().iterator(); i.hasNext();){ ObjectModelOperation operation = (ObjectModelOperation) i.next(); - generateOperationDeclation(output, operation); + generateOperationDeclaration(output, operation); // never body for interface (i hope :) /*{; }*/ @@ -648,7 +648,7 @@ // O P E R A T I O N ////////////////////////////////////////////////////////////////////// - public void generateOperationDeclation(Writer output, ObjectModelOperation operation) + public void generateOperationDeclaration(Writer output, ObjectModelOperation operation) throws IOException { /*{ /** Index: topia/src/java/org/codelutin/topia/generators/Util.java diff -u topia/src/java/org/codelutin/topia/generators/Util.java:1.2 topia/src/java/org/codelutin/topia/generators/Util.java:1.3 --- topia/src/java/org/codelutin/topia/generators/Util.java:1.2 Tue Jun 22 19:01:05 2004 +++ topia/src/java/org/codelutin/topia/generators/Util.java Wed Jun 30 12:31:53 2004 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Mise a jour: $Date: 2004/06/22 19:01:05 $ + * Mise a jour: $Date: 2004/06/30 12:31:53 $ * par : $Author: bpoussin $ */ @@ -41,6 +41,7 @@ import org.codelutin.generator.models.object.ObjectModelClassifier; import org.codelutin.generator.models.object.ObjectModelInterface; import org.codelutin.generator.models.object.ObjectModelOperation; +import java.util.List; /** * Classe contenant des methodes utiles pour la generation @@ -172,22 +173,184 @@ return false; } +// /** +// * Une class est abtraite si elle a des operations abtraite ou qu'elle +// * implante des interfaces qui ont des operations ou qu'elle etend une +// * classe qui a des operations ou des interfaces qui ont des operations. +// * Mais sans implanter elle meme ces operations +// */ +// public static boolean hasAbstractOperation(ObjectModelClass clazz){ +// for(Iterator i=clazz.getOperations().iterator(); i.hasNext();){ +// ObjectModelOperation operation = (ObjectModelOperation)i.next(); +// if(operation.isAbstract()){ +// return true; +// } +// } +// for(Iterator i=clazz.getSuperclasses().iterator(); i.hasNext();){ +// ObjectModelClass parentClazz = (ObjectModelClass)i.next(); +// if(hasAbstractOperation(parentClazz)){ +// return true; +// } +// } +// for(Iterator i=clazz.getInterfaces().iterator(); i.hasNext();){ +// ObjectModelInterface interfacez = (ObjectModelInterface)i.next(); +// if(hasOperation(interfacez)){ +// return true; +// } +// } +// return false; +// } + /** - * Une class est abtraite si elle a des operations abtraite ou qu'elle - * implante des interfaces qui ont des operations. + * Donne la liste de toutes les operations abstraites definies sur la + * classe, ceci comprend les operations definie sur les interfaces ou + * superclass qu'elle etend. */ - public static boolean hasAbstractOperation(ObjectModelClass clazz){ + public static List getAbstractOperationList(ObjectModelClassifier clazz){ + List result = new ArrayList(); + getAbstractOperationList(clazz, result); + return result; + } + /** + * Donne la liste de toutes les operations abstraites definies sur la + * classe, ceci comprend les operations definie sur les interfaces ou + * superclass qu'elle etend. + * @param clazz la classe sur lequel il faut chercher les operations + * @param result un objet liste instancier qui sert a mettre les operations + * trouvées + */ + protected static void getAbstractOperationList(ObjectModelClassifier clazz, List result){ for(Iterator i=clazz.getOperations().iterator(); i.hasNext();){ ObjectModelOperation operation = (ObjectModelOperation)i.next(); - if(operation.isAbstract()){ - return true; + if(clazz instanceof ObjectModelInterface || operation.isAbstract()){ + result.add(operation); + } + } + if(clazz instanceof ObjectModelClass){ + for(Iterator i=((ObjectModelClass)clazz).getSuperclasses().iterator(); i.hasNext();){ + ObjectModelClass parentClazz = (ObjectModelClass)i.next(); + getAbstractOperationList(parentClazz, result); } } for(Iterator i=clazz.getInterfaces().iterator(); i.hasNext();){ ObjectModelInterface interfacez = (ObjectModelInterface)i.next(); - if(hasOperation(interfacez)){ + getAbstractOperationList(interfacez, result); + } + } + + + /** + *

Methode qui retourne vrai si la classe ou la super classe n'implantent + * pas toutes les methodes des interfaces ou bien si elle contient des + * operations abstraites.

+ *

La classe peut implanter une operation soit parce qu'elle a aussi + * l'operation de defini et marquee non abstraite, soit parce que sa + * superclasse implante l'operation, soit parce qu'elle ou sa super classe + * implantent l'operation par la generation des methodes d'acces au + * attributs.

+ *

ATTENTION: une methode non abstraite dans une superclasse ne peut pas + * devenir abstraite dans une classe enfant.

+ */ + public static boolean hasAbstractOperation(ObjectModelClass clazz){ + // recherche de toutes les methodes abstraites de la classe est des + //super classes et des interfaces. + List operations = getAbstractOperationList(clazz); +//System.out.println("List op:" + operations); + // pour chaque operation abstraite, on regarde si la classe ou les + // superclasses les implantes ou les laisse abstraites. + for(Iterator i=operations.iterator(); i.hasNext();){ + ObjectModelOperation operation = (ObjectModelOperation)i.next(); +// System.out.println(operation+" implemented by :"+clazz+" == "+implementOperation(clazz, operation)); + if(! implementOperation(clazz, operation)){ return true; } + } + return false; + } + + /** + * Retourne vrai si la classe ou sa super classe implante l'operation passé + * en argument. Cela est vrai si la classe definie l'operation comme non + * abstraites ou qu'un attribut généré cette méthode. + * pour les attributs les methodes sont: get[attributeName]() + * et si l'attribut n'est pas readOnly on aura pour un attribut de + * cardinalite 1: set[attributeName]([attributeType]) + * cardinalite n: add[attributeName]([attributeType]), + * remove[attributeName]([attributeType]), clear[attributeName]() + */ + public static boolean implementOperation(ObjectModelClass clazz, ObjectModelOperation operation){ + for(Iterator i=clazz.getOperations().iterator(); i.hasNext();){ + if(operation.equals(i.next())){ + return true; + } + } + + // on a pas trouve sur la classe on recherche sur les super classes + for(Iterator i=clazz.getSuperclasses().iterator(); i.hasNext();){ + ObjectModelClass parentClazz = (ObjectModelClass)i.next(); + if(implementOperation(parentClazz, operation)){ + return true; + } + } + + // on a pas trouver sur les operations declarées + // on recherche sur les opérations générer par les attributs + for(Iterator i=clazz.getAttributes().iterator(); i.hasNext();){ + ObjectModelAttribute att = (ObjectModelAttribute)i.next(); + String name = null; + String []argType = null; + + name = "get" + Util.capitalize(att.getName()); + argType = null; + + if(sameOperation(operation, name, argType)){ + return true; + } + + if(!Util.isReadOnly(att)){ + if(!Util.isNMultiplicity(att)){ + name = "set" + Util.capitalize(att.getName()); + argType = new String[]{att.getType()}; + if(sameOperation(operation, name, argType)){ + return true; + } + }else{ + name = "add" + Util.capitalize(att.getName()); + argType = new String[]{att.getType()}; + if(sameOperation(operation, name, argType)){ + return true; + } + name = "remove" + Util.capitalize(att.getName()); + argType = new String[]{att.getType()}; + if(sameOperation(operation, name, argType)){ + return true; + } + name = "clear" + Util.capitalize(att.getName()); + argType = null; + if(sameOperation(operation, name, argType)){ + return true; + } + } + } + } + + return false; + } + + /** + * Verifie que le nom de l'operation est le meme que le parametre name, et + * que les type des parametres de operation sont les memes que argType + */ + public static boolean sameOperation(ObjectModelOperation op, String name, String[] argType){ + if(name.equals(op.getName()) && argType.length == op.getParameters().size()){ + int pos = 0; + for(Iterator i=op.getParameters().iterator(); i.hasNext(); pos++){ + ObjectModelParameter p = (ObjectModelParameter)i.next(); + if(!p.getType().equals(argType[pos])){ + return false; + } + } + return true; } return false; }