v3flattening.tex 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. \begin{codesource}[label=code:v3flattening,caption=Version 3 : Implémentation de la transformation d'aplatissement de hiérarchie de classes en Tom+Java avec stratégies.]
  2. %strategy FlatteningStrat(translator:UMLClassesFlattening) extends Identity() {
  3. visit cfVirtualRoot {
  4. cfVirtualRoot(cfClassEList(_*,cl@cfClass(n,_,_,cfClassEList(),_),_*)) -> {
  5. EList<Class> newChildren = translator.virtR.getChildren();
  6. translator.virtR = `cfVirtualRoot(cfClassEList(flattening(cl),newChildren*));
  7. }
  8. }
  9. }
  10. public static Class flattening(Class toFlatten) {
  11. Class parent = toFlatten.getSuperclass();
  12. if(parent==null) {
  13. return toFlatten;
  14. } else {
  15. Class flattenedParent = flattening(parent);
  16. EList<Attribute> head = toFlatten.getAttributes();
  17. head.addAll(flattenedParent.getAttributes());
  18. return `cfClass(flattenedParent.getName()+toFlatten.getName(), head,
  19. flattenedParent.getSuperclass(), cfClassEList(), null);
  20. }
  21. }
  22. ...
  23. public static void main(String[] args) {
  24. ...
  25. VirtualRoot translator.virtR = `cfVirtualRoot(cfClassEList());
  26. Strategy transformer = `BottomUp(FlatteningStrat(translator));
  27. transformer.visit(source_root, new EcoreContainmentIntrospector());
  28. ...
  29. }
  30. \end{codesource}