How to set the order of the mapping configurations?

I am currently trying to create a simple Entity-To-View converter. The idea is to have a custom object "Entity" and another custom object "View" and generate the JPA entity a view object and a converter between these two with MPS. So i have set up a generator which contains (among other things) two mappings:

One which converts the "View" into a java class (called "views") and another which converts the "View" into a converter java class (called "converters"). Now since the converter requires the view, i want the "converters" mapping to run after the "views" mapping so that I can use mapping labels to get the generated view class.

I tried to set this up in the "Generator Priorities" (as shown here: https://confluence.jetbrains.com/display/MPSD30/Generator+User+Guide+Demo6#GeneratorUserGuideDemo6-specifyingpriorities) but once I set that priority, the "converters" mapping configuration is no longer executed anymore and therefore no converter is being generated.

2015-02-06_17-24-48.png


I am probably setting something up the wrong way. Can someone help me in setting this dependency up correctly?
11 comments
Could it be that the View is no longer present in the input model, when the converters are generated? I suspect it may have been consumed when views were generated. Maybe the "keep input roots" option in the root mapping rule could be of help here?

You may try the "Show Generation Plan" option in model's context menu to see the plan that the generation has built.

BTW, the link to the doc points to an MPS 3.0 version. Not that there have been so many changes, but https://confluence.jetbrains.com/display/MPSD30/Generator+User+Guide+Demo6#GeneratorUserGuideDemo6-specifyingpriorities would be safer.
0
Ok i will try that. Thank you. On a related note, am I supposed to get email notification on starred forum topics? Sending a test email from the profile works but I am not notified when someone answers to my watched threads.
0
I'm not sure, I would expect the star on a thread to guarantee notifications. Maybe you need to mark the whole MPS forum as "Watching" or "Daily Digest" as well, if the star has no effect and provided the e-mail has not been blocked by your spam filter.
0
Okay, so "Keep Input Roots" definitely helped. I'm not really able to decipher the output of "Show Generation Plan", is there some description about what all the outputted text actually means?

  Ignored mapping priority rules:  
 
Generator for language jetbrains.mps.lang.generator.generationContext defines invalid priority rule [jetbrains.mps.lang.generator.generationContext/:*] strictly_together [jetbrains.mps.lang.pattern/:*], with no mapping configurations specified at one side. The rule is ignored.  
=================================  
---------------------  mappings partitioning  -----------------------------------  
 
 [ 1 ]  
  jetbrains.mps.lang.generator.generator.baseLanguage.template.main.*  
 
 [ 2 ]  
  jetbrains.mps.lang.generator.generationContext.generator.baseLanguage.template.main.*  
 
 [ 3 ]  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_concept_method_call  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_concept_switch  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_implicitSelect  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_sequence_operations  
 
 [ 4 ]  
  jetbrains.mps.baseLanguage.collections.generator.baseLanguage.template.pre.*  
 
 [ 5 ]  
  jetbrains.mps.baseLanguage.collections.generator.baseLanguage.template.main.*  
  jetbrains.mps.baseLanguage.collections.generator.baseLanguage.template.post.*  
 
 [ 6 ]  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_assignmentStatement  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_attribute_access  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_concept_operations  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_enum_operations  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_enums  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_link_operations  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_linklist_operations  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_main  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_model_operations  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_node_operations  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_property_operations  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_reflection  
  jetbrains.mps.lang.smodel.generator.baseLanguage.template.main.mc_searchScope_operations  
 
 [ 7 ]  
  jetbrains.mps.baseLanguage.closures.generator.baseLanguage.template.main.preproc  
 
 [ 8 ]  
  jetbrains.mps.baseLanguage.closures.generator.baseLanguage.template.main.main  
 
 [ 9 ]  
  jetbrains.mps.baseLanguage.generator.java.closures.*  
  jetbrains.mps.baseLanguage.generator.java.strings.*  
 
 [ 10 ]  
  jetbrains.mps.baseLanguage.generator.java.main.*  
  jetbrains.mps.baseLanguageInternal.generator.template.main.*  
 
---------------------------------------------------------------------------------  
13 roots, 1 components  
#0(13):  entities Converter converters weave_ViewProperty View views reduce_ViewProperty returnTypeOf_Finder reduce_Finder daos Dao reduce_Property Entity  
 
 
Strong:  
13 roots, 12 components  
#0(1):  Entity  
#1(1):  reduce_Property  
#2(1):  entities  
#3(1):  Dao  
#4(1):  returnTypeOf_Finder  
#5(1):  reduce_Finder  
#6(1):  daos  
#7(1):  View  
#8(2):  views reduce_ViewProperty  
#9(1):  Converter  
#10(1):  weave_ViewProperty  
#11(1):  converters   

prettyPrint();

With the "keep input roots" enabled, generation now goes a bit further but I am getting strange error messages that the context node for my one weaving template could not be defined. Is there some way to debug all the scripts that you enter, so you can basically see what kind of node a script is currently working on and what it is returning?
0
You can enable showing transient models (the bottom right corner of the MPS window), so that after generation all the intermediate models get stored at the bottom of your project tree (in the left-hand side project view).
Some more details are to be found here: https://confluence.jetbrains.com/display/MPSD32/Generator+cookbook#Generatorcookbook-CanIdebugthegenerationprocess%3F

The generation plan shows the names and order of all generators that will be run when generating the selected model.
0
Hi Vaclav, thank you very much for these instructions. From what I see, the generation order now seems to be OK however I still struggle to get references resolved in my "Converter" class. As you can see first the "views" generator runs, which creates my AgentView class from the AgentView element of my custom language.
2015-02-17_10-51-32.png
. Then the second step runs both the "entities" and "converter" generators. The generated AgentViewConverter class references both to the AgentView class generated by "views" and the Agent class generated by "entities". It uses the genContext.get output <mapping label> for (<node>) method to reference both outputs.
2015-02-17_10-52-58.png

and
2015-02-17_11-01-21.png

However in the final output only the references to the Agent class are resolved but not the references to the AgentView class.
2015-02-17_10-51-44.png


This leads to compilation errors further down the road. Are mapping labels only valid within the same generator phase? If so, how can I reference stuff that has been generated in an earlier phase?
0
Hello Jan,

indeed, mapping configurations are not visible across different generation steps.

Is there anything that prevents you from joining the two phases into one, maybe even a single mapping configuration with two (or more) root mapping rules? The reference macros should be processed correctly only after all classes have been generated and added to mapping labels.

Vaclav
0
Hi Vaclav,

it seems that I fundamentally misunderstood the way in which root mapping rules work. I thought that once a root mapping rule processed an input element, that input element will not be processed by another root mapping rule. Therefore I thought that you cannot have two root mapping rules which use the same concept as input. And that's why I came up with multiple mapping configurations when I in fact don't even need them. I just tried adding multiple root mappings and it indeed solves my problem :) Thank you very much for this eye-opener.

Jan
0

>Is there anything that prevents you from joining the two phases into one, maybe even a single mapping configuration with two (or more) root mapping rules?

Vaclav,

I've got similar problem and I tried to reuse mapping labels from one mapping configuration in subsequent one. It looks like mapping labels are not accessible in between mapping configurations. Are there ways to workaround that except merging all the configs into single mapping config? (I use multiple languages so it is not quite possible to use single mapping configuration)

By the way, multiple mapping configurations produce multiple transient models, so they make it easier to debug the generation.

0

I believe the mapping configurations need to be run in the same phase of generation (and the model with the labels has to be imported in the other generator model).

0

I could add that running mapping configurations in the same generation step is achieved either by generator priorities (generator module properties dialog, priorities tab) which is the old method, or with the help of a new feature https://confluence.jetbrains.com/display/MPSD34/Generation+plan

0

Please sign in to leave a comment.