Unresolved references in Generated text Follow
Hello,
I have a couple of questions with respect to generating Java from my language using the generator.
Here is how my language looks:
This is how my language directory looks:
And my root mapping rule looks like so:
And now I get some errors in my generated text. I am attaching a screenshot of one of steps in which I get some erroneous generated text.
Clearly there are problems. I have the following questions:
1. Although I have 4 persons in my Workflow (1 in each WorkflowStep)-> Customer, Chef, Waiter and Customer.... the Customer refers to a single instance. When I use a LOOP macro to generate instance variables, 4 of them are created with 2 for Customer which is right according to the LOOP semantics. How can I generate only 1 variable for Customer?
2. The same problem occurs with the nested classes. Ideally I should have 1 Customer class generated with place_order() and pay_bill() methods inside it.
3. I created a WorkFlowStatus enum (BaseLang enum concept) in the generator model to map the WorkFlowStatus concept in my RWMS language but in the generated code, I get a unresolved reference problem. How may I fix this?
They look like so:
Sorry for the extremely wrong question. I thought it would be helpful to provide context.
Many thanks!!
Please sign in to leave a comment.
Hello,
If people are interested in some background, I started off with this post:
https://mps-support.jetbrains.com/hc/en-us/community/posts/115000709004-Don-t-know-how-to-proceed-with-Generator?page=1#community_comment_115000603324
Some updates:
This leads to the following generated code [Step 0 generation]
1. you need to iterate over a collection of distinct nodes in the LOOP, i.e. node.children.distinct
2. the same as above
3. your enum is a template, so it will only be generated into your code, if there's a rule that gets activated during generation. A conditional root mapping rule needs to be present in your mapping configuration that will actually ensure generation of your enum
Inspecting the transient models comes very handy when debugging generator issues - https://confluence.jetbrains.com/display/MPSD20172/Generator+cookbook#Generatorcookbook-CanIdebugthegenerationprocess?
Hello Sir,
Thank you for your reply.
I have been trying to get questions 1 and 2 above to work for some time without success.
What is have is a Workflow composed of many Steps. Each Step has one Person and one Action. Each Person has a name(string).
I need to iterate over Steps that have Persons with unique names.
My parent node is Workflow so when I do
node.steps.distinct does not help me.
I think it requires a more sophisticated query which I am not able to figure out. DO you have any ideas?
UPDATE_1:
I tried this:
But I get an error: type: list<string> is not a subtype of sequence<node>
Then I misunderstood your language. Maybe you can help me understand it better. How do the Customer, Chef, Person concepts look like? Do they hold any properties or children? Are two customers (step 1 and step 4) the same and should they be generated into a single Java class? If so, why do you actually allow multiple Customer nodes in your model?
Vaclav
Hello SIr,
Actually I modified my language some time back. It looks like so:
It seemed more like I was using only the Person concept and Customer, Chef, etc. were just instances of that concept...
So right now there is only a Person concept which has a property 'name' which can be set to Customer, Chef etc. Each WorkflowStep consists of a Person and an Action.
I need to loop over all the WorkflowSteps and generate fields like so:
public Chef chef;
public Customer customer;
public Waiter waiter;
Right now my code generates 2 Customer fields because there are 2 WorkflowSteps with Persons with name 'Customer'. I need to tell the generator to create fields from each of the WorkflowSteps only if the Persons in them have unique names.
Does that help Sir?
In that case your query should be perhaps something like: node.steps.where{person -> person.previous-siblings.all{it -> it.name :ne: person.name}}
Your solution is, however, vulnerable to typing mistakes - customer and cutsomer will be treated as different entities. I guess a solution with pre-defined nodes of the Person concept declared in an accessory model would be more appropriate. You can take inspiration from how Color is defined for Shapes in the Shapes tutorial - https://confluence.jetbrains.com/display/MPSD20172/Shapes+-+an+introductory+MPS+tutorial
Vaclav
Hello Sir,
I wasn't able to make the query work so I followed the approach of the Shapes tutorial and have created pre-defined nodes in an accessory model.
I have created a new post here with the present state of the project:
https://mps-support.jetbrains.com/hc/en-us/community/posts/115000728224-Dynamically-generating-methods-within-class