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:
  • 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!
Comment actions Permalink
You can:
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.
Comment actions Permalink
Thanks for your quick reply, Alex!

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!
Comment actions Permalink
I tried the following approach:
  • one mapping configuration called "branchingConfiguration" is responsible for creating two classes (Class1 & Class2) for each instance of concept A and copying all the child elements (instances of concept B) there using $COPY_SRC$ marco.
  • two other mapping configurations "step1" & "step2" contains reduction rules for concept B with conditions: containing root is Class1/Class2 in accordance
  • generator priorities were set to execute "branchingConfiguration", then "step1" and then "step2"

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.

Please sign in to leave a comment.