Identifier instead of INamedConcept?

Hi,

i m a newbe to MPS - just read the lwc11 documentation (which is by the way very useful). However i run into to questions..

(1) How can i change the INamedConcept so that only identifiers are allowed? It should be forbidden to use spaces as a concept name in my whole project. How can i do this?

(2) I created an Entity Reference concept in my project with an editor like: "    refto <Entity_Here> <Name>  [ ]    "  One can write:    refto Order myorder     I added an intention "Toggle isVector"

    in order to toggle my isVector Flag. The editor will display [] additionally, or nothing if isVector is false.  Is it also possible to do that without intention? i.e. just by typing [] in the editor or leaving in blank?

Any help appreciated,

Dan

3 comments
Comment actions Permalink

Hi Dan,

1) expecting that you are using INamedConcept to have {name} displayed as node-name in the project view: just implement your own concept-property (lets say yourname) and constrain it with your allowed-identifier (f.i. using "Constrained Data Type"). Then create a new ConceptBehavior and overwrite the (non-static) method getPresentation() (put cursor on field for method-name and choose "getPresentation()" from the code-completion shown behind overwrites in inspector-view) voila.

first.PNG

2) you can create a so called "side transform actions" to achieve that. Have a look f.i. at jetbrains.mps.baseLanguage.actions.dotExpression

Regards, Mirko



Attachment(s):
first.PNG
1
Comment actions Permalink

Hi Mirko,

thanks a lot. Just for the sake of understanding, i tried additonally something different. I created an OfNamedConcept interface which extends the INamedConcept. In my own OfNamedConcept i added a property constraint for the name ( the isValid ) which checks with a regular expression..

This is also a suitable solution, isn t it?

The side transform worked ... thanks ….. :  )

Best,

Dan

0
Comment actions Permalink

Hi Dan,

daniel_Austria schrieb:

thanks a lot. Just for the sake of understanding, i tried additonally something different. I created an OfNamedConcept interface which extends the INamedConcept. In my own OfNamedConcept i added a property constraint for the name ( the isValid ) which checks with a regular expression ..


Also a good solution!

I also tried to create an interface - that overwrites the getPresentation()-method, but without effect (it was'nt called) to the implementing concepts :-(

Anyway, the only disadvantage of your solution i can see, is that you have to implement your identifier-rules by your own (using baseLang). Creating a new property would make it possible to use the "Constrained Data Type", what would make your rule a little more clear...

The advantage is clearly, that you use INamedConcept and that you do not have to implement getPresentation in every implementing concept (or you would have to extend one concrete concept that implements getPresentation ... ugly!)

So, i would prefer your solution!

Regards,

Mirko

0

Please sign in to leave a comment.