Search code examples
javaemfacceleo

Acceleo M2T (Cannot access to the my matamodele attributes , references .. )


I am developing a M2T generator in Acceleo (in Obeo Designer). I have created my metamodel based on *.ecore (pfe.ecore ) and then I have created an instance model in runtime (MyModels.pfe) using Sirius.

Now I am trying to generate the java code of MyModels.pfe using Accelo -the class root is InterationSpatiale.

I want to generate a *.java for each of my classes in the diagram here is my generate.mtl file

 [comment encoding = UTF-8 /]
[module generate('http://www.example.org/pfe')/]
[template public generateElement(myinteractionspatiale : 
InteractionSpatiale)]
[comment @main/]
[file (myinteractionspatiale.name.concat('.java'), false, 'UTF-8')]

public class [myinteractionspatiale.name/] {

[for (aEAttribute : ecore :: EAttribute | 
 myinteractionspatiale.eClass().eAllAttributes)]
   [aEAttribute.eType.instanceClassName/] [aEAttribute.name/];
[/for]
[for (aEReference : EReference 
|myinteractionspatiale.eClass().eAllReferences)]
  [aEReference.eReferenceType.name/] [aEReference.name/];
[/for]
[for (aEAttribute : EAttribute | 
myinteractionspatiale.eClass().eAllAttributes)]
  public [aEAttribute.eType.instanceClassName/] 
  get[aEAttribute.name.toUpperFirst()/] () {
    return this.[aEAttribute.name/];
  }
 [/for]
 [for (aEAttribute : EAttribute | 
 myinteractionspatiale.eClass().eAllAttributes)]
   public void set[aEAttribute.name.toUpperFirst()/] 
   ([aEAttribute.eType.instanceClassName/] [aEAttribute.name/]) {
    this.[aEAttribute.name/] = [aEAttribute.name/];
  }
 [/for]

 [for (aEReference : EReference | 
 myinteractionspatiale.eClass().eAllReferences)]
   public [aEReference.eReferenceType.name/] 
  get[aEReference.name.toUpperFirst()/] () {
    return this.[aEReference.name/];
  }
 [/for]

 [for (aEReference : EReference | 
  myinteractionspatiale.eClass().eAllReferences)]
  public void set[aEReference.name.toUpperFirst()/] 
  ([aEReference.eReferenceType.name/] [aEReference.name/]) {
    this.[aEReference.name/] = [aEReference.name/];}
 [/for]

[for (aEOperation : EOperation | 
myinteractionspatiale.eClass().eAllOperations)]
  public [aEOperation.eType.instanceClassName/] [aEOperation.name/] () {
    }
[/for]

}
 [/file]

[/template]

the generated file I got App.java is

public class App {

java.lang.String name;
Entite entite;
Evenement evenement;
SystemeCoordonnees systemecoordonnees;
TacheSysteme tachesysteme;
RelationSpatiale relationspatiale;
InteractionSpatiale interactionspatiale;
public java.lang.String getName () {
    return this.name;
}
public void setName (java.lang.String name) {
    this.name = name;
}

public Entite getEntite () {
    return this.entite;
}
public Evenement getEvenement () {
    return this.evenement;
}
public SystemeCoordonnees getSystemecoordonnees () {
    return this.systemecoordonnees;
}
public TacheSysteme getTachesysteme () {
    return this.tachesysteme;
}
public RelationSpatiale getRelationspatiale () {
    return this.relationspatiale;
}
public InteractionSpatiale getInteractionspatiale () {
    return this.interactionspatiale;
}

public void setEntite (Entite entite) {
    this.entite = entite;
}
public void setEvenement (Evenement evenement) {
    this.evenement = evenement;
}
public void setSystemecoordonnees (SystemeCoordonnees systemecoordonnees) 
{
    this.systemecoordonnees = systemecoordonnees;
}
public void setTachesysteme (TacheSysteme tachesysteme) {
    this.tachesysteme = tachesysteme;
}
public void setRelationspatiale (RelationSpatiale relationspatiale) {
    this.relationspatiale = relationspatiale;
}
public void setInteractionspatiale (InteractionSpatiale 
interactionspatiale) {
    this.interactionspatiale = interactionspatiale;
}
}

But what I really wanted is to have a file for each class of the model MyModels.pfe not just the java file of the root class.

kindly check the MyModels.pfe to have an idea about about what I want to generate. ScreenShot of MyModels.pfe

Any help is much appreciated on how to iterate and have a file for each class with its attributes and their values[EFixe.java, EMobile.java ...]


Solution

  • aEClass : InteractionSpatiale
    

    is misleading, you should call it something like myInteractionSpatiale because your parameter is an instance of InteractionSpatiale (in the sense of Java/Acceleo typing).

    In the sense of EMF typing, your myInteractionSpatiale is an EObject that is an instance of the EClass "InteractionSpatiale" you have defined in your metamodel pfe.ecore

    I understand you want to iterate on the attributes of this EClass:

    myInteractionSpatiale.eClass().getAllAttributes()