How to generate two-way output
Let's say I have a root concept A that has children of concept B.
I want to generate two Java classes from concept A. Call them Class1 and Class2. In Class1, I want to reduce each B node to a field declaration. In Class2, I want to reduce each B node to a method.
What would be the best way to do this? I've thought of the following:
Any suggestions? Thanks!
I want to generate two Java classes from concept A. Call them Class1 and Class2. In Class1, I want to reduce each B node to a field declaration. In Class2, I want to reduce each B node to a method.
What would be the best way to do this? I've thought of the following:
- Put two root mapping rules and two reduction rules. Each reduction rule checks whether the B node has an ancestor Class1 or Class2. This doesn't seem to work because the B node is always under root A. Even if this works, it's annoying because you have to put a condition everywhere.
- Use two generators: One generator generates Class1 and has a post-processing script that copies out the original A. The other generator then generates Class2. The problem with this is that I lose the ability to run the generator together, possibly because I have mapping labels, etc.
Any suggestions? Thanks!
Please sign in to leave a comment.
1. Create two root mapping rules mapping concept A instances to Class1 & Class2.
2. In Class1/Class2 use $LOOP$ macro to iterate over child instances of concept B and create fields/methods in accordance.
My situation involves further reducing the child instance of concept B. In the $LOOP$ macro, I would typically have a $COPY_SRC for one of the children of B. I want the $COPY_SRC to have two different outcomes based on Class1/Class2. Is that possible or is there a way to work around it? Thanks!
In general you should be able to merge all mapping configurations into a single one - Reduction rules should be executed on the next "minor" step of MPS generation process right after the step with "branching" rule.