Xtext 1.0.0 and UML (Xpand on top)

Several projects combine textual DSLs with Xtext with UML models and there have been some postings (by Sven, Holger and others) on how to achieve this with earlier versions of Xtext. This is a short sketch on how to do it with the latest version. If you do not now what this is about, have a look at the screenshot on the left: The Xtext grammar references a UML model with an Activity and two classes. This is fully integrated you see that content assist suggest the elements from the UML model.

The biggest difference is the need for IResourceProviders for UML. Xtext comes with a IResourceProvider for EMF models, and this can be used for writing an UML version. I added three new files to the Xtext project: UmlResourceDescriptionManager.java and UMLResourceServiceProviderImpl.java UMLResourceDescription.java . The former two are very simple: UMLResourceServiceProviderImpl.java only binds the .uml extension.

This is a very basic implemenation of a UML Resource Description: It returns all "NamedElements" from the UML model.  The functionality could be extended to different purposes, but this does the job right now.

The grammar of our languages is pretty ssimple. Nothing new compared to earlier releases:

As in the other tutorials, you should copy the relevant-meta-models into your project. However, there's a lot of changes in the work flow. Have a look at this work flow to see how to adapt it to UML:

In the Manifest, the Resource Provider has to be made known through an extension. If you add org.eclipse.uml2.codegen.ecore, org.eclipse.uml2.uml and org.eclipse.xtext.ecore you are ready to go and create and run a grammar references to UML. However, if you want to also use code generation, this is a good time to modify the StandaloneSetup.java class:
package de.itemis.graf;

At this point, you can run the editor, create a UML model and reference the model elements from within your Xtext model.

On top, if you want to process this with Xpand, here is the work flow:

And here an example of a template:

Enjoy combining your DSLs with UML.

8 thoughts on “Xtext 1.0.0 and UML (Xpand on top)

  1. Hi Andreas, thanks for your posting, helped a lot! I've got one problem with usage of an external ecore model in the context of xpand file generation. In standalone mode (running workflow) everything is fine. But within Eclipse the xpand template shows errors. It says: Couldn't find xuml::XModel at the DEFINE statement. Is maybe the additional ecore model not registered correctly in eclipse? Anything else to do here? Thanks Fabian
  2. Sometimes it just helps writing down the problem... I missed to activate the EMF metamodel lookup in the xtend/xpand project configuration. Now working. :)
  3. Hi Andreas! Just had the same problem, but was not aware of your article. I solved it nearly exactly the same, and just after finishing it I found this article. Damn, could have saved me some time, but at least now I really understood it :-) Thanks for your great post! ~Karsten
  4. Thanks for your great post! Without this information, I will switch to another tool ;)
  5. Hi! Great article! However I have a follow-up question: Is it possible to use full qualified names for the imported UML-instances? I am importing a series of packages containing classes with identical names, which obviously does not work. I already tried changing the UMLResourceDescription to use getQualifiedName instead of getName - with the result, that no UML-instances where found anymore! Thanks in advance Thomas
  6. Dear Thomas, changing the UMLResourceDescription is the right track, but not complete. The grammar just takes an "ID" as a reference as it is declared now (umlClass=[umlMM::Class]). You could try adding something like: QualifiedName: ID ('.' ID)*; // you might use ':' instead of '.', depending on what getQualifiedName retursn. to the grammar and then change umlClass=[umlMM::Class] to umlClass=[umlMM::Class|QualifiedName] Good Luck! Andreas
  7. Hi Andreas It's really great post, because I've spent so much time searching the same ! :) I followed the same procedure you explained and at the beginning there were no problems at all. But when I started to use the editor I couldn't get a list of suggestions of NamedElements. When I typed an element from the My.uml model (e.g. references foo), I got error like "Couldn't resolve reference to Class 'foo' ". Do you know what might be the problem ? Thanks again for the post Nikola
  8. Hi Andreas I solved the problem, actually I forgot to enable and disable some fragments of the workflow file. Now it's working as intended by the post. Thanks a lot ! This post saved my life :) Best Nikola

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">