Open FAMILIAR-project opened 7 years ago
To my knowledge, there's no clearer way of doing that :( In a way, your helper "hides" this complexity from the student so I'd say it's fine.
Although the names and signatures of these methods are imho bad, what they do is quite clear: the first one registers all the tools generated by Xtext (parser, etc.), the second one loads a model from disk (using the tools registered the line before), and the last one returns a well-typed root. I cannot come up with a better explanation for students :)
Isn't the file extension registered somewhere, and the xtext parser called automatically with the getResource
?
If you're running in the Eclipse context (eg. a contextual menu somewhere in the UI), the registration is done transparently using extension points.
If you're in standalone mode (which, I guess, is the case most of the time with students), you have to do it by yourself.
OK. In my case, I try to avoid writing any standalone code from now on. It's less confusing to always assume there is Eclipse running... :p
And for students I think that it's not that bad, since the goal for them is to develop tools for their language, therefore it makes sense to integrate these tools in the final IDE of their language, I think? And it avoids the first potentially-confusing line of the example above.
Worst case, they can still test their code with a "Junit plugin test" run configuration in headless mode, which does not require starting the UI of an eclipse instance.
@FAMILIAR-project , If by clearer you mean fewer lines of code while adhering to Xtext good practices, then you're doing it just right. However, I would briefly explain what is an injection to the EMF technical space and why we need EMF registration.
@ebousse , the registration happens automatically and transparently only if the plugin is installed, registered, then started (thanks to the "org.eclipse.emf.ecore.generated_package" extension point). As long as you're in the same workspace, this task should be performed manually. And yes, you're totally right, testing their code using Junit plugin test in headless mode could, in some test cases, do the trick.
Thanks for your answers! Another possible technique is to use ParseHelper (see https://www.eclipse.org/Xtext/documentation/103_domainmodelnextsteps.html#tutorial-unit-tests) but that's not "better" in terms of usability/learnability.
I am a bit surprised Xtext does not generate a ready-to-use program for loading models
I won't open a new thread but I have a related question ;) How to open an Ecore metamodel with EcoreTools, typically the metamodel generated by Xtext? http://www.eclipse.org/ecoretools/
I don't remember the easiest way to do that
If you ask how to open it programmatically, I have no clue.
Otherwise, you need to:
http://www.eclipse.org/ecoretools/doc/index.html You have to use the modelling perspective.
The Modeling Project is a facility provided by Sirius which handles models within the scope of a project. What does that mean ? Any model which is in the project is going to be loaded by Sirius behind the scene and its elements will be available in your editors. This mode of usage is designed so that you can work with your models easily, but you might want to have more control. In this case, you can use EcoreTools just by creating Representations Files.
Selecting Viewpoints
Each modeling project has a set of viewpoints which are enabled. This controls what kind of representations you can create on the Ecore models inside the project.
Right clic on the project. Select view point design.
Create a new representation
Hi,
(it is not a feature request, just a technical "question") I am sometimes using Xtext and so students as part of courses/projects. The usual workflow is to write an Xtext grammar, compile it, play with some examples (programs/models) in the generated Eclipse editor. And then of course we want to do something with our programs/models.
For loading programs, I am always writing some helpers function, something like:
It's a bit mysterious to explain to students and I am wondering whether there is no better alternative when starting to write a model transformation.
So what are your hints and best practices?
Thank you!