Programmatically Generating MPS models

Hi,

I would like to migrate from a huge Java code base (Hibernate entities) to my simple MPS model (from which I will generate the Java source code again).
However, migrating manually seems to be very much work. So my question: Is there a good way to generate MPS-Models (e.g. via an API or similar)?

Thanks in advance!
0
13 comments
Avatar
Permanently deleted user
Hi Yann,

for sure, you can do that.
To speak not too many words: Jens Nerche did some interesting examples at https://github.com/mpSamples and the one at https://github.com/mpSamples/mps.samples.plugin seems to fit your needs :) .

Regards, Mirko
0
Avatar
Permanently deleted user
Thanks! Works perfectly!
0
Avatar
Permanently deleted user
Hi,

I looked at the example, but it seems that no model is created programmatically there. Instead they used the existing one and add a new root node.

I would like to realy create a new model so the example doesn't fit for my requirements. I have nodes in an extendet version of baseLanguage and want to sort the baseLanguage Classes and Interfaces to new models at generation time for the output. Anybody an idea how to handle this?

Tanks in advance!
0
Avatar
Permanently deleted user
That is a whole other thing, you want to do.

Just write a simple Model2Model Generator.
I think you can use the COPYSRCL Macro and return a sorted List in this macro.
0
Avatar
Permanently deleted user
The COPYSRCL Macro is executed as part of a generationstep for a model. the input nodes I copy are always part of the same output model. I don't have the possibility to choose another model as target...
0
Avatar
Permanently deleted user
Again, I don't understand your problem... sry.

What do you mean with:
"the input nodes I copy are always part of the same output model"

When a generator is executed a new output model is always generated.
0
Avatar
Permanently deleted user
I have a source model structure and I want to change the structure of the output model. My source model (A) contains 3 classes a1, b1 and c1 and contains another model (B). The model B contains 3 classes a2, b2, c2 and another model (C). Same procedure for model C. After the generation I expect the three models at the top level. Model A should contain a1, a2, a3, Model B b1, b2, b3 and so on.
0
Avatar
Permanently deleted user
I would be also interested in an API to create models programmatically
0
Avatar
Permanently deleted user
Try this:

IModule module = MPSModuleRepository.getInstance().getModuleByFqName("fq.name.of.an.existing.module"); 
SModelFqName fqName = new SModelFqName("fq.name.of.the.new.model", null); 
SModelRoot root = module.getSModelRoots().iterator().next(); 
SModelDescriptor newModel = module.createModel(fqName, root, null);
0
Avatar
Permanently deleted user
It works, thank you!
0
Changes for MPS 3.0
  • - SModelFqname is deprecated
  • getModuleByFqname(..) returns an SModel
  • createModel(...)  does not exist on SModule
I have changed this code to the following:
  SModule module = MPSModuleRepository.getInstance().getModuleByFqName("com.i2s.ibml.core.base.sandbox");
  ModelRoot root = module.getModelRoots().iterator().next();   
  root.createModel("name.of.new.model");
-1
Avatar
Permanently deleted user
A few years ago I thought about using MPS for a small project, but gave up. The idea was to generate into models in 'intermediate language', and then into java or text. That would be very convenient to be able to inspect intermediate results in MPS. Is to possible now in MPS?
0
Avatar
Permanently deleted user
Yes, it is. Intermediate results are called transient models.


On Mon, Sep 9, 2013 at 4:01 PM, Igor Karpov - Meta Programming System <
jetforum@jetbrains.com> wrote:

* Meta Programming System<http://forum.jetbrains.com/forum/Meta-Programming-System>
* > * Programmatically Generating MPS models<http://forum.jetbrains.com/thread/Meta-Programming-System-543>
* 8:01 am<http://forum.jetbrains.com/thread/Meta-Programming-System-543?message=Meta-Programming-System-543-12>  Igor
Karpov <http://forum.jetbrains.com/user/ikar>

A few years ago I thought about using MPS for a small project, but gave
up. The idea was to generate into models in 'intermediate language', and
then into java or text. That would be very convenient to be able to inspect
intermediate results in MPS. Is to possible now in MPS?

   Yann Massard <http://forum.jetbrains.com/user/yamass> @ 03/29/11<http://forum.jetbrains.com/thread/Meta-Programming-System-543>

Hi,

I would like to migrate from a huge Java code base (Hibernate entities) to
my simple MPS model (from which I will generate the Java source code again).
However, migrating manually seems to be very much work. So my question: Is
there a good way to generate MPS-Models (e.g. via an API or similar)?

Thanks in advance!

  JetBrains Forum | Build #172 (Jul/18/2013 5:34PM) | Feedback<http://confluence.jetbrains.net/display/JETF/Feedback>
0

Please sign in to leave a comment.