How to create concepts or extend existing concepts programmatically ? Follow
Dear all,
I have a question on programmatic creation of Concepts. Right now I am able to iterate over a language concepts using the simple technique shown above.
But I have not found a way to add properties and concepts that seems to work despite reading this forum a lot. May be too old and deprecated code, or me not a good programmer enough.
Can anyone give me some hint on how to add a concept and properties, children, .. ?
My version is MPS 2018.3.4
Thanks in advance.
SLanguage lang = language/simpleLanguage/;
Iterable<SAbstractConcept> concepts = lang.getConcepts();
foreach concept in concepts {
message info "Name of concept : " + concept.getName(), <no project>, <no throwable>;
Collection<SProperty> properties = concept.getProperties();
foreach prop in properties {
message info "Name of property : " + prop.getName(), <no project>, <no throwable>;
message info "Type de property : " + prop.getType(), <no project>, <no throwable>;
}
}
Please sign in to leave a comment.
Hi all,
here is my previous attempt. Iterating over the concepts to retrieve information is OK.
Then I probably have an error on the cast : Language language = ((Language) lang);
What is the correct way to do the concept creation ?
Thanks in advance.
SLanguage lang = language/simpleLanguage/;
Iterable<SAbstractConcept> concepts = lang.getConcepts();
foreach concept in concepts {
message info "Name of concept : " + concept.getName(), <no project>, <no throwable>;
}
Language language = ((Language) lang);
model myModel = LanguageAspect.STRUCTURE.get(language);
node<ConceptDeclaration> nodeDecl = new node<ConceptDeclaration>();
nodeDecl.conceptId = "589765345";
nodeDecl.name = "CNode";
nodeDecl.rootable = true;
myModel.add root(nodeDecl);