Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Code generation from editor(Question from beginner, any help aprreciated)
icon5.gif  Code generation from editor [message #551573] Sat, 07 August 2010 11:10 Go to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Just started with a xtext project and got a problem. I worked through the tutorial (version 1.0). All work fine. Generated an IDE, generated a code generator. But now I tried to invoke code generation from inside the generated IDE. But nothing worked.

I thought, using the generated IDE would allow code generation. But I didn't found any hint in the tutorial or by searching with google for doing that. Ether it is not possible (I can't belief that) or I missed some point.

BTW, I build many compilers during the last couples of years, but now I tried to use a modern IDE.

Bodo
Re: Code generation from editor [message #551577 is a reply to message #551573] Sat, 07 August 2010 12:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hello Bodo,

welcome to Xtext. Of course it its possible to call the/a code generator.

There are basically two Possibilities:

(1)
- Call the generator (/org.xtext.example.mydsl.generator when creating with the wizards defaults) explicitly.
- Therefore open the Language generator workflow (GenerateMyDsl.mwe2) and enable the project wizard fragment
			 fragment = projectWizard.SimpleProjectWizardFragment {
			 		generatorProjectName = "${projectName}.generator" 
					modelFileExtension = file.extensions
			 }


- and regenerate the language
- you may have to merge parts from /org.xtext.example.mydsl/plugin.xml_gen to /org.xtext.example.mydsl/plugin.xml manually (not necessary when you start from a new project)
- when new now start a new eclipse runtime you find a new wizard (file -> new -> project -> Xtext -> Mydsl Project that create a workflow for you that calls the generator.

(2) or you do it with the new Xtext 1.0.0 Builder Infrastructure (see the org.eclipse.xtext.example.domainmodel example project - especially the /org.eclipse.xtext.example.domainmodel.ui/src/org/eclipse/xt ext/example/ui/generator/Generator.java class.

Regards
Christian


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

[Updated on: Sat, 07 August 2010 12:29]

Report message to a moderator

Re: Code generation from editor [message #551580 is a reply to message #551577] Sat, 07 August 2010 13:22 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Hello Christian,

I tried way (1) and, surprise! is worked perfectly.

Thank you very much.

BTW: Should this explanation not belong in the tutorial? Probably I should write a quick start guide for compiler writers Smile

Regards
Bodo
Re: Code generation from editor [message #552071 is a reply to message #551580] Tue, 10 August 2010 16:54 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 8/7/10 3:22 PM, schrieb Bodo:
> BTW: Should this explanation not belong in the tutorial? Probably I
> should write a quick start guide for compiler writers :)

That's an excellent idea! ;-)

Sven

--
--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: Code generation from editor [message #554425 is a reply to message #551577] Mon, 23 August 2010 06:06 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Hello Christian,

now I tried to do code generation with the 2nd method you described in your answer.

But some thing went wrong. I build a new Xtext-Project from the example DomainModel. Then I marked the generator (in the method build) and start the eclipse-application.

1. One can not choose a 'domain project'. In the example form MyDsl I managed to generate an eclipse-application with this project.

2. I defined a generic project and edited a file test.dmodel. But now one can't generate code. When I select Project->clean the generator (method build) was invoked 2 times, but couldn't work because the src-gen folder didn't exised.

What I have to do, that DomainModel works as MyDsl did?

Regards

Bodo
Re: Code generation from editor [message #554462 is a reply to message #554425] Mon, 23 August 2010 09:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it's not quite clear what you want to do,

(1) setup a generator for the domainmodel as it works for the mydsl
(2) setup i builderparticipant for mydsl as the domainmodel has it

Regards
Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Code generation from editor [message #554494 is a reply to message #554462] Mon, 23 August 2010 11:46 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Hi Christian,

i will describe all steps I did:



  1. start Xtext
  2. choose a new fresh workspace (workspace-dm)
  3. go to the workbench
  4. choose File->New->Project... (dialog box opened, "Select a wizard")
  5. open Xtext, open Examples, select "Xtext Domain-Model Example", click Next
  6. Dialog box Examples Project listed: org.eclipse.xtext.example.domainmodel, ...ui, and ...ui.tests. Click Finish
  7. in the Package Explorer we got: org.eclipse.xtext.example.domainmodel, ...ui, and ...ui.tests, but no generator.
  8. select org.eclipse.xtext.example.domainmodel, context menu Run As -> Eclipse Application
  9. New Eclipse opened. Because last Eclipse was MyDsl, we have to close the old project. (Has it to be, that all Eclipse Applications share the same workbench?)
  10. Select File->New->Project.... NOW, no specific Domain-Model Project can be selected in the wizard. Only Xtext Project, Xtext Project From ... and Example folder
  11. if we now create a generic project, one can create new files, say test.dmodel
  12. the editor behaves like it should (Domain-Model) but we can't compile


Hope this clears my question
Re: Code generation from editor [message #554496 is a reply to message #554494] Mon, 23 August 2010 11:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

to get the builder running you need to create a java-project at (11)
with a src-gen source folder in it. see first lines of the org.eclipse.xtext.example.ui.generator.Generator class

IJavaProject javaProject = JavaCore.create(context.getBuiltProject());
if (!javaProject.exists())
	return;
final IFolder folder = context.getBuiltProject().getFolder("src-gen");
if (!folder.exists())
	return;
IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder);
if (!root.exists())
	return;


Regards
Christian


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

[Updated on: Mon, 23 August 2010 11:59]

Report message to a moderator

Re: Code generation from editor [message #554532 is a reply to message #554496] Mon, 23 August 2010 13:47 Go to previous message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
OK, now it works best! Smile

10. select File->New->Java Project. A wizard dialog box pops up.
11. fill in a project name, click Next. A dialog box pops up for Java Setting.
12. click at 'Create new source folder' for build the 'src-gen' folder. A 2nd dialog box pops up, enter the name 'src-gen' and click Finish.
13. now there a two folders in the project. Click Finish
14. select the folder 'src', and in the context menu 'New->File'. The 'New File' dialog box pops up. Choose a valid file name (extension .dmodel), click Finish
15. Answer the question 'Do you want the Xtext nature to be added to this project?' with Yes.
16. Type in some text in the domain language (i.e. 'entity Test {}').
17. select Project->Build Project, Code is been generating.
18. results are in src-gen/default-package/Test.java

Thank you for the fast reply, the generation works now.

Some more question now:

Is it really needed, to answer in step 15 with yes?

Is there any chance to use the run-button for this eclipse application? What run configuration has to be taken?

I would prefer to generate XML-Files instead of Java-Source-Code-Files. There for, the output should no be in the project folder. What is the best way to ask the user (file dialog box) where he/she want to put the results?

Regards

Bodo
Previous Topic:Resolving references changed with 1.0?
Next Topic:Loading a model where some values (used in this model) are defined by the another model
Goto Forum:
  


Current Time: Thu Apr 25 07:24:17 GMT 2024

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

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

Back to the top