v2flattening.tex 1.2 KB

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