MPS model to Java model (class diagram

Hello forum!

What's the easiest way to accomplish my intention? Do I have to built my own transformator? If so, what's the best way to start with? Could my intention have success in a feasible time?
How do I have do configure my generator aspect for that?
Note my whole thing should be generic, so if my MPS model changes, I don't want to rewrite my Java generator code.

For example in my sandbox:
person
{
  name:Chuck Norris
  car
  {
    name:Porsche
    horsepower:500
  } 
  car
  {
    name:Fiat
    horsepower:100
  }
}
}
prettyPrint();

My result should look like this:
public class Person
{
    private String name;
    private ArrayList<Car> car;

    public Person(String name, ArrayList<Car> car) {
        this.name = name;
        this.car = car;
    }

    public String getName() {
        return name;
    }

    public List<Car> getCar() {
        return car;
    }
}
public class Car {
    private String name;
    private int horsepower;

    public Car(String name, int horsepower) {
        this.name = name;
        this.horsepower = horsepower;
    }

    public String getName() {
        return name;
    }

    public int getHorsepower() {
        return horsepower;
    }
}
public static void main(String[] args) {
        Car car1 = new Car("Porsche", 500);
        Car car2 = new Car("Fiat", 100);
        ArrayList<Car> cars = new ArrayList<Car>();
        cars.add(car1);
        cars.add(car2);
        Person person = new Person("Chuck Norris", cars);
    }
prettyPrint();

Regards
msch95
4 comments
Hi,

to me this looks like a classic exercise of model-to-model transformation that you should be easily able to do once you go through the introductory tutorials, namely the generator tutorial - https://confluence.jetbrains.com/display/MPSD32/Fast+Track+to+MPS#FastTracktoMPS-Step10-Generatortutorial

Vaclav
0
Thanks Vaclav!
That's clear to me. But the issue is I want to have it generic. This means every concept in MPS is derived from an interface. Let's say IEntity.

For my generator I'd like to have one generator which reads all my concept-structure (childs, properties, references) and translates this into a Java model. Remember this should be generic, because most likely the MPS model is going to change in the future and for me it's not handy to implement the generator for new concepts again and again.
The second generator should of course know about the Java model and feeds it with data. My questions wasn't to clear, I have to admit.

I want to know if it's possible to achieve in a feasible time?
0
Hi,

I can imagine a reduction rule on IEntity that attempts to generate classes in a generic way, perhaps in cooperation with the Behavior methods of the individual concepts.

Vaclav
0
Behavior methods aren't so important to me. The above example is a simple version of what I try to do. My real model is far more complex.
For now I'll try to build a prototype.
Thanks for the (as always) great help.
0

Please sign in to leave a comment.