0

I've a set of concepts that represent types of entities Hrrr.

Sample concepts: Loop with children loopCount: IntegerProperty[1] HttpRequest with children url: StringProperty[1], hostName: StringProperty[1]

Both concepts extend AbstractTestElement concept (it defines common properties like name, comment, etc).

I want Loop and HttpRequest to be generated to baseLanguage as follows:

Loop:

Loop e = new Loop();
e.setProperty(new IntegerProperty("loopCount", node.loopCount));

HttpRequest:

HttpRequest e = new HttpRequest();
e.setProperty(new StringProperty("url", node.url));
e.setProperty(new IntegerProperty("host", node.hostName));

What I want is to have some common generator template that covers this common logic for setProperty so it is not repeated for different kinds of test elements. Well, there are properties that require specific-to-test-element treatment, however there are often cases when properties are one-to-one translated, thus

Here's the question: how can I attach metadata to the Loop/HttpRequest concept configuration? What is MPS-idiomatic way of doing that?

1) While I could use "names of properties" as names put into the new XXXProperty, however ideally I would use HttpRequest.HOST_PROPERTY_NAME kind of references, thus "names of properties" is not sufficient.

2) I might probably invent annotations and annotate properties of my concepts, it looks like MPS itself does not use that approach.

3) (ab)using concept's behaviors to return <quotation new StringProperty("url", node.url) > looks even more awkward.

Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
Vladimir Sitnikov
  • 1,467
  • 12
  • 31

1 Answers1

0

I would rather not use 2. and 3. because both approaches add generator behavior into aspects of your languages which aren't aware of the fact how things will be generated. It basically tight couples you structure with your generator.

If you go for 1, you can still use that static class approach. By creating a new rootnode in the generator which is a java class and contains all your fields. And then have generic generator template that reduces the IntegerProperty and so on ... If they have a common super concept it should be fairly easy to do. You just have to make sure that the property is generated before the containing concept. That way you can still access the role of it in the parent and use that information to generate the field access.

Kolja
  • 2,307
  • 15
  • 23