_v0flattening.tex 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. %\begin{tomcode3}
  2. \begin{codesource2}[label=code:v0flattening,caption=Implémentation de la transformation d'aplatissement de hiérarchie de classes en Java]
  3. public static classflattening.VirtualRoot v0_processClass(classflattening.VirtualRoot root) {
  4. org.eclipse.emf.common.util.EList<classflattening.Class> newChildren =
  5. new org.eclipse.emf.common.util.BasicEList<classflattening.Class>();
  6. for(classflattening.Class cl : root.getChildren()) {
  7. if(cl.getSubclass().isEmpty()) {
  8. newChildren.add(flattening(cl));
  9. }
  10. }
  11. classflattening.VirtualRoot result = (classflattening.VirtualRoot)
  12. classflattening.ClassflatteningFactory.eINSTANCE.create(
  13. (EClass)classflattening.ClassflatteningPackage.eINSTANCE.getEClassifier("VirtualRoot"));
  14. result.eSet(result.eClass().getEStructuralFeature("children"),(Object)newChildren);
  15. return result;
  16. }
  17. public static classflattening.Class flattening(classflattening.Class toFlatten) {
  18. classflattening.Class parent = toFlatten.getSuperclass();
  19. if(parent==null) {
  20. return toFlatten;
  21. } else {
  22. classflattening.Class flattenedParent = flattening(parent);
  23. org.eclipse.emf.common.util.EList<classflattening.Attribute> head =
  24. toFlatten.getAttributes();
  25. head.addAll(flattenedParent.getAttributes());
  26. classflattening.Class result = (classflattening.Class)classflattening.ClassflatteningFactory.eINSTANCE.
  27. create((EClass)classflattening.ClassflatteningPackage.eINSTANCE.getEClassifier("Class"));
  28. result.eSet(result.eClass().getEStructuralFeature("name"),(Object)flattenedParent.getName()+toFlatten.getName());
  29. result.eSet(result.eClass().getEStructuralFeature("attributes"),(Object)head);
  30. result.eSet(result.eClass().getEStructuralFeature("superclass"),(Object)flattenedParent.getSuperclass());
  31. result.eSet(result.eClass().getEStructuralFeature("subclass"),
  32. (Object)(new org.eclipse.emf.common.util.BasicEList<classflattening.Class>()) );
  33. result.eSet(result.eClass().getEStructuralFeature("root"),(Object)virtR);
  34. return result;
  35. }
  36. }
  37. \end{codesource2}
  38. %\end{tomcode3}