Protected Code Regions for Manually Written Code

As far as I can tell, MPS doesn't support in-line protected code regions for manual editing in MPS.  This feature is supported in Xpand and OMG's MOF MTL.  (http://www.openarchitectureware.org/pub/documentation/4.3.1/html/contents/core_reference.html)

Is there any way I can similarly combine manually written code with generated code in MPS?  The reason I need to do this is while in the process of migrating existing code into MPS, it makes it much more feasible for me to move to MPS iteratively.

Thanks!

7 comments
Comment actions Permalink

Hi!

No, protected regions are not supported with MPS.

Instead you can simply include target language (BaseLanguage/java) expressions anywhere inside your high-level domain specific model and then corresponding java code will be inserted into appropriate place during the code generation.

0
Comment actions Permalink

Hi Alex, if I'm understanding you correctly, you're talking about manually entering in the Java code inside the generator from within MPS.  If so, do I correctly understand that there is no way to import or paste existing text-based code, and that I'd have to manually type it in as in the tutorial?

Thanks,

Jeff

0
Comment actions Permalink

Hi!

if I'm understanding you correctly, you're talking about manually entering in the Java code inside the generator from within MPS.

It depends on the situation you have. If you need to generate some java code which is similar for any input modes then you can create it in generator. In case you have to customize code generated for the particular domain model (this situation is actually addressed by "protected regions" feature) then you can type corresponding java code directly in domain model (in some specific child element) and tune generator to inject this code in code into a corresponding place in an output low-level model.

Concerning the possibility to import existing code to MPS - we have following options:

- you can import existing java classes by pointing to the source folder and then MPS will create corresponding MPS models from it

- or you can copy java code and paste it into MPS

0
Comment actions Permalink

Hi Alex,

Thanks for the response.  I think we're having a problem understanding each other, but to clarify, I'm talking about working iteratively to migrate existing Java code into MPS so I can begin modeling an existing project.  I can do this very effectively using the Eclipse/Acceleo/MTL/OCL tooling, but MPS appears much more powerful.

ashatalin wrote:

In case you have to customize code generated for the particular domain model (this situation is actually addressed by "protected regions" feature) then you can type corresponding java code directly in domain model (in some specific child element) and tune generator to inject this code in code into a corresponding place in an output low-level model.


Protected regions are precisely what I'm asking about, but I see no mention of this feature in the documentation. Would you be able to give me an example of how to do this or alternately point me to where this feature is documented?

Concerning the possibility to import existing code to MPS - we have following options:

- you can import existing java classes by pointing to the source folder and then MPS will create corresponding MPS models from it

- or you can copy java code and paste it into MPS

First, let's clarify where it is valid to paste Java code into MPS.  I attempted to do so using the calculator example in the generator for the "Calculator" concept.  When I pasted a simple single line of Java "int a=1;" into the main() method of the "CalculatorImpl()" generator, right after "new CalculatorImpl();" MPS doesn't parse this, and it shows up in red.  If I type the code by hand instead of pasting, then it works fine. Are you talking about MPS 2.0?  I'm using 1.5.

Thanks for any help!

0
Comment actions Permalink

Hi!

Thanks for the response.  I think we're having a problem understanding each other, but to clarify, I'm talking about working iteratively to migrate existing Java code into MPS so I can begin modeling an existing project.  I can do this very effectively using the Eclipse/Acceleo/MTL/OCL tooling, but MPS appears much more powerful.

With MPS we propose following migration path: you can simply start writing new code in MPS having all legacy stuff in java from the very beginning. Just to clarify - in this case you'll be able to use existing java code in any MPS-generated code just like any other external library. Later you can decide to move whole project to MPS. For this purposes we have special action "Get .. content from source" which is able to convert all exiting java code into MPS models.

Protected regions are precisely what I'm asking about, but I see no mention of this feature in the documentation. Would you be able to give me an example of how to do this or alternately point me to where this feature is documented?

We do not have protected regions in MPS, but I know about this feature and I'm trying to point out similar functionality in MPS. May be you can write here a simple example (use case) where you need these regions in MPS and then I'll try to explain how to implement this use case with current MPS functionality?

First, let's clarify where it is valid to paste Java code into MPS.  I attempted to do so using the calculator example in the generator for the "Calculator" concept.  When I pasted a simple single line of Java "int a=1;" into the main() method of the "CalculatorImpl()" generator, right after "new CalculatorImpl();" MPS doesn't parse this, and it shows up in red.  If I type the code by hand instead of pasting, then it works fine. Are you talking about MPS 2.0?  I'm using 1.5.

Yes, I were talking about MPS 2.0, sorry. One more thing concerning paste from java - currently in MPS 2.0 we have simple paste action which works as you described above and in addition we have special pop-up menu action available in MPS editors called "Paste as Java ...", so you have to use this special paste functionality.

0
Comment actions Permalink
Hi Alex, thanks very much for the ongoing support.  After playing more with MPS and looking again at the tutorials, I now understand what you said about the model including the manually written code.

It is clear from the tutorials how to add a simple base language expression.  What I want to do is add a list of statements that I can append to a method that's in the generator.

When I add an individual statement to the concept's children, I can successfully add a single statement (multiplicity 1) to my model and successfully generate a single statement with the $COPY_SRC$ macro.

Incidentally, When I earlier tried to add the base language StatementList as a field, I got a parse error somewhere.  I'll assume this type isn't appropriate for this use.

When I tried to change the multiplicity to (0..n), I change the generator to $LOOP$ on the statements property.  The generator correctly loops on several statements.  However, the $COPY_SRC$ macro is unavailable to reference each statement.  Is this an MPS bug or am I doing something wrong?

Thanks!
Jeff
0
Comment actions Permalink
Hi!

You can use $COPY_SRCL$ macro - this one is similar to $COPY_SRC$ but should be applied for list of nodes.

In addition, if you'd like to place several statement somewhere in your model then  StatementList or BlockStatement concepts can be useful.
0

Please sign in to leave a comment.