Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Generating code from within DSL Editor
Generating code from within DSL Editor [message #554122] Fri, 20 August 2010 09:04 Go to next message
Stefan Missing name is currently offline Stefan Missing nameFriend
Messages: 13
Registered: May 2010
Junior Member
Hi,

with Xtext 0.7.2 it was possible to run the code generator from within the generated DSL editor as described here. Since this example uses MWE, it seems not easily applicable to Xtext 1.0 and MWE2. I tried to convert it best as I could and came up with the following:

module workflow.Generator

import org.eclipse.emf.mwe.utils.*

Workflow{
	component = @MydslGenerator{}
}


However, this piece of code throws the following warning and I do not know how to correct it.

ERROR Mwe2Launcher       - Problems instantiating module workflow.Generator: Cannot resolve proxy: file:/C:/[...]/mydsl.generator/bin/workflow/MydslGenerator.mwe2#xtextLink_:://@root/@assignment.2/@value/@assignment.2/@value/@assignment.2/@value::http://www.eclipse.org/xtext/common/mwe2/Mwe2«Referrable«0::/1


Any help would be greatly appreciated.

Thanks
Stefan
Re: Generating code from within DSL Editor [message #554127 is a reply to message #554122] Fri, 20 August 2010 09:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

zhis is still possible.

the easiest way to try this is to activate the generation of a new project wizard for your dsl in your dsls mwe2

fragment = projectWizard.SimpleProjectWizardFragment {
			 		generatorProjectName = "${projectName}.generator" 
					modelFileExtension = file.extensions
			 }


you may have to merge .ui projects plugin.xml and plugin.xml_gen

then you should be able to create a new project in your runtime with a workflow that calls the generator already contained.

Is there something special about the workflow you try to call?

Regards
Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 20 August 2010 09:35]

Report message to a moderator

Re: Generating code from within DSL Editor [message #554131 is a reply to message #554122] Fri, 20 August 2010 09:25 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

do you want to start the generator manually (executing a workflow file
in the runtime workspace) or do you want to start invoke the mwe2 file
programmatically (from java code within the running eclipse)

In the first case, activate the simple project wizard fragment in the
generator for your language infrastructure. In the project created by
the wizard you will find a workflow file that executes the workflow from
the generator project of your language.

In the second case, it is not advisable to do so at all, as the
standalone setups may mess up your running environment. It is better to
use the Xpand facade directly, e.g. via a builder participant.
The domain model example shipped with Xtext should contain some sample
code showing how to do that.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Generating code from within DSL Editor [message #554143 is a reply to message #554122] Fri, 20 August 2010 10:02 Go to previous messageGo to next message
Stefan Missing name is currently offline Stefan Missing nameFriend
Messages: 13
Registered: May 2010
Junior Member
Thank you both.
There is nothing special about the workflow I'm trying to call, but I figured it would be more convenient to forego the copying of my model from the runtime instance into the generator project.
The generator shall be started manually, not programmatically.

I executed the GenerateMydsl workflow with the projectWizard fragment as you said. From what you're saying I deduce that I now should be able to create a new project with said wizard in my runtime instance. But which wizard do I have to run? There does not seem to be a new one in the wizard overview, at least I cannot find it.

Stefan

[Updated on: Fri, 20 August 2010 10:04]

Report message to a moderator

Re: Generating code from within DSL Editor [message #554146 is a reply to message #554143] Fri, 20 August 2010 10:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you find the wizard under

File -> New -> Xtext -> MyDsl Project

but as i said you may have to merge stuff from plugin.xml_gen to plugin.xml (in the .ui project) since Xtext cannot merge plugin xmls.

   <extension
         point="org.eclipse.ui.newWizards">
      <wizard
            category="org.eclipse.xtext.projectwiz"
            class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.xtext.example.mydsl.ui.wizard.MyDslNewProjectWizard"
            icon="icons/editor.gif"
            id="org.xtext.example.mydsl.ui.wizard.MyDslNewProjectWizard"
            name="MyDsl Project"
            project="true">
      </wizard>
   </extension>


Regards
Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Generating code from within DSL Editor [message #554150 is a reply to message #554143] Fri, 20 August 2010 10:10 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
As Christian said, first compare the plugin.xml and plugin.xml_gen in
the ui-project. Most probably the project wizard extension point has to
be merged into the plugin.xml.

After that, the Xtext-category in the runtime workspace's "New" dialog
should contain a <YourDsl>Project.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Generating code from within DSL Editor [message #554160 is a reply to message #554122] Fri, 20 August 2010 11:24 Go to previous messageGo to next message
Stefan Missing name is currently offline Stefan Missing nameFriend
Messages: 13
Registered: May 2010
Junior Member
Thanks again.
I copied the newWizard extension into the plugin.xml and could then create a MydslProject via the wizard. It gave me the following, which looks quite similar to my own try.

module Generator

var targetDir = "src-gen"
var modelPath = "src/model"

Workflow {
	component = @workflow.MydslGenerator auto-inject {}
}



Adding a couple of dependencies got me rid of most of the errors it produced, but now I fear I am stuck where I was before. Eclipse tells me:

0    [main] ERROR org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher  - Problems instantiating module Generator: Cannot resolve proxy: file:/C:/[...]/mydsl.generator/bin/workflow/MydslGenerator.mwe2#xtextLink_:://@root/@assignment.2/@value/@assignment.2/@value/@assignment.2/@value::http://www.eclipse.org/xtext/common/mwe2/Mwe2<Referrable<0::/1


Full error log, in case it is helpful:
0    [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Problems instantiating module Generator: Cannot resolve proxy: file:/C:/[...]<a href="/mydsl.generator/bin/workflow/MydslGenerator.mwe2#xtextLink_:://@root/@assignment.2/@value/@assignment.2/@value/@assignment.2/@value::http://www.eclipse.org/xtext/common/mwe2/Mwe2«Referrable«0::/1" target="_blank"> /mydsl.generator/bin/workflow/MydslGenerator.mwe2#xtextLink_ :://@root/@assignment.2/@value/@assignment.2/@value/@assignm ent.2/@value::http://www.eclipse.org/xtext/common/mwe2/Mwe2
java.lang.RuntimeException: Problems instantiating module Generator: Cannot resolve proxy: file:/C:/[...]/mydsl.generator/bin/workflow/MydslGenerator.mwe2#xtextLink_:://@root/@assignment.2/@value/@assignment.2/@value/@assignment.2/@value::http://www.eclipse.org/xtext/common/mwe2/Mwe2<Referrable<0::/1
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
Caused by: java.lang.IllegalStateException: Cannot resolve proxy: file:/C:/[...]/mydsl.generator/bin/workflow/MydslGenerator.mwe2#xtextLink_:://@root/@assignment.2/@value/@assignment.2/@value/@assignment.2/@value::http://www.eclipse.org/xtext/common/mwe2/Mwe2<Referrable<0::/1
	at org.eclipse.xtext.common.types.util.JavaReflectAccess.getRawType(JavaReflectAccess.java:88)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.create(Mwe2ExecutionEngine.java:135)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:92)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:259)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:126)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:102)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:259)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:126)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:102)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:259)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:126)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:102)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:259)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:69)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:259)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:89)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:259)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalApplyAssignments(Mwe2ExecutionEngine.java:126)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:102)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:259)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.inCase(Mwe2ExecutionEngine.java:69)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:259)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.internalSwitch(Mwe2ExecutionEngine.java:56)
	at org.eclipse.emf.mwe2.language.factory.Mwe2ExecutionEngine.create(Mwe2ExecutionEngine.java:52)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:71)
	... 3 more


Stefan

[Updated on: Fri, 20 August 2010 11:29]

Report message to a moderator

Re: Generating code from within DSL Editor [message #554163 is a reply to message #554160] Fri, 20 August 2010 11:33 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

have you tried invoking the workflow (in the runtime project) on an
unmodified (apart form the wizard fragment) Xtext poject?

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Generating code from within DSL Editor [message #554167 is a reply to message #554122] Fri, 20 August 2010 11:55 Go to previous messageGo to next message
Stefan Missing name is currently offline Stefan Missing nameFriend
Messages: 13
Registered: May 2010
Junior Member
Unmodified projects do work. I wondered why I didn't have to add any further dependencies as my project required me to do and took a closer look at my workflow again.
I have to apologize for saying there is nothing special about it. It uses code beautifiers as postprocessors and because I used them for a long time before they did not strike me as particularly unusual. If I comment them out, it works fine. But how can I integrate the beautifiers?

Stefan
Re: Generating code from within DSL Editor [message #554229 is a reply to message #554167] Fri, 20 August 2010 15:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi, is the Beautifier class on the classpath of the project the model file is within / you start the generator from?

Does it work at all? e.g. when starting the generator directly in the generator project?

Regards
Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Generating code from within DSL Editor [message #554778 is a reply to message #554122] Tue, 24 August 2010 12:02 Go to previous messageGo to next message
Stefan Missing name is currently offline Stefan Missing nameFriend
Messages: 13
Registered: May 2010
Junior Member
I am using these two beautifiers:

postprocessor = org.eclipse.xpand2.output.JavaBeautifier {}
			postprocessor = org.fornax.utilities.formatter.xml.XmlFormatter {}


The xml formatter is a referenced library. The java beautifier is known to xtext out of the box (if I remember correctly).

Both work perfectly well when the generator is started directly inside the generator project.

Stefan
Re: Generating code from within DSL Editor [message #554797 is a reply to message #554778] Tue, 24 August 2010 12:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

is org.fornax.utilities.formatter.xml.XmlFormatter on the classpath of the project in the runtime app?

If i write a own beatauifier - put it into a third party plugin - and use it like you use XmlFormatter i get the same error you get until i add my beatifiers plugin to the plugin dependencies of the model project in the runtime application.

Regards
Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 24 August 2010 12:39]

Report message to a moderator

Re: Generating code from within DSL Editor [message #554808 is a reply to message #554122] Tue, 24 August 2010 13:03 Go to previous message
Stefan Missing name is currently offline Stefan Missing nameFriend
Messages: 13
Registered: May 2010
Junior Member
I put it on the classpath and now the xml formatter works. The java formatter required some more dependencies (org.eclipse.jface.text, org.eclipse.core.runtime, org.eclipse.jdt.core), but is running, too.

Thank you very much!
Previous Topic:conflict between 'literals' and qualifiednames
Next Topic:Formatting and linewrap
Goto Forum:
  


Current Time: Tue Apr 23 13:35:13 GMT 2024

Powered by FUDForum. Page generated in 0.03418 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top