|
Re: Code generation from editor [message #551577 is a reply to message #551573] |
Sat, 07 August 2010 12:26 |
|
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 #554494 is a reply to message #554462] |
Mon, 23 August 2010 11:46 |
Bodo Messages: 27 Registered: August 2010 |
Junior Member |
|
|
Hi Christian,
i will describe all steps I did:
- start Xtext
- choose a new fresh workspace (workspace-dm)
- go to the workbench
- choose File->New->Project... (dialog box opened, "Select a wizard")
- open Xtext, open Examples, select "Xtext Domain-Model Example", click Next
- Dialog box Examples Project listed: org.eclipse.xtext.example.domainmodel, ...ui, and ...ui.tests. Click Finish
- in the Package Explorer we got: org.eclipse.xtext.example.domainmodel, ...ui, and ...ui.tests, but no generator.
- select org.eclipse.xtext.example.domainmodel, context menu Run As -> Eclipse Application
- 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?)
- 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
- if we now create a generic project, one can create new files, say test.dmodel
- 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 |
|
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 |
Bodo Messages: 27 Registered: August 2010 |
Junior Member |
|
|
OK, now it works best!
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
|
|
|
Powered by
FUDForum. Page generated in 0.04737 seconds