How to use xtext and xpand togheter - eclipse

I have a rather silly question. I am using xtext to define a simple dsl and Xpand to generate code.
Now I want to use xpand to read my dsl models and generate code. How can i do that?
I read lot of tutorials saying that I can simple do that by creating a new xtext project from the wizard. Then, among others, the following project will be created:
org.xtext.example.domainmodel.generator.
And inside, the generator looks like this:
src
model (place the dsl model)
templates (place the template for the code generator)
workflow (workflow file)
Then i simple run the workflow and generate the code from the dsl file. That s straightforwards and easy.
My problem is that when I create a new xtext project I dont get the org.xtext.example.domainmodel.generator. project. I only have the following four:
org.xtext.example.domainmodel
org.xtext.example.domainmodel.sdk
org.xtext.example.domainmodel.tests
org.xtext.example.domainmodel.ui
So how can i produce the org.xtext.example.domainmodel.generator file???

Which tutorials do you mean? (links please) And do they really talk about a generator project? Talking about the package org.xtext.example.domainmodel.generator inside the org.xtext.example.domainmodel project is the usual thing.

Probably not relevant to the original person who asked this :) but I had a similar problem and the reason was that in my grammar extended xbase.
When extending xbase building the mwe2 skips the generator stub generation and uses the xbase code generation which is generated instead (the antlr parser, serializer etc.)

Related

XText - Multiple grammars and example web editor

I have an XText project setup with multiple grammars and am able to edit each grammar with cross-linking within the IDE generated by the mwe2 workflow. When I run the example web editor, the first grammar defined in the mwe2 workflow functions correctly.
If I change the the generated index.html to use one of the alternate grammar extensions the editor no longer functions, and I get an error message that looks like:
Xtext service 'occurrences' failed: Unable to identify the Xtext
language for resource 3c05cdd1.ed
I'd like to understand what is wrong in order to better understand how I can begin minimal integration of editors for the grammars into our existing console.
Thanks!
Pierre Padovani
P.S. I've posted this same question on the Eclipse Community Forums, but my post seems to be stuck in a moderator queue.
Having found the thread which #ppadovani mentions, it seems that the only necessary change is to ignore all the generated Servlet.xtend files except the one whose grammar is working.
In that one which works, it is necessary to initialise run the WebSetup for the other languages.
override init() {
super.init()
// call createInjectorAndDoEMFRegistration for each WebSetup
new DerivedDslWebSetup().createInjectorAndDoEMFRegistration
// keep the rest as-is
val injector = new CoreDslWebSetup().createInjectorAndDoEMFRegistration()
disposableRegistry = injector.getInstance(DisposableRegistry)
}
Reference: https://www.eclipse.org/forums/index.php?t=msg&th=1096166&goto=1798287&#msg_1798287

fUML, Papyrus and Basic Operations

We aim to execute fUML specifications written in Papyrus using the fUML reference implementation. This has not been challenging since an UML model containing a single Class diagram and one or more Activity Diagrams can be directly executed by calling the fUML constructor:
new Fuml(File);
However, it is difficult to specify complex behaviors without basic Integer operations. For example, 'equals', 'greater'...
I am aware that there is some library of such functions that can be selected using OpaqueBehaviors. Therefore, my question is: where and how can those such "basic operations" be found?
Sorry, this question was just pointed out to me recently. But, in case you haven't figured it out yet, I do have an answer for you.
The library you are looking for is the Foundational Model Library, which contains packages such as IntegerFunctions, BooleanFunctions, etc. The normative fUML specification includes a standard XMI file for this library (at http://www.omg.org/spec/FUML/20121019/fUML_Library.xmi, for fUML 1.1). However, to use the library in Papyrus, you need an Eclipse .uml version.
If you want, you can convert the normative XMI yourself: Download the file and open it in the Eclipse UML Editor (not Papyrus). Select File > Save As and save the file with a .uml extension (fUML_Library.uml). You should then be able to import this .uml file into Papyrus and reference the functions in it from your activity models. As long as you maintain the normative element IDs from the original XMI file, the reference implementation will know that these are standard library functions, for which it has built-in implementations.
However, there is actually a .uml version of this library already available for Papyrus. It is included with the additional Moka Model Execution component for Papyrus. If you install this component, then the fUML model library becomes available as a "registered library" that you can import into your model and use as above.
Note that Moka also includes an fUML execution engine that you can use to execute activity models directly within Papyrus (see https://wiki.eclipse.org/Papyrus/UserGuide/ModelExecution). However, any models created in Papyrus that can be executed with Moka can also be executed externally from Papyrus using the reference implementation, just as you have done before.

xtend2 code generation with ecore meta-model

I created an ecore-Metamodel, a genmodel and a corresponding model.
Now I want to generate Code from this.
I found this post and wanted to implement it. I get no errors and so on, but how do I bring the CodeGenerator to generate the wanted output in a File like 'test.txt' (taken that example from the referenced question)?
Do I require a workflow file (mwe2) or do I miss something?
I only needed to run the application as Java and the code worked. I don't need any workflow or mwe2!
But appearently I still cant create the files like I can with a Generator.
I just can use a simple filewriter.

EMF namespace URI/prefix is null

I have to use EMF to create a EMF Generator Model from an existing ecore diagram, but it gives me namespace errors when trying to do so.
Here is is the screenshot of the two errors.
I think the error might be in the ecore file (XML), but I have no idea what to write, as I have only been using the GUI tool to create the ecore model...
My ecorediag file is here, and my ecore file is here.
I have bad experience with EMF, as it has never worked smoothly without any hiccups, and this is yet another problem, however, I am forced to use it.
I tried Googling the errors, but only 9 and 8 hits were returned, most of which did not help solve the problem.
What do I need to edit in the ecorediag or ecore file to be able to generate my EMF Generator Model?
For the record, I am using Eclipse 4.2.2.
change nsURI in to "http: ///ecore_file_name.ecore" and nsPrefix into "ecore_file_name" it woks great
The solution I found was to rewrite the whole project from scratch.
The approach was to carefully generate the genmodel for every change I made to the ecore file (adding/renaming/removing attributes/classes) to make sure nothing bad happened between any alterations to the model. By following this approach, you will be able to isolate the problem if something goes wrong.
However, I am still looking for another solution/answer other than rewriting everything.

Refactoring library of eclipse

It is possible to implement the refactoring by using Eclipse library (JDT,LTK) without involving of the wizards. I would like to get benefit from refactoring feature of eclipse but I wan't to provide input for refactoring by other ways (that is not entering in the wizard) such as reading from file, etc.
If possible , Please suggest me how
You can find a sample in the JDT's SurroundWithTryCatchAction (eliding a lot of detail):
SurroundWithTryCatchRefactoring refactoring= SurroundWithTryCatchRefactoring.create(cu, selection);
Change change= refactoring.createChange(new NullProgressMonitor());
PerformChangeOperation op= new PerformChangeOperation(change);
WorkbenchRunnableAdapter adapter= new WorkbenchRunnableAdapter(op);
PlatformUI.getWorkbench().getProgressService().runInUI(
new BusyIndicatorRunnableContext(), adapter, adapter.getSchedulingRule());
The refactoring is set up entirely non-interactively through the create-helper.