Using OpenAPI to add extends or implements

Hi,

Could someone please help me with the following code? I'm trying to programmatically add super-classes and interfaces to a concept.

I'm following the code from https://mps-support.jetbrains.com/hc/en-us/community/posts/206614395-How-to-add-create-a-new-Concept-using-the-Open-API-

Specifically the code:

node<InterfaceConceptReference> namedRef = new node<InterfaceConceptReference>();
namedRef.intfc.set(concept/INamedConcept/.asNode);
node<ConceptDeclaration> test = currNode : ConceptDeclaration;
namedRef.virtualPackage = currNode.virtualPackage;
test.implements.add(namedRef);

Note that currNode is of type node<>, as it can be an interface or concept itself.

Thank you for any help you can provide!

 

1
4 comments

Could you please describe the exact problem that you are having?

1

Pardon me, I wasn't clear with my first post.

I'm executing the above code as part of a plugin action, performed on a model. In this use case, I'm executing the code on a language's Structure model, in order to programmatically import Ecore meta-models.

I expect the code to modify the concept represented by 'test' to have INamedConcept as an interface. However, nothing happens, and no errors are generated.

If the above code is incorrect, how would I programmatically add an interface to a concept?

Thank you.

1

Yes, the code is correct and works for me in the Console. You can try running the code from the Console, as well, to see, whether the issue is in the code or in the context of the action (e.g. different or read-only model).

Vaclav

 

1

Ah, I've solved my issue, which was something unrelated. But thank you for showing me how the console works! That's very useful. And many thanks for the speedy responses.

My issue (as a warning to others) was that I was placing the concept nodes into a map before adding the INamedConcept. Then, I queried the map using a non-existent key.

My assumption was that any operations on this returned value (null) would throw an error in some way.The take-away is therefore to practice defensive programming and throw an error if null happens to be returned.

1

Please sign in to leave a comment.