How to add/create a new Concept using the Open API?

Hi folks,

I've read a lot about creating nodes using the Open API (which works very well). Now I need to create a new concept instead of a node. So, is it possible to define a new concept and editor using Java?

Thanks in advance!

Cheers,
Dennis
7 comments
You may take inspiration from the "CreateMissingStub" quick fix:

execute(node)->void { 
  node<ConceptDeclaration> declaration = node : ConceptDeclaration; 
  string name = declaration.name; 
  string virtualPackage = declaration.virtualPackage; 
  node<ConceptDeclaration> stub = declaration.model.new root node(ConceptDeclaration); 
  stub.name = "Stub" + name; 
  stub.virtualPackage = virtualPackage; 
  stub.extends.set(declaration); 
  node<InterfaceConceptReference> ref1 = new node<InterfaceConceptReference>(); 
  ref1.intfc.set(concept/IDontSubstituteByDefault/.asNode); 
  stub.implements.add(ref1); 
  node<InterfaceConceptReference> ref2 = new node<InterfaceConceptReference>(); 
  ref2.intfc.set(concept/IStubForAnotherConcept/.asNode); 
  stub.implements.add(ref2); 
   
  SModel model = declaration/.getModel(); 
  if (model == null) { return; } 
  SModule language = model.getModule(); 
  SModel editorModel = LanguageAspect.EDITOR.get((Language) language); 
  if (editorModel == null) { return; } 
   
  node<ConceptEditorDeclaration> editor = new node<ConceptEditorDeclaration>(); 
  editor.conceptDeclaration.set(stub); 
  editor.virtualPackage = virtualPackage; 
  node<CellModel_Component> component = new node<CellModel_Component>(); 
  component.editorComponent.set(node/ImplementationRemovedInStubMessage/); 
  editor.cellModel.set(component); 
  editorModel.addRootNode(editor); 
}
prettyPrint();
0
node<ConceptEditorDeclaration> editor = new node<ConceptEditorDeclaration>();

I'm not able to import the jetbrains.mps.lang.editor.structure.ConceptEditorDeclaration into my Action. What dependencies and languages do I have to import, in order to make it work?

I tried the following dependencies and languages:

Dependencies:

jetbrains.mps.lang.structure.editor@java_stub
jetbrains.mps.openapi.editor@java_stub
jetbrains.mps.baselanguage.editor

Used Languages:

jetbrains.mps.baselanguage
jetbrains.mps.lang.editor
jetbrains.mps.lang.structure

Unfortunately most of these imports are grayed out, so I figured they are not being used..?
0
j.m.lang.editor.structure is the model that you need to depend on, I believe.
0
Thank you very much! It is working, but the import gives me (out of scope). Why is that?
FYI my action is contained in a Plugin Aspect in my language. Perhaps this has something to do with the issue?
0
I guess you're missing j.m.lang.editor dependency in the surrounding module (solution). Could it be it?

Vaclav
0
Nope, the surrounding module already depends on jetbrains.mps.lang.editor... It's kinda weird, 'cause even so it's working properly.
0
Sorry, I meant the dependencies of the surrounding Language, not Solution.

Yo may also try to add the import by Control/Cmd + R and typing "ConceptEditorDeclaration". This should import both the language and the model dependencies.
0

Please sign in to leave a comment.