Anonymous class generation

Hello everybody!

I start working with MPS not long ago, so I still have some difficulties.

The source code ( in model ):

  • IInteface i = new IInterface() {// some code //};

Should be translated into:

  • IInteface i = new IInterface#some unique extension#();

and (in another file):

  • class IInterface#some unique extension# implements IInterface {// some code //}

So my question is: how make this unique class names to be equivalent? (i've found "genContext.unique name from...", but its not enough)

Thank you for your attention!
1 comment
Hi,

I think, the feature you are searching for is mapping labels (see the tutorial and the wiki).

When a generator applies a reduction rule to a node of the source model, it can memorize the node it generated for it. It's like a HashMap "from source model node to generated node". You can look up the generated nodes by using "genContext.get output LABELNAME for (SOURCENODE)".

So in your case:
  1. Generate the IInterface class with a root mapping rule (using "genContext.unique name from..." if you want)
  2. Generate the anonymous class instantiation using a reference macro, looking up the generated class in the mapping label.

Cheers
Yann
0

Please sign in to leave a comment.