IGL Course

Acceleo (doc generation)

Go back

In this section, we will again generate documentation, for our classes. You will edit the following files in org.eclipse.acceleo.module.sample > src > org/eclipse/acceleo/module/sample/

  • main/generateMain.mtl
  • files/generateClass.mtl
  • files/generateInterface.mtl

**Don't forget to use CTRL+SPACE to generate some syntax/autocompletion.


TODO 1 (generateMain)

[comment TODO search for classes and interfaces in model's nested packages/]
[comment TODO then display Package's name/]
[comment TODO and indent classes and interfaces names/]

Todo: iterate values in "nestedPackage", and call "generateClassElement" if we got a class, or "generateInterfaceElement" if we got an interface.

Tips

Solution

Don't forget to import

[import org::eclipse::acceleo::module::sample::files::generateInterface/]

Then the code is

[comment DONE search for classes and interfaces in model's nested packages/]
[for (p : Package | aModel.nestedPackage->sortedBy(name))]
	[comment DONE then display Package's name/]
	Package [p.name/]
	[comment DONE and indent classes and interfaces names/]
	[for (c : Class | p.packagedElement->filter(Class)->sortedBy(name))]
		[generateClassElement(c)/]
	[/for]
	[for (i : Interface | p.packagedElement->filter(Interface)->sortedBy(name))]
		[generateInterfaceElement(i)/]
	[/for]
[/for]

I'm expecting something like this, but without changing some things, it won't look neat at all.

Package {Name}
	public class {Name} {extend ...}{implements ...} {
		
		public {Type} {attributeName};
			
		public {Type} {methodName}({args}) {
		}			
	}

Generate Documentation

  • In the runtime_eclipse instance
  • Click on the arrow to extend the model (see di, notation, UML)
  • Right-click on the UML file
    • Acceleo Model To Text
    • Generate UML2text
  • You got a .txt in the folder src-gen

TODO 2 (generateClass)

[comment TODO also generate Association elements for aClass : see generateAssociation.mtl/]

Todo: simply call generateAssociationElement

Solution

Don't forget to import

[import org::eclipse::acceleo::module::sample::files::generateAssociation/]

Then the code is

[comment DONE also generate Association elements for aClass : see generateAssociation.mtl/]
[generateAssociationElement(aClass)/]

TODO 3 (generateInterface)

[comment TODO see generateClass.mtl for inspiration/]
  • Todo: ???
  • Solution: Whatever you do here, it will never be called, so that's useless. Wondering why, here is the explanation
    • Currently, your code generateMain (which is the code of the teacher) is not working.
    • Our interfaces are not inside a package, but inside a package which is in another package. Your code isn't recursive, so we will never generate interfaces.
    • Note that interfaces are generated in their own file, so you can see that if you got only one file, then you don't have your interfaces

Fortunately, the teachers did not do something that is this complex, so don't lose time on it as we won't use it later.